4#ifndef GREM_CORE_ASSERTIONS_HPP
5#define GREM_CORE_ASSERTIONS_HPP
13#if (!defined(GREM_ASSERT) || !defined(GREM_UNREACHABLE))
14#ifdef GREM_USE_RELEASE_ASSERTIONS
15#ifdef GREM_RELEASE_ASSERTIONS_FAST_FAIL
16#if !defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
25#include <source_location>
28#elif !defined(NDEBUG) || !defined(GREM_ASSUME_UNCHECKED_ASSERTIONS_NEVER_FAIL)
29#if !defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
42#ifdef GREM_USE_RELEASE_ASSERTIONS
43#ifdef GREM_RELEASE_ASSERTIONS_FAST_FAIL
45#define GREM_ASSERT(expression) ((static_cast<bool>(expression)) ? (void)0 : __debugbreak())
46#elif defined(__clang__) || defined(__GNUC__)
47#define GREM_ASSERT(expression) ((static_cast<bool>(expression)) ? (void)0 : __builtin_trap())
49#define GREM_ASSERT(expression) ((static_cast<bool>(expression)) ? (void)0 : std::abort())
54[[noreturn]]
inline void assertionViolation(
const char* expressionString,
const std::source_location& source) {
55 std::fprintf(stderr,
"Assertion failed: %s\n Source: %s:%d:%d\n Function: %s\n", expressionString, source.file_name(),
static_cast<int>(source.line()),
56 static_cast<int>(source.column()), source.function_name());
61#define GREM_ASSERT(expression) ((static_cast<bool>(expression)) ? (void)0 : grem::detail::assertionViolation(#expression, std::source_location::current()))
64#ifdef GREM_ASSUME_UNCHECKED_ASSERTIONS_NEVER_FAIL
66#define GREM_ASSERT(expression) __builtin_assume(expression)
67#elif defined(_MSC_VER)
68#define GREM_ASSERT(expression) __assume(expression)
70#define GREM_ASSERT(expression) ((void)0)
73#define GREM_ASSERT(expression) ((void)0)
77#define GREM_ASSERT(expression) assert(expression)
86#pragma clang diagnostic push
87#pragma clang diagnostic ignored "-Winvalid-noreturn"
90#if !defined(GREM_UNREACHABLE) && defined(GREM_USE_RELEASE_ASSERTIONS) && !defined(GREM_RELEASE_ASSERTIONS_FAST_FAIL)
93[[noreturn]]
inline void unreachableViolation(
const std::source_location& source) {
94 std::fprintf(stderr,
"Unreachable violation.\n Source: %s:%d:%d\n Function: %s\n", source.file_name(),
static_cast<int>(source.line()),
static_cast<int>(source.column()),
95 source.function_name());
104#ifdef GREM_UNREACHABLE
108#elif defined(GREM_USE_RELEASE_ASSERTIONS)
109#ifdef GREM_RELEASE_ASSERTIONS_FAST_FAIL
113#elif defined(__clang__) || defined(__GNUC__)
120[[noreturn]]
inline void unreachable(
const std::source_location& source = std::source_location::current()) {
121 detail::unreachableViolation(source);
126#if defined(NDEBUG) && defined(GREM_ASSUME_UNCHECKED_ASSERTIONS_NEVER_FAIL)
127#if defined(__clang__) || defined(__GNUC__)
128 __builtin_unreachable();
129#elif defined(_MSC_VER)
135#elif defined(__clang__) || defined(__GNUC__)
147#pragma clang diagnostic pop
void unreachable()
Definition assertions.hpp:125