HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_Pragma.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_Pragma.h (SYS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SYS_PRAGMA_H_INCLUDED__
12 #define __SYS_PRAGMA_H_INCLUDED__
13 
14 #include "SYS_Compiler.h"
15 
16 /// SYS_PRAGMA allows one to embed multiple into macros
17 #if defined(_MSC_VER)
18 # define SYS_PRAGMA(X) __pragma(X)
19 #elif defined(__GNUC__)
20 # define SYS_PRAGMA(X) _Pragma(#X)
21 #else
22 # define SYS_PRAGMA(X)
23 #endif
24 
25 /// Temporarily disable warnings. The PUSH/POPs must match!
26 /// @note Only implemented for Visual C++ and gcc 4.6
27 #if defined(_MSC_VER)
28 # define SYS_PRAGMA_PUSH_WARN() SYS_PRAGMA(warning(push))
29 # define SYS_PRAGMA_POP_WARN() SYS_PRAGMA(warning(pop))
30 #elif SYS_IS_GCC_GE(4, 6) || defined(__clang__)
31 # define SYS_PRAGMA_PUSH_WARN() SYS_PRAGMA(GCC diagnostic push)
32 # define SYS_PRAGMA_POP_WARN() SYS_PRAGMA(GCC diagnostic pop)
33 #else
34 # define SYS_PRAGMA_PUSH_WARN()
35 # define SYS_PRAGMA_POP_WARN()
36 #endif
37 
38 /// Disable deprecation warnings
39 /// @internal Note that the test for __clang__ must come before the _MSC_VER
40 /// test so that this pragma has an effect for clang-cl builds
41 #if SYS_IS_GCC_GE(4, 2) || defined(__clang__)
42 # define SYS_PRAGMA_DISABLE_DEPRECATED() \
43  SYS_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
44 #elif defined(_MSC_VER)
45 # define SYS_PRAGMA_DISABLE_DEPRECATED() \
46  SYS_PRAGMA(warning(disable: 4996))
47 #else
48 # define SYS_PRAGMA_DISABLE_DEPRECATED()
49 #endif
50 #if defined(_MSC_VER)
51 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL() \
52  SYS_PRAGMA(warning(disable: 4263)) \
53  SYS_PRAGMA(warning(disable: 4266)) \
54  /**/
55 #elif SYS_IS_GCC_GE(4, 6) || defined(__clang__)
56 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL() \
57  SYS_PRAGMA(GCC diagnostic ignored "-Woverloaded-virtual")
58 #else
59 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL()
60 #endif
61 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
62 # define SYS_PRAGMA_DISABLE_IGNORED_QUALIFIERS() \
63  SYS_PRAGMA(GCC diagnostic ignored "-Wignored-qualifiers")
64 #else
65 # define SYS_PRAGMA_DISABLE_IGNORED_QUALIFIERS()
66 #endif
67 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
68 # define SYS_PRAGMA_DISABLE_UNUSED_FUNCTION() \
69  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-function")
70 #else
71 # define SYS_PRAGMA_DISABLE_UNUSED_FUNCTION()
72 #endif
73 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
74 # define SYS_PRAGMA_DISABLE_UNUSED_VALUE() \
75  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-value")
76 #else
77 # define SYS_PRAGMA_DISABLE_UNUSED_VALUE()
78 #endif
79 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
80 # define SYS_PRAGMA_DISABLE_UNUSED_VARIABLE() \
81  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-variable")
82 #else
83 # define SYS_PRAGMA_DISABLE_UNUSED_VARIABLE()
84 #endif
85 #if SYS_IS_GCC_GE(4, 6)
86 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE() \
87  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-but-set-variable")
88 #elif defined(_MSC_VER)
89 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE() \
90  SYS_PRAGMA(warning(disable: 4189))
91 #else
92 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE()
93 #endif
94 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
95 # define SYS_PRAGMA_DISABLE_COMMENT_WARNING() \
96  SYS_PRAGMA(GCC diagnostic ignored "-Wcomment")
97 #else
98 # define SYS_PRAGMA_DISABLE_COMMENT_WARNING()
99 #endif
100 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
101 # define SYS_PRAGMA_DISABLE_MISSING_FIELD_INITIALIZERS() \
102  SYS_PRAGMA(GCC diagnostic ignored "-Wmissing-field-initializers")
103 #else
104 # define SYS_PRAGMA_DISABLE_MISSING_FIELD_INITIALIZERS()
105 #endif
106 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
107 # define SYS_PRAGMA_DISABLE_NON_VIRTUAL_DTOR() \
108  SYS_PRAGMA(GCC diagnostic ignored "-Wnon-virtual-dtor")
109 #else
110 # define SYS_PRAGMA_DISABLE_NON_VIRTUAL_DTOR() \
111  SYS_PRAGMA(warning(disable: 4265))
112 #endif
113 #if SYS_IS_GCC_GE(4, 6) || SYS_IS_CLANG_GE(13, 0)
114 # define SYS_PRAGMA_DISABLE_FREE_NONHEAP_OBJECT() \
115  SYS_PRAGMA(GCC diagnostic ignored "-Wfree-nonheap-object")
116 #else
117 # define SYS_PRAGMA_DISABLE_FREE_NONHEAP_OBJECT()
118 #endif
119 
120 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
121 # define SYS_PRAGMA_DISABLE_INVALID_OFFSETOF() \
122  SYS_PRAGMA(GCC diagnostic ignored "-Winvalid-offsetof")
123 #else
124 # define SYS_PRAGMA_DISABLE_INVALID_OFFSETOF()
125 #endif
126 
127 #if defined(__clang__)
128 # define SYS_PRAGMA_DISABLE_INCONSISTENT_OVERRIDE() \
129  SYS_PRAGMA(GCC diagnostic ignored "-Winconsistent-missing-override")
130 #else
131 # define SYS_PRAGMA_DISABLE_INCONSISTENT_OVERRIDE()
132 #endif
133 
134 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
135 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED() \
136  SYS_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
137 #else
138 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED()
139 #endif
140 
141 #if defined(__clang__)
142 # define SYS_PRAGMA_DISABLE_VARARGS() \
143  SYS_PRAGMA(GCC diagnostic ignored "-Wvarargs")
144 #else
145 # define SYS_PRAGMA_DISABLE_VARARGS()
146 #endif
147 
148 // This can be used to disable the warning about ignored attributes on
149 // templates. We're likely hitting:
150 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50044
151 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
152 # define SYS_PRAGMA_DISABLE_ATTRIBUTES() \
153  SYS_PRAGMA(GCC diagnostic ignored "-Wattributes")
154 #else
155 # define SYS_PRAGMA_DISABLE_ATTRIBUTES()
156 #endif
157 
158 #if SYS_IS_CLANG_GE(10, 0)
159 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
160  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override") \
161  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-destructor-override")
162 #elif SYS_IS_GCC_GE(5, 0)
163 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
164  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override")
165 #else
166 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE()
167 #endif
168 
169 #if SYS_IS_GCC_GE(8, 0) && !defined(__clang__)
170 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN() \
171  SYS_PRAGMA(GCC diagnostic ignored "-Walloc-size-larger-than=")
172 #else
173 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN()
174 #endif
175 
176 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
177 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE() \
178  SYS_PRAGMA(GCC diagnostic ignored "-Wmismatched-new-delete")
179 #else
180 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE()
181 #endif
182 
183 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
184 # define SYS_PRAGMA_DISABLE_NON_NULL() \
185  SYS_PRAGMA(GCC diagnostic ignored "-Wnonnull")
186 #else
187 # define SYS_PRAGMA_DISABLE_NON_NULL()
188 #endif
189 
190 #endif // __SYS_PRAGMA_H_INCLUDED__