[Bug preprocessor/49928] New: Only workaround for "-Wundef" is "defined(Macro) && Macro", but it is undefined behavior?

schaub.johannes at googlemail dot com gcc-bugzilla@gcc.gnu.org
Mon Aug 1 04:37:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49928

           Summary: Only workaround for "-Wundef" is "defined(Macro) &&
                    Macro", but it is undefined behavior?
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


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

Doesn't warn anymore then. But that yields to undefined behavior and IMO it's
not intuitive, because "BAR" is still used but is undefined (this doesn't work
like short circuiting or something), so I would think GCC provides another way
to do this. 

If it doesn't exist yet, I would like to ask for a builtin, like

    #define FOO __possibly_undefined(BAR) // , or
    #define FOO ((BAR))

See https://bugs.webkit.org/show_bug.cgi?id=65401



More information about the Gcc-bugs mailing list