arphaman created this revision.
arphaman added reviewers: rsmith, ahatanak.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch 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.


Repository:
  rL LLVM

https://reviews.llvm.org/D27299

Files:
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/switch.cpp


Index: test/SemaCXX/switch.cpp
===================================================================
--- test/SemaCXX/switch.cpp
+++ 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;
+  }
+}
+
+}
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ 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: test/SemaCXX/switch.cpp
===================================================================
--- test/SemaCXX/switch.cpp
+++ 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;
+  }
+}
+
+}
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ 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;
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D27299: [Sema] C++1... Alex Lorenz via Phabricator via cfe-commits

Reply via email to