[patch] macro redefinition with different token count

DJ Delorie dj@redhat.com
Sun Jun 1 18:56:00 GMT 2003


> Cool, thanks.  I'm sure it was there one day, maybe it got blown
> away somehow.

Here's the patch as committed:

2003-06-01  DJ Delorie  <dj@redhat.com>

	* cppmacro.c (warn_of_redefinition): Handle cases where the two
	definitions have different numbers of tokens.

Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.133
diff -p -2 -r1.133 cppmacro.c
*** cppmacro.c	24 Apr 2003 20:03:57 -0000	1.133
--- cppmacro.c	1 Jun 2003 18:54:27 -0000
*************** warn_of_redefinition (pfile, node, macro
*** 1276,1283 ****
      return _cpp_expansions_different_trad (macro1, macro2);
  
!   if (macro1->count == macro2->count)
!     for (i = 0; i < macro1->count; i++)
!       if (!_cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
! 	return true;
  
    return false;
--- 1276,1285 ----
      return _cpp_expansions_different_trad (macro1, macro2);
  
!   if (macro1->count != macro2->count)
!     return true;
! 
!   for (i = 0; i < macro1->count; i++)
!     if (!_cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
!       return true;
  
    return false;


2003-06-01  Loren James Rittle  <ljrittle@acm.org>
	
	* gcc.dg/cpp/redef3.c: New file.

Index: testsuite/gcc.dg/cpp/redef3.c
===================================================================
RCS file: testsuite/gcc.dg/cpp/redef3.c
diff -N testsuite/gcc.dg/cpp/redef3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/cpp/redef3.c	1 Jun 2003 18:54:28 -0000
***************
*** 0 ****
--- 1,21 ----
+ /* Test for redefining macros with mismatch token count (and the oddity). */
+ 
+ /* { dg-do preprocess } */
+ /* { dg-options "-DC -DD=1 -DE" } */
+ 
+ #define A
+ #define A 1
+ #define B 2 3
+ #define B 2
+ #define C 1
+ #define D 1 2
+ #define E
+ 
+ /* { dg-warning "redefined" "redef A"      { target *-*-* } 7  }
+    { dg-warning "redefined" "redef B"      { target *-*-* } 9  }
+    { dg-warning "redefined" "redef D"      { target *-*-* } 11 }
+    { dg-warning "redefined" "redef E"      { target *-*-* } 12 }
+    { dg-warning "previous"  "prev def A"   { target *-*-* } 6  }
+    { dg-warning "previous"  "prev def B"   { target *-*-* } 8  }
+    { dg-warning "previous"  "prev def D/E" { target *-*-* } 0  }
+ */



More information about the Gcc-patches mailing list