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  SYS_PRAGMA(GCC diagnostic ignored "-Winconsistent-missing-destructor-override")
137 #else
138 # define SYS_PRAGMA_DISABLE_INCONSISTENT_OVERRIDE()
139 #endif
140 
141 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
142 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED() \
143  SYS_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
144 #else
145 # define SYS_PRAGMA_DISABLE_MAYBE_UNINITIALIZED()
146 #endif
147 
148 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
149 # define SYS_PRAGMA_DISABLE_UNINITIALIZED() \
150  SYS_PRAGMA(GCC diagnostic ignored "-Wuninitialized")
151 #else
152 # define SYS_PRAGMA_DISABLE_UNINITIALIZED()
153 #endif
154 
155 #if defined(__clang__)
156 # define SYS_PRAGMA_DISABLE_VARARGS() \
157  SYS_PRAGMA(GCC diagnostic ignored "-Wvarargs")
158 #else
159 # define SYS_PRAGMA_DISABLE_VARARGS()
160 #endif
161 
162 // This can be used to disable the warning about ignored attributes on
163 // templates. We're likely hitting:
164 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50044
165 #if SYS_IS_GCC_GE(4, 8) && !defined(__clang__)
166 # define SYS_PRAGMA_DISABLE_ATTRIBUTES() \
167  SYS_PRAGMA(GCC diagnostic ignored "-Wattributes")
168 #else
169 # define SYS_PRAGMA_DISABLE_ATTRIBUTES()
170 #endif
171 
172 #if SYS_IS_CLANG_GE(10, 0)
173 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
174  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override") \
175  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-destructor-override")
176 #elif SYS_IS_GCC_GE(5, 0)
177 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE() \
178  SYS_PRAGMA(GCC diagnostic ignored "-Wsuggest-override")
179 #else
180 # define SYS_PRAGMA_DISABLE_SUGGEST_OVERRIDE()
181 #endif
182 
183 #if SYS_IS_GCC_GE(8, 0) && !defined(__clang__)
184 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN() \
185  SYS_PRAGMA(GCC diagnostic ignored "-Walloc-size-larger-than=")
186 #else
187 # define SYS_PRAGMA_DISABLE_ALLOC_SIZE_LARGER_THAN()
188 #endif
189 
190 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
191 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE() \
192  SYS_PRAGMA(GCC diagnostic ignored "-Wmismatched-new-delete")
193 #else
194 # define SYS_PRAGMA_DISABLE_MISMATCHED_NEW_DELETE()
195 #endif
196 
197 #if SYS_IS_GCC_GE(11, 0) && !defined(__clang__)
198 # define SYS_PRAGMA_DISABLE_NON_NULL() \
199  SYS_PRAGMA(GCC diagnostic ignored "-Wnonnull")
200 #else
201 # define SYS_PRAGMA_DISABLE_NON_NULL()
202 #endif
203 
204 #endif // __SYS_PRAGMA_H_INCLUDED__