Bitcoin ABC  0.22.13
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 
52 template <typename T> T get_pure_r_value(T &&val) {
53  return std::forward<T>(val);
54 }
55 
57 #define Assert(val) \
58  [&]() -> decltype(get_pure_r_value(val)) & { \
59  auto &check = (val); \
60  assert(#val &&check); \
61  return check; \
62  }()
63 
64 #endif // BITCOIN_UTIL_CHECK_H
T get_pure_r_value(T &&val)
Helper for Assert().
Definition: check.h:52