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