5#ifndef BITCOIN_UTIL_CHECK_H
6#define BITCOIN_UTIL_CHECK_H
8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-config.h>
18 using std::runtime_error::runtime_error;
21#define format_internal_error(msg, file, line, func, report) \
22 strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this " \
24 msg, file, line, func, report)
29 const char *func,
const char *assertion) {
32 assertion, file, line, func, PACKAGE_BUGREPORT));
35 return std::forward<T>(val);
39#error "Cannot compile without assertions!"
44 const char *assertion);
47template <
bool IS_ASSERT,
typename T>
49 [[maybe_unused]]
const char *file,
50 [[maybe_unused]]
int line,
51 [[maybe_unused]]
const char *func,
52 [[maybe_unused]]
const char *assertion) {
53 if constexpr (IS_ASSERT
54#ifdef ABORT_ON_FAILED_ASSUME
62 return std::forward<T>(val);
83#define CHECK_NONFATAL(condition) \
84 inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition)
88 inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
101 inline_assertion_check<false>(val, __FILE__, __LINE__, __func__, #val)
109#define NONFATAL_UNREACHABLE() \
110 throw NonFatalCheckError(format_internal_error( \
111 "Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__, \
T && inline_check_non_fatal(LIFETIMEBOUND T &&val, const char *file, int line, const char *func, const char *assertion)
Helper for CHECK_NONFATAL()
#define format_internal_error(msg, file, line, func, report)
T && inline_assertion_check(LIFETIMEBOUND T &&val, const char *file, int line, const char *func, const char *assertion)
Helper for Assert()/Assume()
void assertion_fail(const char *file, int line, const char *func, const char *assertion)
Helper for Assert()