Bitcoin ABC  0.24.7
P2P Digital Currency
check.h
Go to the documentation of this file.
1 // Copyright (c) 2019 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  using std::runtime_error::runtime_error;
18 };
19 
34 #define CHECK_NONFATAL(condition) \
35  do { \
36  if (!(condition)) { \
37  throw NonFatalCheckError( \
38  strprintf("%s:%d (%s)\n" \
39  "Internal bug detected: '%s'\n" \
40  "You may report this issue here: %s\n", \
41  __FILE__, __LINE__, __func__, (#condition), \
42  PACKAGE_BUGREPORT)); \
43  } \
44  } while (false)
45 
46 #if defined(NDEBUG)
47 #error "Cannot compile without assertions!"
48 #endif
49 
51 template <typename T> T get_pure_r_value(T &&val) {
52  return std::forward<T>(val);
53 }
54 
56 #define Assert(val) \
57  ([&]() -> decltype(get_pure_r_value(val)) { \
58  auto &&check = (val); \
59  assert(#val &&check); \
60  return std::forward<decltype(get_pure_r_value(val))>(check); \
61  }())
62 
73 #ifdef ABORT_ON_FAILED_ASSUME
74 #define Assume(val) Assert(val)
75 #else
76 #define Assume(val) ((void)(val))
77 #endif
78 
79 #endif // BITCOIN_UTIL_CHECK_H
tinyformat.h
get_pure_r_value
T get_pure_r_value(T &&val)
Helper for Assert()
Definition: check.h:51
NonFatalCheckError
Definition: check.h:16