[cfe-commits] r53069 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/enum.c

Chris Lattner sabre at nondot.org
Wed Jul 2 20:30:59 PDT 2008


Author: lattner
Date: Wed Jul  2 22:30:58 2008
New Revision: 53069

URL: http://llvm.org/viewvc/llvm-project?rev=53069&view=rev
Log:
Fix PR2020 by recovering by defining an anonymous enum, instead of recovering
by filling in the body of a union with enum constants.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/enum.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=53069&r1=53068&r2=53069&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul  2 22:30:58 2008
@@ -1688,35 +1688,38 @@
     assert((isa<TagDecl>(PrevDecl) || isa<NamespaceDecl>(PrevDecl)) &&
             "unexpected Decl type");
     if (TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
-      // If this is a use of a previous tag, or if the tag is already declared in
-      // the same scope (so that the definition/declaration completes or
+      // If this is a use of a previous tag, or if the tag is already declared
+      // in the same scope (so that the definition/declaration completes or
       // rementions the tag), reuse the decl.
       if (TK == TK_Reference ||
           IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
-        // Make sure that this wasn't declared as an enum and now used as a struct
-        // or something similar.
+        // Make sure that this wasn't declared as an enum and now used as a
+        // struct or something similar.
         if (PrevTagDecl->getTagKind() != Kind) {
           Diag(KWLoc, diag::err_use_with_wrong_tag, Name->getName());
           Diag(PrevDecl->getLocation(), diag::err_previous_use);
-        }
-        
-        // If this is a use or a forward declaration, we're good.
-        if (TK != TK_Definition)
-          return PrevDecl;
-
-        // Diagnose attempts to redefine a tag.
-        if (PrevTagDecl->isDefinition()) {
-          Diag(NameLoc, diag::err_redefinition, Name->getName());
-          Diag(PrevDecl->getLocation(), diag::err_previous_definition);
-          // If this is a redefinition, recover by making this struct be
-          // anonymous, which will make any later references get the previous
-          // definition.
+          // Recover by making this an anonymous redefinition.
           Name = 0;
+          PrevDecl = 0;
         } else {
-          // Okay, this is definition of a previously declared or referenced tag.
-          // Move the location of the decl to be the definition site.
-          PrevDecl->setLocation(NameLoc);
-          return PrevDecl;
+          // If this is a use or a forward declaration, we're good.
+          if (TK != TK_Definition)
+            return PrevDecl;
+
+          // Diagnose attempts to redefine a tag.
+          if (PrevTagDecl->isDefinition()) {
+            Diag(NameLoc, diag::err_redefinition, Name->getName());
+            Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+            // If this is a redefinition, recover by making this struct be
+            // anonymous, which will make any later references get the previous
+            // definition.
+            Name = 0;
+          } else {
+            // Okay, this is definition of a previously declared or referenced
+            // tag. Move the location of the decl to be the definition site.
+            PrevDecl->setLocation(NameLoc);
+            return PrevDecl;
+          }
         }
       }
       // If we get here, this is a definition of a new struct type in a nested

Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=53069&r1=53068&r2=53069&view=diff

==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Wed Jul  2 22:30:58 2008
@@ -28,3 +28,8 @@
 {
   ve + i;
 }
+
+// PR2020
+union u0;    // expected-error {{previous use is here}}
+enum u0 { U0A }; // expected-error {{error: use of 'u0' with tag type that does not match previous declaration}}
+





More information about the cfe-commits mailing list