[PATCH] D27299: [Sema] C++11 opaque enums should avoid the "case value not in enumerated type" switch warning
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 8 06:56:26 PST 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289055: [Sema] Avoid "case value not in enumerated type" warning for C++11 opaque enums (authored by arphaman).
Changed prior to commit:
https://reviews.llvm.org/D27299?vs=79892&id=80757#toc
Repository:
rL LLVM
https://reviews.llvm.org/D27299
Files:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/switch.cpp
Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -1070,7 +1070,8 @@
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;
Index: cfe/trunk/test/SemaCXX/switch.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/switch.cpp
+++ cfe/trunk/test/SemaCXX/switch.cpp
@@ -100,3 +100,33 @@
}
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;
+ }
+}
+
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27299.80757.patch
Type: text/x-patch
Size: 1421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161208/8785336b/attachment.bin>
More information about the cfe-commits
mailing list