]> granicus.if.org Git - clang/commitdiff
[Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings by
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 1 Mar 2019 06:43:20 +0000 (06:43 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 1 Mar 2019 06:43:20 +0000 (06:43 +0000)
declaring an unavailable method in the subclass's extension that
overrides the designated initializer in the base class.

r243676 made changes to allow declaring the unavailable method in the
subclass interface to silence the warning. This commit additionally
allows declaring the unavailable method in the class extension.

rdar://problem/42731306

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

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/attr-designated-init.m

index 82e8def14acb4803a1a6fd683aaa59f25d4e0ad5..cea362fb42502578248ab52812f36960dc5b0de7 100644 (file)
@@ -2280,9 +2280,18 @@ void Sema::DiagnoseMissingDesignatedInitOverrides(
          I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) {
     const ObjCMethodDecl *MD = *I;
     if (!InitSelSet.count(MD->getSelector())) {
+      // Don't emit a diagnostic if the overriding method in the subclass is
+      // marked as unavailable.
       bool Ignore = false;
       if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) {
         Ignore = IMD->isUnavailable();
+      } else {
+        // Check the methods declared in the class extensions too.
+        for (auto *Ext : IFD->visible_extensions())
+          if (auto *IMD = Ext->getInstanceMethod(MD->getSelector())) {
+            Ignore = IMD->isUnavailable();
+            break;
+          }
       }
       if (!Ignore) {
         Diag(ImplD->getLocation(),
index 3558916dbe54a615175c7bcd3284761aa351d6ac..7d1e7008e8e0ea2fc0b1d7692d2b2b78fc66f00f 100644 (file)
@@ -389,6 +389,19 @@ __attribute__((objc_root_class))
 }
 @end
 
+@interface SubTest1Ext : Test1
+-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
+@end
+// Mark 'init' as unavailable in the extension to silence warning.
+@interface SubTest1Ext()
+-(instancetype)init NS_UNAVAILABLE;
+@end
+@implementation SubTest1Ext
+-(instancetype)initWithRequiredParameter:(id)foo {
+  return [super init];
+}
+@end
+
 @interface Test2 : NSObject
 @end
 @interface SubTest2 : Test2