Skip to content

Commit 042b1b5

Browse files
committed
preprocessor tweak - use new Standard Conforming Preprocessor when building with MSVC, addresses microsoft#7042
1 parent 5adc27f commit 042b1b5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHI
114114
add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
115115
endif()
116116

117+
if(MSVC)
118+
# use new Standard Conforming Preprocessor
119+
# https://learn.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-170
120+
add_compile_options(/Zc:preprocessor)
121+
endif()
122+
117123
# enable control flow guard
118124
if(WIN32)
119125
if(MSVC)

include/dxc/Support/Global.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {
295295
// This prints 'Hello World (i > 10)' and breaks in the debugger if the
296296
// assertion doesn't hold.
297297
//
298+
299+
#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
298300
#define DXASSERT_ARGS(exp, fmt, ...) \
299301
do { \
300302
if (!(exp)) { \
@@ -304,6 +306,19 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {
304306
__debugbreak(); \
305307
} \
306308
} while (0)
309+
#else
310+
#define DXASSERT_ARGS(exp, fmt, ...) \
311+
do { \
312+
if (!(exp)) { \
313+
OutputDebugFormatA("Error: \t%s\nFile:\n%s(%d)\nFunc:\t%s.\n\t" fmt \
314+
"\n", \
315+
"!(" #exp ")", __FILE__, __LINE__, \
316+
__FUNCTION__ __VA_OPT__(, ) __VA_ARGS__); \
317+
__debugbreak(); \
318+
} \
319+
} while (0)
320+
#endif
321+
307322
#define DXASSERT(exp, msg) DXASSERT_ARGS(exp, msg)
308323

309324
#define DXASSERT_LOCALVAR(local, exp, msg) DXASSERT(exp, msg)
@@ -325,13 +340,23 @@ inline void OutputDebugFormatA(const char *pszFormat, ...) {
325340

326341
#define DXVERIFY_NOMSG assert
327342

343+
#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
328344
#define DXASSERT_ARGS(expr, fmt, ...) \
329345
do { \
330346
if (!(expr)) { \
331347
fprintf(stderr, fmt, __VA_ARGS__); \
332348
assert(false); \
333349
} \
334350
} while (0)
351+
#else
352+
#define DXASSERT_ARGS(expr, fmt, ...) \
353+
do { \
354+
if (!(expr)) { \
355+
fprintf(stderr, fmt __VA_OPT__(, ) __VA_ARGS__); \
356+
assert(false); \
357+
} \
358+
} while (0)
359+
#endif
335360

336361
#define DXASSERT(expr, msg) \
337362
do { \

0 commit comments

Comments
 (0)