]> granicus.if.org Git - clang/commitdiff
[Sema] Don't emit -Wunguarded-availability for switch cases
authorErik Pilkington <erik.pilkington@gmail.com>
Fri, 18 Aug 2017 20:20:56 +0000 (20:20 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Fri, 18 Aug 2017 20:20:56 +0000 (20:20 +0000)
This made it awkward to switch over an enum where some entries
are partial and is unlikley to catch any bugs.

Differential revision: https://reviews.llvm.org/D36777

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311191 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/SemaObjC/unguarded-availability.m

index 3d58b9ae05af91ba50212596ba1d774f4a4c01f3..b8432ebd53bae44d1076199bfe4c4b40c4fb3a2b 100644 (file)
@@ -7513,6 +7513,10 @@ public:
 
   bool TraverseLambdaExpr(LambdaExpr *E) { return true; }
 
+  // for 'case X:' statements, don't bother looking at the 'X'; it can't lead
+  // to any useful diagnostics.
+  bool TraverseCaseStmt(CaseStmt *CS) { return TraverseStmt(CS->getSubStmt()); }
+
   bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *PRE) {
     if (PRE->isClassReceiver())
       DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation());
index f94d1425febca13e9bb6685f278fc09cac9faa1e..b34cd0f9822cd21236dcefefbd2aebf244ea814f 100644 (file)
@@ -287,3 +287,27 @@ AVAILABLE_10_12
 @interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol>
 
 @end
+
+typedef enum {
+  AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 3 {{marked deprecated here}}
+  AK_Cat __attribute__((availability(macos, introduced=10.4))),
+  AK_CyborgCat __attribute__((availability(macos, introduced=10.12))), // expected-note {{marked partial here}}
+} Animals;
+
+void switchAnimals(Animals a) {
+  switch (a) {
+  case AK_Dodo: break; // expected-warning{{'AK_Dodo' is deprecated}}
+  case AK_Cat: break;
+  case AK_Cat|AK_CyborgCat: break; // expected-warning{{case value not in enum}}
+  case AK_CyborgCat: break; // no warn
+  }
+
+  switch (a) {
+  case AK_Dodo...AK_CyborgCat: // expected-warning {{'AK_Dodo' is depr}}
+    break;
+  }
+
+  (void)AK_Dodo; // expected-warning{{'AK_Dodo' is deprecated}}
+  (void)AK_Cat; // no warning
+  (void)AK_CyborgCat; // expected-warning{{'AK_CyborgCat' is only available on macOS 10.12 or newer}} expected-note {{@available}}
+}