Bitcoin Core
22.99.0
P2P Digital Currency
src
util
check.h
Go to the documentation of this file.
1
// Copyright (c) 2019-2021 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_CHECK_H
6
#define BITCOIN_UTIL_CHECK_H
7
8
#if defined(HAVE_CONFIG_H)
9
#include <
config/bitcoin-config.h
>
10
#endif
11
12
#include <
tinyformat.h
>
13
14
#include <stdexcept>
15
16
class
NonFatalCheckError
:
public
std::runtime_error
17
{
18
using
std::runtime_error::runtime_error;
19
};
20
32
#define CHECK_NONFATAL(condition) \
33
do { \
34
if (!(condition)) { \
35
throw NonFatalCheckError( \
36
strprintf("Internal bug detected: '%s'\n" \
37
"%s:%d (%s)\n" \
38
"You may report this issue here: %s\n", \
39
(#condition), \
40
__FILE__, __LINE__, __func__, \
41
PACKAGE_BUGREPORT)); \
42
} \
43
} while (false)
44
45
#if defined(NDEBUG)
46
#error "Cannot compile without assertions!"
47
#endif
48
50
template
<
typename
T>
51
T
get_pure_r_value
(T&& val)
52
{
53
return
std::forward<T>(val);
54
}
55
57
#define Assert(val) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); assert(#val && check); return std::forward<decltype(get_pure_r_value(val))>(check); }())
58
69
#ifdef ABORT_ON_FAILED_ASSUME
70
#define Assume(val) Assert(val)
71
#else
72
#define Assume(val) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); return std::forward<decltype(get_pure_r_value(val))>(check); }())
73
#endif
74
75
#endif // BITCOIN_UTIL_CHECK_H
bitcoin-config.h
tinyformat.h
get_pure_r_value
T get_pure_r_value(T &&val)
Helper for Assert()
Definition:
check.h:51
T
#define T(expected, seed, data)
NonFatalCheckError
Definition:
check.h:16
Generated on Fri Feb 18 2022 20:03:52 for Bitcoin Core by
1.8.17