Rerun C++ SDK
Loading...
Searching...
No Matches
compiler_utils.hpp
1#pragma once
2
3// Push pop warnings
4#if defined(__GNUC__) || defined(__clang__)
5#define RR_PUSH_WARNINGS _Pragma("GCC diagnostic push")
6#define RR_POP_WARNINGS _Pragma("GCC diagnostic pop")
7#elif defined(_MSC_VER)
8#define RR_PUSH_WARNINGS __pragma(warning(push))
9#define RR_POP_WARNINGS __pragma(warning(pop))
10#else
11#define RR_PUSH_WARNINGS
12#define RR_POP_WARNINGS
13#endif
14
15// Macro for enabling and disabling the "-Wmaybe-uninitialized" warning in GCC.
16// See: https://github.com/rerun-io/rerun/issues/4027
17
18#define RR_WITH_MAYBE_UNINITIALIZED_DISABLED(expr) \
19 RR_DISABLE_MAYBE_UNINITIALIZED_PUSH \
20 expr RR_DISABLE_MAYBE_UNINITIALIZED_POP
21
22#if defined(__GNUC__) && !defined(__clang__)
23
24#define RR_DISABLE_MAYBE_UNINITIALIZED_PUSH \
25 RR_PUSH_WARNINGS \
26 _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
27#else
28#define RR_DISABLE_MAYBE_UNINITIALIZED_PUSH RR_PUSH_WARNINGS
29#endif
30
31#define RR_DISABLE_MAYBE_UNINITIALIZED_POP RR_POP_WARNINGS
32
33// Macro for marking code as unreachable.
34// Reaching the code after all is undefined behavior.
35
36#if defined(__GNUC__) || defined(__clang__)
37#define RR_UNREACHABLE() __builtin_unreachable()
38#elif defined(_MSC_VER)
39#define RR_UNREACHABLE() __assume(false)
40#else
41#define RR_UNREACHABLE() \
42 do { \
43 } while (false)
44#endif
45
46// Disable deprecation warning
47#if defined(__GNUC__) || defined(__clang__)
48#define RR_DISABLE_DEPRECATION_WARNING \
49 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
50#elif defined(_MSC_VER)
51#define RR_DISABLE_DEPRECATION_WARNING __pragma(warning(disable : 4996))
52#else
53#define RR_DISABLE_DEPRECATION_WARNING
54#endif
55
56// Disable possible null reference warning
57#if defined(__GNUC__) || defined(__clang__)
58#define RR_DISABLE_NULL_DEREF_WARNING _Pragma("GCC diagnostic ignored \"-Wnull-dereference\"")
59#else
60#define RR_DISABLE_NULL_DEREF_WARNING
61#endif