From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14552 invoked by alias); 30 Nov 2001 23:06:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 14513 invoked by uid 71); 30 Nov 2001 23:06:01 -0000 Date: Fri, 23 Nov 2001 00:45:00 -0000 Message-ID: <20011130230601.14509.qmail@sourceware.cygnus.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Neil Booth Subject: Re: preprocessor/4976: cpp fails to warn about macro redefinitions Reply-To: Neil Booth X-SW-Source: 2001-11/txt/msg00786.txt.bz2 List-Id: The following reply was made to PR preprocessor/4976; it has been noted by GNATS. From: Neil Booth 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.