This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug preprocessor/32868] New: Don't warn about redefinitions of __STDC_FORMAT_MACROS


Compiling this C or C++ file:

#define __STDC_FORMAT_MACROS 1
#define __STDC_FORMAT_MACROS 1

produces these warnings:

foo.c:2:1: warning: "__STDC_FORMAT_MACROS" redefined
foo.c:1:1: warning: this is the location of the previous definition

This is because of these lines in libcpp/macro.c:

  if (! ustrncmp (NODE_NAME (node), DSC ("__STDC_")))
    node->flags |= NODE_WARN;

The idea behind these lines is sound: the compiler defines macros whose name
begins with "__STDC_".  The user should not redefine them.

However, __STDC_FORMAT_MACROS is an exception here.  This macro is not defined
by the compiler.  It is intended to be defined by the user when compiling a C++
file to direct the <stdint.h> header file to define macros PRId32 and friends. 
See footnote 182 in section 7.8.1 in C99.

If the user defines the macro in a .h file, as is permitted, then including
that some .h file twice, if it does not have an include guard, will give an
inappropriate warning.  In particular this can happen with an autoconf-style
config.h file, as autoconf does not generate include guards for such files.

I expect that the right fix is to specifically exclude __STDC_FORMAT_MACROS
from this warning.  Or perhaps another approach would be to specially mark the
macros defined in cpp_init_builtins.


-- 
           Summary: Don't warn about redefinitions of __STDC_FORMAT_MACROS
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]