erik.pilkington created this revision. Currently, this has pretty terrible ergonomics for the fairly common case of switching over an enum which has some entries that are partial. Thanks to Nico Weber for pointing this out!
Thanks, Erik https://reviews.llvm.org/D36777 Files: lib/Sema/SemaDeclAttr.cpp test/SemaObjC/unguarded-availability.m Index: test/SemaObjC/unguarded-availability.m =================================================================== --- test/SemaObjC/unguarded-availability.m +++ test/SemaObjC/unguarded-availability.m @@ -287,3 +287,22 @@ @interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol> @end + +typedef enum { + AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 2 {{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 + } + + (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}} +} Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -7513,6 +7513,15 @@ bool TraverseLambdaExpr(LambdaExpr *E) { return true; } + bool TraverseCaseStmt(CaseStmt *CS) { + // for 'case X:' statements, don't bother looking at the 'X'; it can't lead + // to any useful diagnostics. + for (Stmt *Child : llvm::drop_begin(CS->children(), 1)) + if (!Base::TraverseStmt(Child)) + return false; + return true; + } + bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *PRE) { if (PRE->isClassReceiver()) DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation());
Index: test/SemaObjC/unguarded-availability.m =================================================================== --- test/SemaObjC/unguarded-availability.m +++ test/SemaObjC/unguarded-availability.m @@ -287,3 +287,22 @@ @interface BaseClass (CategoryWithNewProtocolRequirement) <NewProtocol> @end + +typedef enum { + AK_Dodo __attribute__((availability(macos, deprecated=10.3))), // expected-note 2 {{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 + } + + (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}} +} Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -7513,6 +7513,15 @@ bool TraverseLambdaExpr(LambdaExpr *E) { return true; } + bool TraverseCaseStmt(CaseStmt *CS) { + // for 'case X:' statements, don't bother looking at the 'X'; it can't lead + // to any useful diagnostics. + for (Stmt *Child : llvm::drop_begin(CS->children(), 1)) + if (!Base::TraverseStmt(Child)) + return false; + return true; + } + bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *PRE) { if (PRE->isClassReceiver()) DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits