From: Alex Lorenz Date: Thu, 8 Dec 2016 14:46:05 +0000 (+0000) Subject: [Sema] Avoid "case value not in enumerated type" warning for C++11 opaque enums X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c6c37651c4570ca488e18b57b62d082b03d2302;p=clang [Sema] Avoid "case value not in enumerated type" warning for C++11 opaque enums This commit ensures that the switch warning "case value not in enumerated type" isn't shown for opaque enums. We don't know the actual list of values in opaque enums, so that warning is incorrect. rdar://29230764 Differential Revision: https://reviews.llvm.org/D27299 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289055 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 89c82c9805..50f0a22ff0 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1070,7 +1070,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, const EnumType *ET = CondTypeBeforePromotion->getAs(); // If switch has default case, then ignore it. - if (!CaseListIsErroneous && !HasConstantCond && ET) { + if (!CaseListIsErroneous && !HasConstantCond && ET && + ET->getDecl()->isCompleteDefinition()) { const EnumDecl *ED = ET->getDecl(); EnumValsTy EnumVals; diff --git a/test/SemaCXX/switch.cpp b/test/SemaCXX/switch.cpp index 392dcd8698..0c60ce0209 100644 --- a/test/SemaCXX/switch.cpp +++ b/test/SemaCXX/switch.cpp @@ -100,3 +100,33 @@ namespace Conversion { } template void f(S); // expected-note {{instantiation of}} } + +// rdar://29230764 +namespace OpaqueEnumWarnings { + +enum Opaque : int; +enum class OpaqueClass : int; + +enum class Defined : int; +enum class Defined : int { a }; + +void test(Opaque o, OpaqueClass oc, Defined d) { + // Don't warn that case value is not present in opaque enums. + switch (o) { + case (Opaque)1: + break; + } + switch (oc) { + case (OpaqueClass)1: + break; + } + + switch (d) { + case Defined::a: + break; + case (Defined)2: // expected-warning {{case value not in enumerated type 'OpaqueEnumWarnings::Defined'}} + break; + } +} + +}