]> gcc.gnu.org Git - gcc.git/commitdiff
c-decl.c (xref_tag): Don't return previous tags of wrong type.
authorJoseph Myers <jsm28@cam.ac.uk>
Mon, 11 Jun 2001 11:50:29 +0000 (12:50 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 11 Jun 2001 11:50:29 +0000 (12:50 +0100)
* c-decl.c (xref_tag): Don't return previous tags of wrong type.

testsuite:
* gcc.dg/c99-tag-1.c: Add more tests.

From-SVN: r43179

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-tag-1.c

index ad24ae548020fae6f3565fa92a11cc8caf02671a..fe8a6199aa4eb6385f8cd8ce3b7cdce8895952ab 100644 (file)
@@ -1,3 +1,7 @@
+2001-06-11  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-decl.c (xref_tag): Don't return previous tags of wrong type.
+
 2001-06-11  Aldy Hernandez  <aldyh@redhat.com>
 
         * loop.c (scan_loop): Do not combine asm statements.
index 78c852e214f7de49bfdcbf8fb12be8410fe00091..b68f7721a587dc9de04cff844a65e1272fcc6eb8 100644 (file)
@@ -5226,11 +5226,18 @@ xref_tag (code, name)
      already defined for this tag and return it.  */
 
   register tree ref = lookup_tag (code, name, current_binding_level, 0);
-  /* Even if this is the wrong type of tag, return what we found.
-     There will be an error message anyway, from pending_xref_error.
-     If we create an empty xref just for an invalid use of the type,
-     the main result is to create lots of superfluous error messages.  */
-  if (ref)
+  /* If this is the right type of tag, return what we found.
+     (This reference will be shadowed by shadow_tag later if appropriate.)
+     If this is the wrong type of tag, do not return it.  If it was the
+     wrong type in the same binding level, we will have had an error
+     message already; if in a different binding level and declaring
+     a name, pending_xref_error will give an error message; but if in a
+     different binding level and not declaring a name, this tag should
+     shadow the previous declaration of a different type of tag, and
+     this would not work properly if we return the reference found.
+     (For example, with "struct foo" in an outer scope, "union foo;"
+     must shadow that tag with a new one of union type.)  */
+  if (ref && TREE_CODE (ref) == code)
     return ref;
 
   /* If no such tag is yet defined, create a forward-reference node
index 467a5e4316f187e4980d735232ee7e3333fc35a2..d1255208049272a2c2690d09b182be396e505911 100644 (file)
@@ -1,3 +1,7 @@
+2001-06-11  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.dg/c99-tag-1.c: Add more tests.
+
 2001-06-10  Alexandre Oliva  <aoliva@redhat.com>
 
        * g++.old-deja/g++.abi/ptrmem.C: Take into account different
index 293636154adaddf6c208f33f3ae60046c4e82caf..e93d3bcf0b4ccd243794a83aac5b52a379fadefc 100644 (file)
@@ -124,7 +124,7 @@ foo (void)
       enum u0 *y0; /* { dg-bogus "warning" "warning in place of error" } */
       /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } 124 } */
       int y1[sizeof (enum u2 *)]; /* { dg-bogus "warning" "warning in place of error" } */
-      /* { dg-error "wrong" "wrong tag type" { target *-*-* } 126 } */
+      /* { dg-error "wrong|forward" "wrong tag type" { target *-*-* } 126 } */
       struct v;
       struct e0 *z0; /* { dg-bogus "warning" "warning in place of error" } */
       /* { dg-error "wrong" "wrong tag type" { target *-*-* } 129 } */
@@ -132,5 +132,20 @@ foo (void)
       /* { dg-error "wrong" "wrong tag type" { target *-*-* } 131 } */
       struct w;
     }
+    /* When explicitly shadowed to be a tag of a different type, references
+       to the new type of tag must be accepted and those to the old type
+       rejected.  */
+    {
+      union s0;
+      union s0 *x0;
+      union s1;
+      struct s1 *x1; /* { dg-bogus "warning" "warning in place of error" } */
+      /* { dg-error "wrong" "wrong tag type" { target *-*-* } 142 } */
+      union s2;
+      union s2 *x2;
+      union s3;
+      struct s3 *x3; /* { dg-bogus "warning" "warning in place of error" } */
+      /* { dg-error "wrong" "wrong tag type" { target *-*-* } 147 } */
+    }
   }
 }
This page took 0.112855 seconds and 5 git commands to generate.