]> granicus.if.org Git - clang/commitdiff
Sema::ActOnEnumBody(): handle nested enum redefinitions.
authorSteve Naroff <snaroff@apple.com>
Thu, 7 Aug 2008 14:08:16 +0000 (14:08 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 7 Aug 2008 14:08:16 +0000 (14:08 +0000)
Fixes <rdar://problem/6093889> Nested enum redefinition crashes sema.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54463 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp

index b513dde4661948c2f5527b7868c97e26a7b77b51..61e29de8d41778e16b854546e1dddca21ba50670 100644 (file)
@@ -2223,11 +2223,23 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
   return New;
 }
 
+// FIXME: For consistency with ActOnFields(), we should have the parser
+// pass in the source location for the left/right braces.
 void Sema::ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDeclX,
                          DeclTy **Elements, unsigned NumElements) {
   EnumDecl *Enum = cast<EnumDecl>(static_cast<Decl*>(EnumDeclX));
-  assert(!Enum->isDefinition() && "Enum redefinitions can't reach here");
   
+  if (Enum && Enum->isDefinition()) {
+    // Diagnose code like:
+    //   enum e0 {
+    //     E0 = sizeof(enum e0 { E1 })
+    //   };
+    Diag(Enum->getLocation(), diag::err_nested_redefinition,
+         Enum->getName());
+    Diag(EnumLoc, diag::err_previous_definition);
+    Enum->setInvalidDecl();
+    return;
+  }
   // TODO: If the result value doesn't fit in an int, it must be a long or long
   // long value.  ISO C does not support this, but GCC does as an extension,
   // emit a warning.