[Bug preprocessor/49928] Only workaround for "-Wundef" is "defined(Macro) && Macro", but it is undefined behavior?
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Sep 28 23:29:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49928
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Johannes Schaub from comment #0)
> It appears that to inhibit a warning about using an undefined macro
> identifier, one has to employ the following work-around
>
> #define FOO BAR
> #if FOO // warns about 'BAR'
>
> Instead:
>
> #define FOO defined BAR && BAR
> #if FOO
I don't think a new GCC-specific builtin just to avoid an optional warning is a
good idea.
It seems to me that a better workaround that doesn't involve undefined
behaviour, and is much simpler to understand, would be to simply ensure that
BAR is always defined:
#define BAR 0
#define FOO BAR
If WebKit wants to be able to compile cleanly with -Wundef then they should
ensure all macros are defined, not create nasty hacks using undefined
behaviour.
So e.g.
// define everything to 0 initially
#define WTF_PLATFORM_CHROMIUM 0
#define WTF_PLATFORM_QT 0
#define WTF_PLATFORM_MAC 0
#if defined(BUILDING_CHROMIUM__)
# undef WTF_PLATFORM_CHROMIUM
# define WTF_PLATFORM_CHROMIUM 1
#elif ...
Alternatively, it would be nice to use:
#pragma GCC diagnostic ignored "-Wundef"
to suppress the warnings in code bases that are (by design) not compatible with
-Wundef ... unfortunately that doesn't work (PR 53431).
More information about the Gcc-bugs
mailing list