Author: arphaman Date: Thu Dec 8 08:46:05 2016 New Revision: 289055 URL: http://llvm.org/viewvc/llvm-project?rev=289055&view=rev Log: [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 Modified: cfe/trunk/lib/Sema/SemaStmt.cpp cfe/trunk/test/SemaCXX/switch.cpp Modified: cfe/trunk/lib/Sema/SemaStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=289055&r1=289054&r2=289055&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaStmt.cpp (original) +++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Dec 8 08:46:05 2016 @@ -1070,7 +1070,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocati const EnumType *ET = CondTypeBeforePromotion->getAs<EnumType>(); // 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; Modified: cfe/trunk/test/SemaCXX/switch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/switch.cpp?rev=289055&r1=289054&r2=289055&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/switch.cpp (original) +++ cfe/trunk/test/SemaCXX/switch.cpp Thu Dec 8 08:46:05 2016 @@ -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; + } +} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits