FE 0.9.2
Header-only C++ frontend library
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <cstdlib>
5
6namespace fe {
7
8/// @sa https://stackoverflow.com/a/65258501
9#ifdef __GNUC__ // GCC 4.8+, Clang, Intel and other compilers compatible with GCC (-std=c++0x or above)
10[[noreturn]] inline __attribute__((always_inline)) void unreachable() {
11 assert(false);
12 __builtin_unreachable();
13}
14#elif defined(_MSC_VER) // MSVC
15[[noreturn]] __forceinline void unreachable() {
16 assert(false);
17 __assume(false);
18}
19#else // ???
20[[noreturn]] inline void unreachable() {
21 assert(false);
22 std::abort();
23}
24#endif
25
26/// Raise a breakpoint in the debugger.
27#if (defined(__clang__) || defined(__GNUC__)) && (defined(__x86_64__) || defined(__i386__))
28inline void breakpoint() { asm("int3"); }
29#else
30inline void breakpoint() {
31 volatile int* p = nullptr;
32 *p = 42;
33}
34#endif
35
36} // namespace fe
37
38#ifndef NDEBUG
39# define assert_unused(x) assert(x)
40#else
41# define assert_unused(x) ((void)(0 && (x)))
42#endif
Definition arena.h:13
void breakpoint()
Raise a breakpoint in the debugger.
Definition assert.h:30
void unreachable()
Definition assert.h:20