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(__clang__)
51 # define SYS_PRAGMA_DISABLE_DEPRECATED_COPY_DTOR() \
52  SYS_PRAGMA(clang diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor")
53 #else
54 # define SYS_PRAGMA_DISABLE_DEPRECATED_COPY_DTOR()
55 #endif
56 #if defined(_MSC_VER)
57 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL() \
58  SYS_PRAGMA(warning(disable: 4263)) \
59  SYS_PRAGMA(warning(disable: 4266)) \
60  /**/
61 #elif SYS_IS_GCC_GE(4, 6) || defined(__clang__)
62 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL() \
63  SYS_PRAGMA(GCC diagnostic ignored "-Woverloaded-virtual")
64 #else
65 # define SYS_PRAGMA_DISABLE_OVERLOADED_VIRTUAL()
66 #endif
67 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
68 # define SYS_PRAGMA_DISABLE_IGNORED_QUALIFIERS() \
69  SYS_PRAGMA(GCC diagnostic ignored "-Wignored-qualifiers")
70 #else
71 # define SYS_PRAGMA_DISABLE_IGNORED_QUALIFIERS()
72 #endif
73 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
74 # define SYS_PRAGMA_DISABLE_UNUSED_FUNCTION() \
75  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-function")
76 #else
77 # define SYS_PRAGMA_DISABLE_UNUSED_FUNCTION()
78 #endif
79 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
80 # define SYS_PRAGMA_DISABLE_UNUSED_VALUE() \
81  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-value")
82 #else
83 # define SYS_PRAGMA_DISABLE_UNUSED_VALUE()
84 #endif
85 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
86 # define SYS_PRAGMA_DISABLE_UNUSED_VARIABLE() \
87  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-variable")
88 #else
89 # define SYS_PRAGMA_DISABLE_UNUSED_VARIABLE()
90 #endif
91 #if SYS_IS_GCC_GE(4, 6)
92 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE() \
93  SYS_PRAGMA(GCC diagnostic ignored "-Wunused-but-set-variable")
94 #elif defined(_MSC_VER)
95 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE() \
96  SYS_PRAGMA(warning(disable: 4189))
97 #else
98 # define SYS_PRAGMA_DISABLE_UNUSED_BUT_SET_VARIABLE()
99 #endif
100 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
101 # define SYS_PRAGMA_DISABLE_COMMENT_WARNING() \
102  SYS_PRAGMA(GCC diagnostic ignored "-Wcomment")
103 #else
104 # define SYS_PRAGMA_DISABLE_COMMENT_WARNING()
105 #endif
106 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
107 # define SYS_PRAGMA_DISABLE_MISSING_FIELD_INITIALIZERS() \
108  SYS_PRAGMA(GCC diagnostic ignored "-Wmissing-field-initializers")
109 #else
110 # define SYS_PRAGMA_DISABLE_MISSING_FIELD_INITIALIZERS()
111 #endif
112 #if SYS_IS_GCC_GE(4, 6) || defined(__clang__)
113 # define SYS_PRAGMA_DISABLE_NON_VIRTUAL_DTOR() \
114  SYS_PRAGMA(GCC diagnostic ignored "-Wnon-virtual-dtor")
115 #else
116 # define SYS_PRAGMA_DISABLE_NON_VIRTUAL_DTOR() \
117  SYS_PRAGMA(warning(disable: 4265))
118 #endif
119 #if SYS_IS_GCC_GE(4, 6) || SYS_IS_CLANG_GE(13, 0)
120 # define SYS_PRAGMA_DISABLE_FREE_NONHEAP_OBJECT() \
121  SYS_PRAGMA(GCC diagnostic ignored "-Wfree-nonheap-object")
122 #else
123 # define SYS_PRAGMA_DISABLE_FREE_NONHEAP_OBJECT()
124 #endif
125 
126 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
127 # define SYS_PRAGMA_DISABLE_INVALID_OFFSETOF() \
128  SYS_PRAGMA(GCC diagnostic ignored "-Winvalid-offsetof")
129 #else
130 # define SYS_PRAGMA_DISABLE_INVALID_OFFSETOF()
131 #endif
132 
133 #if defined(__clang__)
134 # define SYS_PRAGMA_DISABLE_INCONSISTENT_OVERRIDE() \
135  SYS_PRAGMA(GCC diagnostic ignored "-Winconsistent-missing-override")
136 #else
137 # define SYS_PRAGMA_DISABLE_INCONSISTENT_OVERRIDE()
138 #endif
139 
140 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
141 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED() \
142  SYS_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
143 #else
144 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED()
145 #endif
146 
147 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
148 # define SYS_PRAGMA_DISABLE_UNINITIALIZED() \
149  SYS_PRAGMA(GCC diagnostic ignored "-Wuninitialized")
150 #else
151 # define SYS_PRAGMA_DISABLE_UNINITIALIZED()
152 #endif
153 
154 #if defined(__clang__)
155 # define SYS_PRAGMA_DISABLE_VARARGS() \
156  SYS_PRAGMA(GCC diagnostic ignored "-Wvarargs")
157 #else
158 # define SYS_PRAGMA_DISABLE_VARARGS()
159 #endif
160 
161 // This can be used to disable the warning about ignored attributes on
162 // templates. We're likely hitting:
163 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50044
164 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
165 # define SYS_PRAGMA_DISABLE_ATTRIBUTES() \
166  SYS_PRAGMA(GCC diagnostic ignored "-Wattributes")
167 #else
168 # define SYS_PRAGMA_DISABLE_ATTRIBUTES()
169 #endif
170 
171 #if SYS_IS_CLANG_GE(10, 0)
172 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
173  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override") \
174  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-destructor-override")
175 #elif SYS_IS_GCC_GE(5, 0)
176 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
177  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override")
178 #else
179 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE()
180 #endif
181 
182 #if SYS_IS_GCC_GE(8, 0) && !defined(__clang__)
183 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN() \
184  SYS_PRAGMA(GCC diagnostic ignored "-Walloc-size-larger-than=")
185 #else
186 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN()
187 #endif
188 
189 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
190 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE() \
191  SYS_PRAGMA(GCC diagnostic ignored "-Wmismatched-new-delete")
192 #else
193 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE()
194 #endif
195 
196 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
197 # define SYS_PRAGMA_DISABLE_NON_NULL() \
198  SYS_PRAGMA(GCC diagnostic ignored "-Wnonnull")
199 #else
200 # define SYS_PRAGMA_DISABLE_NON_NULL()
201 #endif
202 
203 #endif // __SYS_PRAGMA_H_INCLUDED__