]> granicus.if.org Git - clang/commitdiff
Extend -Wdeprecated-implementations to warn about unavailable methods
authorAlex Lorenz <arphaman@gmail.com>
Thu, 13 Jul 2017 16:37:11 +0000 (16:37 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 13 Jul 2017 16:37:11 +0000 (16:37 +0000)
rdar://22867595

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/warn-deprecated-implementations.m

index 671c3e92f4518be1add0984ae1d8c959f0aa0f5e..ab1653d313becc9efa443917b60fe21c6b9d77b8 100644 (file)
@@ -4581,6 +4581,9 @@ def warn_deprecated_fwdclass_message : Warning<
 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">;
index 2cf0ca94ac25fd6475539df07870337a412d3453..302f24880f6cc125f5ef1adc03671ca03769ac16 100644 (file)
@@ -253,7 +253,17 @@ static void DiagnoseObjCImplementedDeprecations(Sema &S, const NamedDecl *ND,
   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;
index ed2156d9abe68a5b95016705e2ae0a7aed396c8e..440b2886f01dc966f7323f7e5b6bfb82e546215e 100644 (file)
@@ -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-note {{'CL' has been explicitly marked d
 
 @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-note {{'CL' has been explicitly marked d
 
 @implementation SUB
 - (void) B {} // expected-warning {{implementing deprecated method}}
++ (void) unavailable { } // expected-warning {{implementing unavailable method}}
 @end
 
 @interface Test