Go to the documentation of this file.
11 #ifndef __SYS_COMPILER_H_INCLUDED__
12 #define __SYS_COMPILER_H_INCLUDED__
15 #define SYS_IS_GCC_GE(MAJOR, MINOR) \
16 (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
17 #define SYS_IS_GCC_EQ(MAJOR, MINOR) \
18 (__GNUC__ == MAJOR && __GNUC_MINOR__ == MINOR)
20 #define SYS_IS_GCC_GE(MAJOR, MINOR) 0
21 #define SYS_IS_GCC_EQ(MAJOR, MINOR) 0
24 #if defined(__clang__)
25 #define SYS_IS_CLANG_GE(MAJOR, MINOR) \
26 (__clang_major__ > MAJOR || (__clang_major__ == MAJOR && __clang_minor__ >= MINOR))
28 #define SYS_IS_CLANG_GE(MAJOR, MINOR) 0
31 #if (__cplusplus >= 201402) || (defined(_MSC_VER) && _MSVC_LANG >= 201402)
32 #define SYS_HAS_CXX14 1
34 #define SYS_HAS_CXX14 0
38 #define SYS_CONCAT(a, b) SYS_CONCAT_(a, b)
39 #define SYS_CONCAT_(a, b) a ## b
41 #define SYS_TO_STRING_(a) # a
42 #define SYS_TO_STRING(a) SYS_TO_STRING_(a)
46 #define SYS_MESSAGE(desc) __pragma(message(__FILE__ "(" SYS_TO_STRING(__LINE__) ") : Warning: " #desc))
48 #define SYS_MESSAGE(__msg__) _Pragma(SYS_TO_STRING(message __msg__))
52 #if defined(__has_cpp_attribute)
53 #if __has_cpp_attribute(fallthrough) == 201603
54 #define SYS_FALLTHROUGH [[fallthrough]]
56 #if __has_cpp_attribute(maybe_unused) == 201603
57 #define SYS_MAYBE_UNUSED [[maybe_unused]]
60 #if !defined(SYS_FALLTHROUGH)
61 #define SYS_FALLTHROUGH
63 #if !defined(SYS_MAYBE_UNUSED)
64 #define SYS_MAYBE_UNUSED
69 #if SYS_IS_GCC_GE(7, 0)
70 #define SYS_MAYBE_UNUSED_MEMBER
72 #define SYS_MAYBE_UNUSED_MEMBER SYS_MAYBE_UNUSED
75 #if defined(__has_cpp_attribute)
76 #if __has_cpp_attribute(nodiscard) >= 201603L
77 #define SYS_NO_DISCARD_RESULT [[nodiscard]]
79 #elif __cplusplus >= 201703L // We live in the future and using c++17 or later!
80 #define SYS_NO_DISCARD_RESULT [[nodiscard]]
82 #if !defined(SYS_NO_DISCARD_RESULT)
84 #define SYS_NO_DISCARD_RESULT __attribute__((warn_unused_result))
86 #define SYS_NO_DISCARD_RESULT
93 #if defined(__GNUC__) || defined(__clang__)
94 # define SYS_UNUSED_VAR_ATTRIB __attribute__((unused))
96 # define SYS_UNUSED_VAR_ATTRIB
101 #define SYS_FUNC_NORETURN [[noreturn]]
107 #if !(defined(__APPLE__) && defined(__clang__))
108 #define SYS_THREAD_LOCAL thread_local
110 #define SYS_THREAD_LOCAL __thread
115 #if defined(_MSC_VER)
116 #define SYS_ASSUME(EXPR) __assume(EXPR)
117 #elif defined(__clang__)
118 #if __has_builtin(__builtin_assume)
119 #define SYS_ASSUME(EXPR) __builtin_assume(EXPR)
121 #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
124 #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
128 #if defined(__has_feature)
129 #if __has_feature(thread_sanitizer)
130 #define SYS_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
132 #if __has_feature(memory_sanitizer)
133 #define SYS_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
135 #if __has_feature(address_sanitizer)
136 #define SYS_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
139 #if !defined(SYS_NO_SANITIZE_THREAD)
140 #define SYS_NO_SANITIZE_THREAD
142 #if !defined(SYS_NO_SANITIZE_MEMORY)
143 #define SYS_NO_SANITIZE_MEMORY
145 #if !defined(SYS_NO_SANITIZE_ADDRESS)
146 #define SYS_NO_SANITIZE_ADDRESS
150 #if defined(__SANITIZE_ADDRESS__)
151 #define SYS_ASAN_ENABLED 1
152 #elif defined(__has_feature)
153 #if __has_feature(address_sanitizer)
154 #define SYS_ASAN_ENABLED 1
156 #define SYS_ASAN_ENABLED 0
159 #define SYS_ASAN_ENABLED 0
162 #endif // __SYS_COMPILER_H_INCLUDED__