This is the mail archive of the gcc-prs@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]

Re: preprocessor/4976: cpp fails to warn about macro redefinitions

[Get raw message]
The following reply was made to PR preprocessor/4976; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.demon.co.uk>
To: fredette@mit.edu
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: preprocessor/4976: cpp fails to warn about macro redefinitions
Date: Fri, 30 Nov 2001 23:02:13 +0000

 fredette@mit.edu wrote:-
 
 > cpp fails to warn about macro redefinitions.
 
 It was changed to only warn if -pedantic, for a reason lost in the
 mists of time.
 
 > gcc/gcc/cppmacro.c revision 1.46 introduced the NODE_WARN flag, with  
 > this code at the end of the _cpp_create_definition function:
 > 
 >  if (! ustrncmp (node->name, DSC ("__STDC_")))  
 >    node->flags |= NODE_WARN;
 > 
 > It is this NODE_WARN flag that is supposed to trigger (through the 
 > warn_of_redefinition function) a warning when a macro is redefined.  
 > 
 > The test seems wrong - as ustrncmp behaves like strncmp, this test  
 > will fail for all macros other than __STDC__.  I.e., only a  
 > redefined __STDC__ macro node will happen to get this flag.
 
 No, it will warn for any macro beginning with __STDC_ since that
 namespace is reserved.
 
 > Further, gcc/gcc/cpplib.c revision 1.240, in the do_undef function,
 > replaced a check of NODE_BUILTIN with NODE_WARN.  Assuming 
 > that normal macros are supposed to be tagged with NODE_WARN,  
 > this check is also wrong, because it will cause a warning
 > whenever a normal macro is undefined.
 
 No, normal macros are not tagged NODE_WARN.  If you look more closely
 at the code, you'd observe that macros tagged NODE_WARN trigger
 warnings unconditionally when redefined or undefined.
 
 Further, you would notice that NODE_WARN macros are precisely those
 beginning with __STDC_ and builtins like __TIME__ and __LINE__.
 
 We don't want code like
 
 #define x some thing
 #define x    some /* Comment.  */ thing
 
 to give a warning; the standard explicitly permits such things.  If
 all macros were tagged NODE_WARN, then everything would warn and there
 would be no point in the warn_of_redefinition() function.
 
 What causes non-trivial redefinitions of normal macros to be ignored
 in your case is the check for -pedantic in warn_of_redefinition().
 That was removed last week, and GCC 3.0.3 and 3.1 will warn regardless
 of -pedantic.
 
 Neil.


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