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]

preprocessor/4976: cpp fails to warn about macro redefinitions

[Get raw message]

>Number:         4976
>Category:       preprocessor
>Synopsis:       cpp fails to warn about macro redefinitions
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 30 14:16:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Matthew Fredette
>Release:        gcc-3.0.2
>Organization:
>Environment:
NetBSD the-gates-of-delirium.home 1.5W NetBSD 1.5W (THE-GATES-OF-DELIRIUM) #3: Fri Jul 13 09:31:17 EDT 2001     root@the-gates-of-delirium:/data/union-i386/src/sys/arch/i386/compile/THE-GATES-OF-DELIRIUM i386
>Description:
cpp fails to warn about macro redefinitions.

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.

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.
>How-To-Repeat:
Try to preprocess a file that defines a macro, then redefines
it with a different value.
>Fix:
Remove the ! from the test at line 1426 of gcc/gcc/cppmacro.c, revision 1.87.
Replace NODE_WARN with NODE_BUILTIN at line 496 of gcc/gcc/gcclib.c, revision 1.287.
>Release-Note:
>Audit-Trail:
>Unformatted:


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