diff options
author | Anthony Towns <aj@erisian.com.au> | 2022-03-26 12:41:28 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2022-03-30 23:09:13 +1000 |
commit | 2ef47ba6c57a12840499a13908ab61aefca6cb55 (patch) | |
tree | 8fa4af2c41a838756e8dffa5d3587c0ef414faf5 /src/util/check.h | |
parent | 7c9fe25c16d48b53a61fa2f6ff77eaf8820cb1f6 (diff) | |
download | bitcoin-2ef47ba6c57a12840499a13908ab61aefca6cb55.tar.xz |
util/check: stop using lambda for Assert/Assume
Diffstat (limited to 'src/util/check.h')
-rw-r--r-- | src/util/check.h | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/util/check.h b/src/util/check.h index a443c13cf2..80e973e7e2 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -47,14 +47,26 @@ class NonFatalCheckError : public std::runtime_error #endif /** Helper for Assert() */ -template <typename T> -T get_pure_r_value(T&& val) +void assertion_fail(const char* file, int line, const char* func, const char* assertion); + +/** Helper for Assert()/Assume() */ +template <bool IS_ASSERT, typename T> +T&& inline_assertion_check(T&& val, const char* file, int line, const char* func, const char* assertion) { + if constexpr (IS_ASSERT +#ifdef ABORT_ON_FAILED_ASSUME + || true +#endif + ) { + if (!val) { + assertion_fail(file, line, func, assertion); + } + } return std::forward<T>(val); } /** Identity function. Abort if the value compares equal to zero */ -#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); }()) +#define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val) /** * Assume is the identity function. @@ -66,10 +78,6 @@ T get_pure_r_value(T&& val) * - 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) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); return std::forward<decltype(get_pure_r_value(val))>(check); }()) -#endif +#define Assume(val) inline_assertion_check<false>(val, __FILE__, __LINE__, __func__, #val) #endif // BITCOIN_UTIL_CHECK_H |