]> granicus.if.org Git - clang/commitdiff
[Sema] -Wenum-compare no longer warn on anonymous enums in switch statements
authorGabor Horvath <xazax.hun@gmail.com>
Wed, 9 Aug 2017 12:34:58 +0000 (12:34 +0000)
committerGabor Horvath <xazax.hun@gmail.com>
Wed, 9 Aug 2017 12:34:58 +0000 (12:34 +0000)
Patch by: Reka Nikolett Kovacs

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

lib/Sema/SemaStmt.cpp
test/SemaCXX/warn-enum-compare.cpp

index 6bdc71bb8917abfccc95afcc4a45afd53121d1b1..1b6aed61933197946beca53d2952ceda43864d52 100644 (file)
@@ -753,6 +753,12 @@ static void checkEnumTypesInSwitchStmt(Sema &S, const Expr *Cond,
   if (!CondEnumType || !CaseEnumType)
     return;
 
+  // Ignore anonymous enums.
+  if (!CondEnumType->getDecl()->getIdentifier())
+    return;
+  if (!CaseEnumType->getDecl()->getIdentifier())
+    return;
+
   if (S.Context.hasSameUnqualifiedType(CondType, CaseType))
     return;
 
index d1f6beb7ddadb8d6edcf854037fa56020116f2c6..f82f7750be85a8afbf6a680c2e9b1676ec64408e 100644 (file)
@@ -226,4 +226,11 @@ void test () {
     case BarF: break;
     case FooA: break; // expected-warning {{comparison of two values with different enumeration types ('Bar' and 'Foo')}}
   }
+
+  switch(x) {
+    case AnonAA: break; // expected-warning {{case value not in enumerated type 'Foo'}}
+    case FooA: break;
+    case FooB: break;
+    case FooC: break;
+  }
 }