From ad466635e762ea18b188b7229bc92f7998bc34ea Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Wed, 9 Aug 2017 12:34:58 +0000 Subject: [PATCH] [Sema] -Wenum-compare no longer warn on anonymous enums in switch statements 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 | 6 ++++++ test/SemaCXX/warn-enum-compare.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 6bdc71bb89..1b6aed6193 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -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; diff --git a/test/SemaCXX/warn-enum-compare.cpp b/test/SemaCXX/warn-enum-compare.cpp index d1f6beb7dd..f82f7750be 100644 --- a/test/SemaCXX/warn-enum-compare.cpp +++ b/test/SemaCXX/warn-enum-compare.cpp @@ -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; + } } -- 2.40.0