public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug preprocessor/32868]  New: Don't warn about redefinitions of __STDC_FORMAT_MACROS
@ 2007-07-23 17:28 ian at airs dot com
  2007-07-26 21:33 ` [Bug preprocessor/32868] " tromey at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ian at airs dot com @ 2007-07-23 17:28 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-11-30 18:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-23 17:28 [Bug preprocessor/32868] New: Don't warn about redefinitions of __STDC_FORMAT_MACROS ian at airs dot com
2007-07-26 21:33 ` [Bug preprocessor/32868] " tromey at gcc dot gnu dot org
2007-11-27 20:53 ` tromey at gcc dot gnu dot org
2007-11-28 14:29 ` ian at airs dot com
2007-11-28 16:26 ` tromey at gcc dot gnu dot org
2007-11-30 18:24 ` tromey at gcc dot gnu dot org
2007-11-30 18:25 ` tromey at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).