Changeset View
Changeset View
Standalone View
Standalone View
src/compat/assumptions.h
Show All 14 Lines | |||||
// Assumption: We assume that the macro NDEBUG is not defined. | // Assumption: We assume that the macro NDEBUG is not defined. | ||||
// Example(s): We use assert(...) extensively with the assumption of it never | // Example(s): We use assert(...) extensively with the assumption of it never | ||||
// being a noop at runtime. | // being a noop at runtime. | ||||
#if defined(NDEBUG) | #if defined(NDEBUG) | ||||
#error "Bitcoin cannot be compiled without assertions." | #error "Bitcoin cannot be compiled without assertions." | ||||
#endif | #endif | ||||
// Assumption: We assume a C++14 (ISO/IEC 14882:2014) compiler (minimum | |||||
// requirement). | |||||
// Example(s): We use std::make_unique() through the codebase. | |||||
// Note: MSVC does not report the expected __cplusplus value due to | |||||
// legacy reasons. | |||||
#if !defined(_MSC_VER) | |||||
// N3936* §16.8 [cpp.predefined]/p1:: | |||||
// "The name __cplusplus is defined to the value 201402L when compiling a C++ | |||||
// translation unit." | |||||
static_assert(__cplusplus >= 201402L, "C++14 standard assumed"); | |||||
#endif | |||||
// Assumption: We assume the floating-point types to fulfill the requirements of | // Assumption: We assume the floating-point types to fulfill the requirements of | ||||
// IEC 559 (IEEE 754) standard. | // IEC 559 (IEEE 754) standard. | ||||
// Example(s): Floating-point division by zero in ConnectBlock, | // Example(s): Floating-point division by zero in ConnectBlock, | ||||
// CreateTransaction | // CreateTransaction | ||||
// and EstimateMedianVal. | // and EstimateMedianVal. | ||||
static_assert(std::numeric_limits<float>::is_iec559, "IEEE 754 float assumed"); | static_assert(std::numeric_limits<float>::is_iec559, "IEEE 754 float assumed"); | ||||
static_assert(std::numeric_limits<double>::is_iec559, | static_assert(std::numeric_limits<double>::is_iec559, | ||||
"IEEE 754 double assumed"); | "IEEE 754 double assumed"); | ||||
Show All 21 Lines | |||||
// bytes, so we have to ensure that uint8_t is an alias to a "byte type". | // bytes, so we have to ensure that uint8_t is an alias to a "byte type". | ||||
// http://eel.is/c++draft/basic.types | // http://eel.is/c++draft/basic.types | ||||
// http://eel.is/c++draft/basic.memobj#def:byte | // http://eel.is/c++draft/basic.memobj#def:byte | ||||
// http://eel.is/c++draft/expr.sizeof#1 | // http://eel.is/c++draft/expr.sizeof#1 | ||||
// http://eel.is/c++draft/cstdint#syn | // http://eel.is/c++draft/cstdint#syn | ||||
static_assert(std::is_same<uint8_t, unsigned char>::value, | static_assert(std::is_same<uint8_t, unsigned char>::value, | ||||
"uint8_t is an alias of unsigned char"); | "uint8_t is an alias of unsigned char"); | ||||
// Assumption: We assume size_t to be 32-bit or 64-bit. | |||||
// Example(s): size_t assumed to be at least 32-bit in | |||||
// ecdsa_signature_parse_der_lax(...). | |||||
// size_t assumed to be 32-bit or 64-bit in MallocUsage(...). | |||||
static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, | |||||
"size_t assumed to be 32-bit or 64-bit"); | |||||
static_assert(sizeof(size_t) == sizeof(void *), | |||||
"Sizes of size_t and void* assumed to be equal"); | |||||
// Some important things we are NOT assuming (non-exhaustive list): | // Some important things we are NOT assuming (non-exhaustive list): | ||||
// * We are NOT assuming a specific value for sizeof(std::size_t). | |||||
// * We are NOT assuming a specific value for std::endian::native. | // * We are NOT assuming a specific value for std::endian::native. | ||||
// * We are NOT assuming a specific value for std::locale("").name(). | // * We are NOT assuming a specific value for std::locale("").name(). | ||||
// * We are NOT assuming a specific value for | // * We are NOT assuming a specific value for | ||||
// std::numeric_limits<char>::is_signed. | // std::numeric_limits<char>::is_signed. | ||||
/** | /** | ||||
* /!\ C++ right shift signedness handling is implementation defined. It is | * /!\ C++ right shift signedness handling is implementation defined. It is | ||||
* defined as an arithmetic on all the platform we support, but this | * defined as an arithmetic on all the platform we support, but this | ||||
Show All 16 Lines |