Sema: Don't crash when trying to emit a warning for a duplicate value in an invalid...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 7 Apr 2013 14:10:40 +0000 (14:10 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 7 Apr 2013 14:10:40 +0000 (14:10 +0000)
Fixes PR15693. A null check on a pointer returned from cast<> is a very dubious
construct, do we have a checker for this somewhere?

llvm-svn: 178975

clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-duplicate-enum.c

index 84d992c..c8a5d93 100644 (file)
@@ -11538,7 +11538,7 @@ static void CheckForDuplicateEnumValues(Sema &S, Decl **Elements,
   // Populate the EnumMap with all values represented by enum constants without
   // an initialier.
   for (unsigned i = 0; i < NumElements; ++i) {
-    EnumConstantDecl *ECD = cast<EnumConstantDecl>(Elements[i]);
+    EnumConstantDecl *ECD = cast_or_null<EnumConstantDecl>(Elements[i]);
 
     // Null EnumConstantDecl means a previous diagnostic has been emitted for
     // this constant.  Skip this enum since it may be ill-formed.
index 239f6f1..f108b3a 100644 (file)
@@ -90,3 +90,12 @@ enum {
   NMax = N2,
   NCount = NMax + 1
 };
+
+// PR15693
+enum enum1 {
+  VALUE // expected-note{{previous definition is here}}
+};
+
+enum enum2 {
+  VALUE // expected-error{{redefinition of enumerator 'VALUE'}}
+};