r307924 - Extend -Wdeprecated-implementations to warn about unavailable methods
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 13 09:37:12 PDT 2017
Author: arphaman
Date: Thu Jul 13 09:37:11 2017
New Revision: 307924
URL: http://llvm.org/viewvc/llvm-project?rev=307924&view=rev
Log:
Extend -Wdeprecated-implementations to warn about unavailable methods
rdar://22867595
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307924&r1=307923&r2=307924&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 13 09:37:11 2017
@@ -4581,6 +4581,9 @@ def warn_deprecated_fwdclass_message : W
def warn_deprecated_def : Warning<
"implementing deprecated %select{method|class|category}0">,
InGroup<DeprecatedImplementations>, DefaultIgnore;
+def warn_unavailable_def : Warning<
+ "implementing unavailable method">,
+ InGroup<DeprecatedImplementations>, DefaultIgnore;
def err_unavailable : Error<"%0 is unavailable">;
def err_property_method_unavailable :
Error<"property access is using %0 method which is unavailable">;
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=307924&r1=307923&r2=307924&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jul 13 09:37:11 2017
@@ -253,7 +253,17 @@ static void DiagnoseObjCImplementedDepre
if (!ND)
return;
bool IsCategory = false;
- if (!ND->isDeprecated()) {
+ AvailabilityResult Availability = ND->getAvailability();
+ if (Availability != AR_Deprecated) {
+ if (const auto *MD = dyn_cast<ObjCMethodDecl>(ND)) {
+ if (Availability != AR_Unavailable)
+ return;
+ // Warn about implementing unavailable methods.
+ S.Diag(ImplLoc, diag::warn_unavailable_def);
+ S.Diag(ND->getLocation(), diag::note_method_declared_at)
+ << ND->getDeclName();
+ return;
+ }
if (const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
if (!CD->getClassInterface()->isDeprecated())
return;
Modified: cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m?rev=307924&r1=307923&r2=307924&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m (original)
+++ cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m Thu Jul 13 09:37:11 2017
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-implementations -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple=x86_64-apple-macos10.10 -fsyntax-only -Wdeprecated-implementations -verify -Wno-objc-root-class %s
// rdar://8973810
// rdar://12717705
@protocol P
- (void) D __attribute__((deprecated)); // expected-note {{method 'D' declared here}}
+
+- (void) unavailable __attribute__((__unavailable__)); // expected-note {{method 'unavailable' declared here}}
@end
@interface A <P>
@@ -18,6 +20,8 @@
+ (void)F { } // No warning, implementing its own deprecated method
- (void) D {} // expected-warning {{implementing deprecated method}}
- (void) E {} // No warning, implementing deprecated method in its class extension.
+
+- (void) unavailable { } // expected-warning {{implementing unavailable metho}}
@end
@interface A(CAT)
@@ -43,6 +47,8 @@ __attribute__((deprecated)) // expected-
@interface BASE
- (void) B __attribute__((deprecated)); // expected-note {{method 'B' declared here}}
+
++ (void) unavailable __attribute__((availability(macos, unavailable))); // expected-note {{method 'unavailable' declared here}}
@end
@interface SUB : BASE
@@ -50,6 +56,7 @@ __attribute__((deprecated)) // expected-
@implementation SUB
- (void) B {} // expected-warning {{implementing deprecated method}}
++ (void) unavailable { } // expected-warning {{implementing unavailable method}}
@end
@interface Test
More information about the cfe-commits
mailing list