5 #ifndef BITCOIN_UTIL_CHECK_H 6 #define BITCOIN_UTIL_CHECK_H 13 #include <string_view> 31 return std::forward<T>(val);
35 #error "Cannot compile without assertions!" 39 void assertion_fail(std::string_view file,
int line, std::string_view func, std::string_view assertion);
42 template <
bool IS_ASSERT,
typename T>
45 if constexpr (IS_ASSERT
46 #ifdef ABORT_ON_FAILED_ASSUME
54 return std::forward<T>(val);
60 #define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__) 73 #define CHECK_NONFATAL(condition) \ 74 inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition) 77 #define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val) 89 #define Assume(val) inline_assertion_check<false>(val, __FILE__, __LINE__, __func__, #val) 94 #define NONFATAL_UNREACHABLE() \ 95 throw NonFatalCheckError( \ 96 "Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__) 100 #endif // BITCOIN_UTIL_CHECK_H
T && inline_assertion_check(LIFETIMEBOUND T &&val, [[maybe_unused]] const char *file, [[maybe_unused]] int line, [[maybe_unused]] const char *func, [[maybe_unused]] const char *assertion)
Helper for Assert()/Assume()
T && inline_check_non_fatal(LIFETIMEBOUND T &&val, const char *file, int line, const char *func, const char *assertion)
Helper for CHECK_NONFATAL()
NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
Helper for Assert()
#define T(expected, seed, data)