Files
ternfs-XTXMarkets/cpp/core/Assert.hpp
Francesco Mazzoli 9adca070ba Convert build system to cmake
Also, produce fully static binaries. This means that `gethostname`
does not work (doesn't work with static glibc unless you build it
with `--enable-static-nss`, which no distro builds glibc with).
2023-01-26 23:20:58 +00:00

41 lines
1.1 KiB
C++

#pragma once
#include "Common.hpp"
#include "Exception.hpp"
// Assert macros take an optional FormatTuple-style message, e.g.:
// ASSERT(result != 0, "expected nonzero result, got %s", result);
//
// Plain ASSERT(result != 0) also works.
// Assert which fires in all builds including release, essentially shorthand for
// if (!expr) then throw
#define ALWAYS_ASSERT(expr, ...) do { \
if (unlikely(!(expr))) \
throw AssertionException(__LINE__, SHORT_FILE, removeTemplates(__PRETTY_FUNCTION__).c_str(), #expr, ## __VA_ARGS__); \
} while (false)
#if defined(EGGS_DEBUG)
#define ASSERT(expr, ...) ALWAYS_ASSERT(expr, ## __VA_ARGS__)
#define CHECK_UNREACHABLE() do { \
throw AssertionException(__LINE__, SHORT_FILE, removeTemplates(__PRETTY_FUNCTION__).c_str(), "unreachable code"); \
} while (false)
#define IF_DEBUG(expr) do { \
expr; \
} while (false)
#else
#define ASSERT(expr, ...) do { \
(void)sizeof(expr); \
} while (false)
#define CHECK_UNREACHABLE() __builtin_unreachable()
#define IF_DEBUG(expr) do { } while (false)
#endif