arocc icon indicating copy to clipboard operation
arocc copied to clipboard

Macro expansion which produces defined(X)

Open ehaas opened this issue 3 years ago • 0 comments

This is undefined behavior according to the C standard but both gcc and clang treat it like defined is a function-like macro:

#define FOO_IS_DEFINED defined(FOO)
#define FOO

#if FOO_IS_DEFINED
#error "FOO is defined"
#endif

clang warns test.c:4:5: warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]

Both will evaluate the #if condition to true and will display the "FOO is defined" error message.

aro currently says error: function-like macro 'defined' is not defined

ehaas avatar Jul 13 '22 00:07 ehaas