UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MSVCPlatformCompilerPreSetup.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_SKIP - Cause cirular dependencies for header units
6
7#if defined(__clang__)
8 // UE4 uses a struct packing of 4 for Win32 and 8 for Win64,
9 // and the default packing is 8 for Win32 and 16 for Win64
10 #ifdef _WIN64
11 #ifndef PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
12 #define PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING \
13 _Pragma("pack(push)") \
14 _Pragma("pack(16)")
15 #endif // PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
16 #else // _WIN64
17 #ifndef PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
18 #define PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING \
19 _Pragma("pack(push)") \
20 _Pragma("pack(8)")
21 #endif // PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
22 #endif // _WIN64
23
24 #ifndef PRAGMA_POP_PLATFORM_DEFAULT_PACKING
25 #define PRAGMA_POP_PLATFORM_DEFAULT_PACKING \
26 _Pragma("pack(pop)")
27 #endif // PRAGMA_POP_PLATFORM_DEFAULT_PACKING
28
30#else
31 #ifndef PRAGMA_DISABLE_DEPRECATION_WARNINGS
32 #define PRAGMA_DISABLE_DEPRECATION_WARNINGS \
33 __pragma (warning(push)) \
34 __pragma (warning(disable: 4995)) /* 'function': name was marked as #pragma deprecated */ \
35 __pragma (warning(disable: 4996)) /* The compiler encountered a deprecated declaration. */
36 #endif // PRAGMA_DISABLE_DEPRECATION_WARNINGS
37
38 #ifndef PRAGMA_ENABLE_DEPRECATION_WARNINGS
39 #define PRAGMA_ENABLE_DEPRECATION_WARNINGS \
40 __pragma (warning(pop))
41 #endif // PRAGMA_ENABLE_DEPRECATION_WARNINGS
42
43 #ifndef PRAGMA_DISABLE_BUFFER_OVERRUN_WARNING
44 #define PRAGMA_DISABLE_BUFFER_OVERRUN_WARNING \
45 __pragma (warning(push)) \
46 __pragma (warning(disable:4789)) /* buffer 'identifier' of size N bytes will be overrun; M bytes will be written starting at offset L */
47 #endif // PRAGMA_DISABLE_BUFFER_OVERRUN_WARNING
48
49 #ifndef PRAGMA_ENABLE_BUFFER_OVERRUN_WARNING
50 #define PRAGMA_ENABLE_BUFFER_OVERRUN_WARNING \
51 __pragma (warning(pop))
52 #endif // PRAGMA_ENABLE_BUFFER_OVERRUN_WARNING
53
54 #ifndef PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
55 #define PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS \
56 __pragma (warning(push)) \
57 __pragma (warning(disable: 4456)) /* declaration of 'LocalVariable' hides previous local declaration */ \
58 __pragma (warning(disable: 4457)) /* declaration of 'LocalVariable' hides function parameter */ \
59 __pragma (warning(disable: 4458)) /* declaration of 'LocalVariable' hides class member */ \
60 __pragma (warning(disable: 4459)) /* declaration of 'LocalVariable' hides global declaration */ \
61 __pragma (warning(disable: 6244)) /* local declaration of <variable> hides previous declaration at <line> of <file> */
62 #endif // PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
63
64 #ifndef PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS
65 #define PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS \
66 __pragma(warning(pop))
67 #endif // PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS
68
69 #ifndef PRAGMA_DISABLE_UNREACHABLE_CODE_WARNINGS
70 #define PRAGMA_DISABLE_UNREACHABLE_CODE_WARNINGS \
71 __pragma (warning(push)) \
72 __pragma (warning(disable: 4702)) /* unreachable code */
73 #endif // PRAGMA_DISABLE_UNREACHABLE_CODE_WARNINGS
74
75 #ifndef PRAGMA_RESTORE_UNREACHABLE_CODE_WARNINGS
76 #define PRAGMA_RESTORE_UNREACHABLE_CODE_WARNINGS \
77 __pragma (warning(pop))
78 #endif // PRAGMA_RESTORE_UNREACHABLE_CODE_WARNINGS
79
80 #ifndef PRAGMA_DISABLE_UNSAFE_TYPECAST_WARNINGS
81 #define PRAGMA_DISABLE_UNSAFE_TYPECAST_WARNINGS \
82 __pragma (warning(push)) \
83 __pragma (warning(disable: 4244)) /* 'argument': conversion from 'type1' to 'type2', possible loss of data */ \
84 __pragma (warning(disable: 4838)) /* 'argument': conversion from 'type1' to 'type2' requires a narrowing conversion */
85 #endif // PRAGMA_DISABLE_UNSAFE_TYPECAST_WARNINGS
86
87 #ifndef PRAGMA_ENABLE_UNSAFE_TYPECAST_WARNINGS
88 #define PRAGMA_ENABLE_UNSAFE_TYPECAST_WARNINGS \
89 UE_DEPRECATED_MACRO(5.0, "The PRAGMA_ENABLE_UNSAFE_TYPECAST_WARNINGS macro has been deprecated in favor of PRAGMA_RESTORE_UNSAFE_TYPECAST_WARNINGS. To force enable warnings use PRAGMA_FORCE_UNSAFE_TYPECAST_WARNINGS.")
90 #endif // PRAGMA_ENABLE_UNSAFE_TYPECAST_WARNINGS
91
92 #ifndef PRAGMA_FORCE_UNSAFE_TYPECAST_WARNINGS
93 #define PRAGMA_FORCE_UNSAFE_TYPECAST_WARNINGS \
94 __pragma (warning(push)) \
95 __pragma (warning(error: 4244)) /* 'argument': conversion from 'type1' to 'type2', possible loss of data */ \
96 __pragma (warning(error: 4838)) /* 'argument': conversion from 'type1' to 'type2' requires a narrowing conversion */
97 #endif // PRAGMA_FORCE_UNSAFE_TYPECAST_WARNINGS
98
99 #ifndef PRAGMA_RESTORE_UNSAFE_TYPECAST_WARNINGS
100 #define PRAGMA_RESTORE_UNSAFE_TYPECAST_WARNINGS \
101 __pragma(warning(pop))
102 #endif // PRAGMA_RESTORE_UNSAFE_TYPECAST_WARNINGS
103
104 #ifndef PRAGMA_DISABLE_SWITCH_UNHANDLED_ENUM_CASE_WARNINGS
105 #define PRAGMA_DISABLE_SWITCH_UNHANDLED_ENUM_CASE_WARNINGS \
106 __pragma (warning(push)) \
107 __pragma (warning(disable: 4061)) /* enumerator 'enumator' in switch of enum 'enumeration' is not explicitly handled by a case label */
108 #endif // PRAGMA_DISABLE_UNSAFE_TYPECAST_WARNINGS
109
110 #ifndef PRAGMA_RESTORE_SWITCH_UNHANDLED_ENUM_CASE_WARNINGS
111 #define PRAGMA_RESTORE_SWITCH_UNHANDLED_ENUM_CASE_WARNINGS \
112 __pragma(warning(pop))
113 #endif // PRAGMA_RESTORE_UNSAFE_TYPECAST_WARNINGS
114
115 #ifndef PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS
116 #define PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS \
117 __pragma(warning(push)) \
118 __pragma(warning(disable: 4668)) /* 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives' */
119 #endif // PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS
120
121 #ifndef PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS
122 #define PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS \
123 __pragma(warning(pop))
124 #endif // PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS
125
126 #ifndef PRAGMA_DISABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS
127 #define PRAGMA_DISABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS \
128 __pragma(warning(push)) \
129 __pragma(warning(disable: 4265)) /* class' : class has virtual functions, but destructor is not virtual */
130 #endif // PRAGMA_DISABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS
131
132 #ifndef PRAGMA_ENABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS
133 #define PRAGMA_ENABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS \
134 __pragma(warning(pop))
135 #endif // PRAGMA_ENABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS
136
137 #ifndef PRAGMA_DISABLE_REORDER_WARNINGS
138 #define PRAGMA_DISABLE_REORDER_WARNINGS \
139 __pragma(warning(push)) \
140 __pragma(warning(disable: 5038)) /* data member 'member1' will be initialized after data member 'member2' data member 'member' will be initialized after base class 'base_class' */
141 #endif // PRAGMA_DISABLE_REORDER_WARNINGS
142
143 #ifndef PRAGMA_ENABLE_REORDER_WARNINGS
144 #define PRAGMA_ENABLE_REORDER_WARNINGS \
145 __pragma(warning(pop))
146 #endif // PRAGMA_ENABLE_REORDER_WARNINGS
147
148 #ifndef PRAGMA_DISABLE_REGISTER_WARNINGS
149 #define PRAGMA_DISABLE_REGISTER_WARNINGS \
150 __pragma(warning(push)) \
151 __pragma(warning(disable: 5033)) /* 'register' is no longer a supported storage class */
152 #endif // PRAGMA_DISABLE_REGISTER_WARNINGS
153
154 #ifndef PRAGMA_ENABLE_REGISTER_WARNINGS
155 #define PRAGMA_ENABLE_REGISTER_WARNINGS \
156 __pragma(warning(pop))
157 #endif // PRAGMA_ENABLE_REGISTER_WARNINGS
158
159 #ifndef PRAGMA_DISABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
160 #define PRAGMA_DISABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
161 // MSVC doesn't seem to have a warning similar to -Wunused-private-field
162 #endif // PRAGMA_DISABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
163
164 #ifndef PRAGMA_ENABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
165 #define PRAGMA_ENABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
166 // MSVC doesn't seem to have a warning similar to -Wunused-private-field
167 #endif // PRAGMA_ENABLE_UNUSED_PRIVATE_FIELDS_WARNINGS
168
169 #ifndef PRAGMA_DISABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
170 #define PRAGMA_DISABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
171 // MSVC doesn't seem to have a warning similar to -Wuninitialized-const-reference
172 #endif // PRAGMA_DISABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
173
174 #ifndef PRAGMA_ENABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
175 #define PRAGMA_ENABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
176 // MSVC doesn't seem to have a warning similar to -Wuninitialized-const-reference
177 #endif // PRAGMA_ENABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS
178
179 #ifndef PRAGMA_DISABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
180 #define PRAGMA_DISABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
181 // MSVC doesn't seem to have a warning similar to -Wenum-constexpr-conversion
182 #endif // PRAGMA_DISABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
183
184 #ifndef PRAGMA_ENABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
185 #define PRAGMA_ENABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
186 // MSVC doesn't seem to have a warning similar to -Wenum-constexpr-conversion
187 #endif // PRAGMA_ENABLE_ENUM_CONSTEXPR_CONVERSION_WARNINGS
188
189 #ifndef PRAGMA_DISABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
190 #define PRAGMA_DISABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
191 // MSVC doesn't seem to have a warning similar to -Wdeprecated-copy-with-user-provided-copy
192 #endif // PRAGMA_DISABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
193
194 #ifndef PRAGMA_ENABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
195 #define PRAGMA_ENABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
196 // MSVC doesn't seem to have a warning similar to -Wdeprecated-copy-with-user-provided-copy
197 #endif // PRAGMA_ENABLE_DEPRECATED_COPY_WITH_USER_DEFINED_COPY_WARNINGS
198
199 #ifndef PRAGMA_DISABLE_NONPORTABLE_INCLUDE_PATH_WARNING
200 #define PRAGMA_DISABLE_NONPORTABLE_INCLUDE_PATH_WARNING
201 // MSVC doesn't seem to have a warning similar to -Wnonportable-include-path
202 #endif // PRAGMA_DISABLE_NONPORTABLE_INCLUDE_PATH_WARNING
203
204 #ifndef PRAGMA_ENABLE_NONPORTABLE_INCLUDE_PATH_WARNING
205 #define PRAGMA_ENABLE_NONPORTABLE_INCLUDE_PATH_WARNING
206 // MSVC doesn't seem to have a warning similar to -Wnonportable-include-path
207 #endif // PRAGMA_ENABLE_NONPORTABLE_INCLUDE_PATH_WARNING
208
209 #ifndef PRAGMA_POP
210 #define PRAGMA_POP \
211 __pragma(warning(pop))
212 #endif // PRAGMA_POP
213
214 // UE4 uses a struct packing of 4 for Win32 and 8 for Win64,
215 // and the default packing is 8 for Win32 and 16 for Win64
216 #ifdef _WIN64
217 #ifndef PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
218 #define PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING \
219 __pragma(pack(push, 16))
220 #endif // PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
221 #else // _WIN64
222 #ifndef PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
223 #define PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING \
224 __pragma(pack(push, 8))
225 #endif // PRAGMA_PUSH_PLATFORM_DEFAULT_PACKING
226 #endif // _WIN64
227
228 #ifndef PRAGMA_POP_PLATFORM_DEFAULT_PACKING
229 #define PRAGMA_POP_PLATFORM_DEFAULT_PACKING \
230 __pragma(pack(pop))
231 #endif // PRAGMA_POP_PLATFORM_DEFAULT_PACKING
232
233 // Disable common CA warnings around SDK includes
234 #ifndef UE_COMPILER_THIRD_PARTY_INCLUDES_START
235 #define UE_COMPILER_THIRD_PARTY_INCLUDES_START \
236 __pragma(warning(push)) \
237 __pragma(warning(disable: 4125)) /* decimal digit terminates octal escape sequence. */ \
238 __pragma(warning(disable: 4510)) /* '<class>': default constructor could not be generated. */ \
239 __pragma(warning(disable: 4610)) /* object '<class>' can never be instantiated - user-defined constructor required. */ \
240 __pragma(warning(disable: 4800)) /* Implicit conversion from '<type>' to bool. Possible information loss. */ \
241 __pragma(warning(disable: 4946)) /* reinterpret_cast used between related classes: '<class1>' and '<class2>' */ \
242 __pragma(warning(disable: 4996)) /* '<obj>' was declared deprecated. */ \
243 __pragma(warning(disable: 6011)) /* Dereferencing NULL pointer '<ptr>'. */ \
244 __pragma(warning(disable: 6101)) /* Returning uninitialized memory '<expr>'. A successful path through the function does not set the named _Out_ parameter. */ \
245 __pragma(warning(disable: 6287)) /* Redundant code: the left and right sub-expressions are identical. */ \
246 __pragma(warning(disable: 6308)) /* 'realloc' might return null pointer: assigning null pointer to 'X', which is passed as an argument to 'realloc', will cause the original memory block to be leaked. */ \
247 __pragma(warning(disable: 6326)) /* Potential comparison of a constant with another constant. */ \
248 __pragma(warning(disable: 6340)) /* Mismatch on sign: Incorrect type passed as parameter in call to function. */ \
249 __pragma(warning(disable: 6385)) /* Reading invalid data from '<ptr>': the readable size is '<num1>' bytes, but '<num2>' bytes may be read. */ \
250 __pragma(warning(disable: 6386)) /* Buffer overrun while writing to '<ptr>': the writable size is '<num1>' bytes, but '<num2>' bytes might be written. */ \
251 __pragma(warning(disable: 6553)) /* The annotation for function '<func>' on _Param_(<num>) does not apply to a value type. */ \
252 __pragma(warning(disable: 28182)) /* Dereferencing NULL pointer. '<ptr1>' contains the same NULL value as '<ptr2>' did. */ \
253 __pragma(warning(disable: 28251)) /* Inconsistent annotation for '<func>': this instance has no annotations. */ \
254 __pragma(warning(disable: 28252)) /* Inconsistent annotation for '<func>': return/function has '<annotation>' on the prior instance. */ \
255 __pragma(warning(disable: 28253)) /* Inconsistent annotation for '<func>': _Param_(<num>) has '<annotation>' on the prior instance. */ \
256 __pragma(warning(disable: 28301)) /* No annotations for first declaration of '<func>'. */ \
257 PRAGMA_DISABLE_REORDER_WARNINGS \
258 PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS \
259 PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS \
260 PRAGMA_DISABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS \
261 PRAGMA_DISABLE_DEPRECATION_WARNINGS \
262 PRAGMA_DISABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS \
263 PRAGMA_DISABLE_UNREACHABLE_CODE_WARNINGS
264 #endif // THIRD_PARTY_INCLUDES_START
265
266 #ifndef UE_COMPILER_THIRD_PARTY_INCLUDES_END
267 #define UE_COMPILER_THIRD_PARTY_INCLUDES_END \
268 PRAGMA_RESTORE_UNREACHABLE_CODE_WARNINGS \
269 PRAGMA_ENABLE_UNINITIALIZED_CONST_REFERENCE_WARNINGS \
270 PRAGMA_ENABLE_DEPRECATION_WARNINGS \
271 PRAGMA_ENABLE_MISSING_VIRTUAL_DESTRUCTOR_WARNINGS \
272 PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS \
273 PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS \
274 PRAGMA_ENABLE_REORDER_WARNINGS \
275 __pragma(warning(pop))
276 #endif // THIRD_PARTY_INCLUDES_END
277
278 #define EMIT_CUSTOM_WARNING_AT_LINE(Line, Warning) \
279 __pragma(message(WARNING_LOCATION(Line) ": warning C4996: " Warning))
280
281 #define EMIT_CUSTOM_ERROR_AT_LINE(Line, Error) \
282 __pragma(message(WARNING_LOCATION(Line) ": error C4996: " Error))
283
284 #ifndef PRAGMA_PUSH_ATTRIBUTE_MINSIZE_FUNCTIONS
285 #define PRAGMA_PUSH_ATTRIBUTE_MINSIZE_FUNCTIONS // no-op for now
286 #endif // PRAGMA_PUSH_ATTRIBUTE_MINSIZE_FUNCTIONS
287
288 #ifndef PRAGMA_POP_ATTRIBUTE_MINSIZE_FUNCTIONS
289 #define PRAGMA_POP_ATTRIBUTE_MINSIZE_FUNCTIONS // no-op for now
290 #endif // PRAGMA_POP_ATTRIBUTE_MINSIZE_FUNCTIONS
291
292 #ifndef PGO_LINK_DISABLE_WARNINGS
293 #define PGO_LINK_DISABLE_WARNINGS PRAGMA_DISABLE_BUFFER_OVERRUN_WARNING
294 #endif
295
296 #ifndef PGO_LINK_ENABLE_WARNINGS
297 #define PGO_LINK_ENABLE_WARNINGS PRAGMA_ENABLE_BUFFER_OVERRUN_WARNING
298 #endif
299#endif // defined(__clang__)