Bug 97998 - GCC should not complain about double definitions of macros whose names begin with __STDC_
Summary: GCC should not complain about double definitions of macros whose names begin ...
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2020-11-25 19:57 UTC by Zack Weinberg
Modified: 2020-11-26 21:54 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Zack Weinberg 2020-11-25 19:57:25 UTC
Normally, GCC does not warn about a second definition of a preprocessor macro with the exact same expansion:

    #define some_ordinary_macro 1
    #define some_ordinary_macro 1   /* no diagnostic */

However, GCC 9 and 10 *do* complain about this kind of redefinition if the name of the macro begins with __STDC_:

    #define __STDC_anything 1
    #define __STDC_anything 1     /* warning: "__STDC_anything" redefined */

In particular, it will complain about double definitions of the various __STDC_WANT_*__ macros.  The upcoming autoconf 2.70 will start defining many of those macros when the script uses AC_USE_SYSTEM_EXTENSIONS, and this broke code in APR's configure script that included the internal 'confdefs.h' (which accumulates the various #defines that will be emitted into config.h) a second time (autoconf test programs always include confdefs.h before doing anything else)

I think GCC should treat __STDC_ macros the same as ordinary macros - no warning for a second definition with the same expansion.  N.B. clang already behaves this way.

(If the second definition has a *different* expansion, GCC complains regardless of the macro's name, and that behavior should not be changed.)
Comment 1 Zack Weinberg 2020-11-25 19:58:12 UTC
For more information see Autoconf bug report <https://savannah.gnu.org/support/?110382> and APR pull request <https://github.com/apache/apr/pull/25>.
Comment 2 jsm-csl@polyomino.org.uk 2020-11-25 21:41:25 UTC
In bug 91451 I suggested changing this specifically for __STDC_WANT_*.
Comment 3 Zack Weinberg 2020-11-25 21:52:37 UTC
Rather than an ever-growing list of macros that need exempting from this rule, I would suggest flipping it around and only complaining about the "standard predefined" and "common predefined" macros (as the manual uses those terms).