Skip to content

Commit ba87c62

Browse files
committed
[Sema] Don't emit -Wunguarded-availability for switch cases
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 llvm-svn: 311191
1 parent 599b117 commit ba87c62

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7513,6 +7513,10 @@ class DiagnoseUnguardedAvailability
75137513

75147514
bool TraverseLambdaExpr(LambdaExpr *E) { return true; }
75157515

7516+
// for 'case X:' statements, don't bother looking at the 'X'; it can't lead
7517+
// to any useful diagnostics.
7518+
bool TraverseCaseStmt(CaseStmt *CS) { return TraverseStmt(CS->getSubStmt()); }
7519+
75167520
bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *PRE) {
75177521
if (PRE->isClassReceiver())
75187522
DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation());

clang/test/SemaObjC/unguarded-availability.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,27 @@ @interface ClassWithNewProtocolRequirement : BaseClass <NewProtocol>
287287
@interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol>
288288

289289
@end
290+
291+
typedef enum {
292+
AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 3 {{marked deprecated here}}
293+
AK_Cat __attribute__((availability(macos, introduced=10.4))),
294+
AK_CyborgCat __attribute__((availability(macos, introduced=10.12))), // expected-note {{marked partial here}}
295+
} Animals;
296+
297+
void switchAnimals(Animals a) {
298+
switch (a) {
299+
case AK_Dodo: break; // expected-warning{{'AK_Dodo' is deprecated}}
300+
case AK_Cat: break;
301+
case AK_Cat|AK_CyborgCat: break; // expected-warning{{case value not in enum}}
302+
case AK_CyborgCat: break; // no warn
303+
}
304+
305+
switch (a) {
306+
case AK_Dodo...AK_CyborgCat: // expected-warning {{'AK_Dodo' is depr}}
307+
break;
308+
}
309+
310+
(void)AK_Dodo; // expected-warning{{'AK_Dodo' is deprecated}}
311+
(void)AK_Cat; // no warning
312+
(void)AK_CyborgCat; // expected-warning{{'AK_CyborgCat' is only available on macOS 10.12 or newer}} expected-note {{@available}}
313+
}

0 commit comments

Comments
 (0)