Changeset View
Changeset View
Standalone View
Standalone View
src/util/check.h
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | do { \ | ||||
PACKAGE_BUGREPORT)); \ | PACKAGE_BUGREPORT)); \ | ||||
} \ | } \ | ||||
} while (false) | } while (false) | ||||
#if defined(NDEBUG) | #if defined(NDEBUG) | ||||
#error "Cannot compile without assertions!" | #error "Cannot compile without assertions!" | ||||
#endif | #endif | ||||
/** Helper for Assert(). TODO remove in C++14 and replace | /** Helper for Assert() */ | ||||
* `decltype(get_pure_r_value(val))` with `T` (templated lambda) */ | |||||
template <typename T> T get_pure_r_value(T &&val) { | template <typename T> T get_pure_r_value(T &&val) { | ||||
return std::forward<T>(val); | return std::forward<T>(val); | ||||
} | } | ||||
/** Identity function. Abort if the value compares equal to zero */ | /** Identity function. Abort if the value compares equal to zero */ | ||||
#define Assert(val) \ | #define Assert(val) \ | ||||
[&]() -> decltype(get_pure_r_value(val)) { \ | ([&]() -> decltype(get_pure_r_value(val)) { \ | ||||
auto &&check = (val); \ | auto &&check = (val); \ | ||||
assert(#val &&check); \ | assert(#val &&check); \ | ||||
return std::forward<decltype(get_pure_r_value(val))>(check); \ | return std::forward<decltype(get_pure_r_value(val))>(check); \ | ||||
}() | }()) | ||||
/** | |||||
* Assume is the identity function. | |||||
* | |||||
* - Should be used to run non-fatal checks. In debug builds it behaves like | |||||
* Assert()/assert() to notify developers and testers about non-fatal errors. | |||||
* In production it doesn't warn or log anything. | |||||
* - For fatal errors, use Assert(). | |||||
* - For non-fatal errors in interactive sessions (e.g. RPC or command line | |||||
* interfaces), CHECK_NONFATAL() might be more appropriate. | |||||
*/ | |||||
#ifdef ABORT_ON_FAILED_ASSUME | |||||
#define Assume(val) Assert(val) | |||||
#else | |||||
#define Assume(val) ((void)(val)) | |||||
#endif | |||||
#endif // BITCOIN_UTIL_CHECK_H | #endif // BITCOIN_UTIL_CHECK_H |