openMSX
unreachable.hh
Go to the documentation of this file.
1 #ifndef UNREACHABLE_HH
2 #define UNREACHABLE_HH
3 
4 // Clang has a very convenient way of testing features, unfortunately (for now)
5 // it's clang-only so add a fallback for non-clang compilers.
6 #ifndef __has_builtin
7  #define __has_builtin(x) 0
8 #endif
9 
10 #if defined(NDEBUG)
11  // clang
12  #if __has_builtin(__builtin_unreachable)
13  #define UNREACHABLE __builtin_unreachable()
14 
15  // __builtin_unreachable() was introduced in gcc-4.5, but 4.5 and 4.6 contain
16  // bugs on architectures with delay slots (e.g. MIPS). Look at the git
17  // history of this file for more details.
18  #elif ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
19  // gcc-4.7 or above
20  #define UNREACHABLE __builtin_unreachable()
21 
22  #elif defined(_MSC_VER)
23  // visual studio
24  #define UNREACHABLE __assume(0)
25 
26  #else
27  // fall-back
28  #define UNREACHABLE /*nothing*/
29 
30  #endif
31 
32 #else
33  // asserts enabled
34  #include <cassert>
35  #define UNREACHABLE assert(false)
36 
37 #endif
38 
39 #endif // UNREACHABLE_HH