forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cata_unreachable.h
42 lines (38 loc) · 967 Bytes
/
cata_unreachable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#ifndef CATA_SRC_CATA_UNREACHABLE_H
#define CATA_SRC_CATA_UNREACHABLE_H
namespace cata
{
/**
* @brief Marks unreachable code.
*
* Utility function to mark unreachable code to help compiler with optimizations.
*
* Usage:
* void ( bool always_true )
* {
* if ( always_true ) {
* return;
* } else {
* // If always_true happens to be false, this will cause Undefined Behavior.
* cata::unreachable();
* }
* }
*
* Source: https://stackoverflow.com/a/65258501
*/
#ifdef __GNUC__ // GCC 4.8+, Clang, Intel and other compilers compatible with GCC (-std=c++0x or above)
[[noreturn]] inline __attribute__( ( always_inline ) ) void unreachable()
{
__builtin_unreachable();
}
#elif defined(_MSC_VER) // MSVC
[[noreturn]] __forceinline void unreachable()
{
__assume( false );
}
#else // ???
inline void unreachable() {}
#endif
} // namespace cata
#endif // CATA_SRC_CATA_UNREACHABLE_H