From 660195f0245171612d909cbdf49b025319c0a08f Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Thu, 8 Dec 2016 14:46:05 +0000 Subject: [PATCH] [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 llvm-svn: 289055 --- clang/lib/Sema/SemaStmt.cpp | 3 ++- clang/test/SemaCXX/switch.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 89c82c9..50f0a22 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/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/clang/test/SemaCXX/switch.cpp b/clang/test/SemaCXX/switch.cpp index 392dcd8..0c60ce0 100644 --- a/clang/test/SemaCXX/switch.cpp +++ b/clang/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; + } +} + +} -- 2.7.4