This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: New bug in cpp, bogus macro redefinition warnings
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: New bug in cpp, bogus macro redefinition warnings
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Wed, 1 Mar 2000 09:37:34 -0800
- Cc: egcs-bugs at egcs dot cygnus dot com, egcs-patches at egcs dot cygnus dot com
- References: <200003011624.LAA09971@caip.rutgers.edu>
On Wed, Mar 01, 2000 at 11:24:37AM -0500, Kaveh R. Ghazi wrote:
> Bootstrapping last night's snapshot on sparc-sun-solaris2.7 exposed a
> new bug in cpp. I get large amounts of macro redefinition warnings
> (~1200) from the system headers.
>
> They come from macros defined to the same value more than once, but
> one instance is followed by a comment. E.g. you can see what I mean
> in the following two line file.
>
> > #define FOO 10 /* sdf */
> > #define FOO 10
>
> (Perhaps you want to install this as a test case.)
>
> With last night's "gcc version 2.96 20000229 (experimental)", it gives:
>
> > foo.c:2:14: warning: `FOO' redefined
> > foo.c:1:11: warning: this is the location of the previous definition
Aaargh. Yes, I see the problem. Please try this patch - will commit,
with test case, once it completes bootstrap.
zw
* cpphash.c (collect_expansion): Remove trailing whitespace
from macro definitions.
===================================================================
Index: cpphash.c
--- cpphash.c 2000/03/01 00:57:08 1.42
+++ cpphash.c 2000/03/01 17:36:40
@@ -487,6 +487,10 @@ collect_expansion (pfile, arglist)
else if (last_token == PASTE)
cpp_error (pfile, "`##' at end of macro definition");
+ /* Trim trailing white space from definition. */
+ while (is_hspace (CPP_PWRITTEN (pfile)[-1]))
+ CPP_ADJUST_WRITTEN (pfile, -1);
+
CPP_NUL_TERMINATE (pfile);
len = CPP_WRITTEN (pfile) - start + 1;
exp = xmalloc (len + 4); /* space for no-concat markers at either end */