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 (__cplusplus >= 201103) || (_MSC_VER >= 1800)
53 #define SYS_SAFE_BOOL explicit
59 #if defined(__has_cpp_attribute)
60 #if __has_cpp_attribute(fallthrough) == 201603
61 #define SYS_FALLTHROUGH [[fallthrough]]
63 #if __has_cpp_attribute(maybe_unused) == 201603
64 #define SYS_MAYBE_UNUSED [[maybe_unused]]
67 #if !defined(SYS_FALLTHROUGH)
68 #define SYS_FALLTHROUGH
70 #if !defined(SYS_MAYBE_UNUSED)
71 #define SYS_MAYBE_UNUSED
76 #if SYS_IS_GCC_GE(7, 0)
77 #define SYS_MAYBE_UNUSED_MEMBER
79 #define SYS_MAYBE_UNUSED_MEMBER SYS_MAYBE_UNUSED
82 #if defined(__has_cpp_attribute)
83 #if __has_cpp_attribute(nodiscard) >= 201603L
84 #define SYS_NO_DISCARD_RESULT [[nodiscard]]
86 #elif __cplusplus >= 201703L // We live in the future and using c++17 or later!
87 #define SYS_NO_DISCARD_RESULT [[nodiscard]]
89 #if !defined(SYS_NO_DISCARD_RESULT)
91 #define SYS_NO_DISCARD_RESULT __attribute__((warn_unused_result))
93 #define SYS_NO_DISCARD_RESULT
100 #if defined(__GNUC__) || defined(__clang__)
101 # define SYS_UNUSED_VAR_ATTRIB __attribute__((unused))
103 # define SYS_UNUSED_VAR_ATTRIB
108 #define SYS_FUNC_NORETURN [[noreturn]]
114 #if !(defined(__APPLE__) && defined(__clang__))
115 #define SYS_THREAD_LOCAL thread_local
117 #define SYS_THREAD_LOCAL __thread
122 #if defined(_MSC_VER)
123 #define SYS_ASSUME(EXPR) __assume(EXPR)
124 #elif defined(__clang__)
125 #if __has_builtin(__builtin_assume)
126 #define SYS_ASSUME(EXPR) __builtin_assume(EXPR)
128 #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
131 #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
135 #if defined(__has_feature)
136 #if __has_feature(thread_sanitizer)
137 #define SYS_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
139 #if __has_feature(memory_sanitizer)
140 #define SYS_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
142 #if __has_feature(address_sanitizer)
143 #define SYS_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
146 #if !defined(SYS_NO_SANITIZE_THREAD)
147 #define SYS_NO_SANITIZE_THREAD
149 #if !defined(SYS_NO_SANITIZE_MEMORY)
150 #define SYS_NO_SANITIZE_MEMORY
152 #if !defined(SYS_NO_SANITIZE_ADDRESS)
153 #define SYS_NO_SANITIZE_ADDRESS
156 #endif // __SYS_COMPILER_H_INCLUDED__