r310468 - [Sema] -Wenum-compare no longer warn on anonymous enums in switch statements
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 9 05:34:58 PDT 2017
Author: xazax
Date: Wed Aug 9 05:34:58 2017
New Revision: 310468
URL: http://llvm.org/viewvc/llvm-project?rev=310468&view=rev
Log:
[Sema] -Wenum-compare no longer warn on anonymous enums in switch statements
Patch by: Reka Nikolett Kovacs
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/warn-enum-compare.cpp
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=310468&r1=310467&r2=310468&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Aug 9 05:34:58 2017
@@ -753,6 +753,12 @@ static void checkEnumTypesInSwitchStmt(S
if (!CondEnumType || !CaseEnumType)
return;
+ // Ignore anonymous enums.
+ if (!CondEnumType->getDecl()->getIdentifier())
+ return;
+ if (!CaseEnumType->getDecl()->getIdentifier())
+ return;
+
if (S.Context.hasSameUnqualifiedType(CondType, CaseType))
return;
Modified: cfe/trunk/test/SemaCXX/warn-enum-compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=310468&r1=310467&r2=310468&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-enum-compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-enum-compare.cpp Wed Aug 9 05:34:58 2017
@@ -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;
+ }
}
More information about the cfe-commits
mailing list