r355175 - [Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings by

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 28 22:43:20 PST 2019


Author: ahatanak
Date: Thu Feb 28 22:43:20 2019
New Revision: 355175

URL: http://llvm.org/viewvc/llvm-project?rev=355175&view=rev
Log:
[Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings by
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

Modified:
    cfe/trunk/lib/Sema/SemaObjCProperty.cpp
    cfe/trunk/test/SemaObjC/attr-designated-init.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=355175&r1=355174&r2=355175&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Feb 28 22:43:20 2019
@@ -2280,9 +2280,18 @@ void Sema::DiagnoseMissingDesignatedInit
          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(),

Modified: cfe/trunk/test/SemaObjC/attr-designated-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-designated-init.m?rev=355175&r1=355174&r2=355175&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/trunk/test/SemaObjC/attr-designated-init.m Thu Feb 28 22:43:20 2019
@@ -389,6 +389,19 @@ __attribute__((objc_root_class))
 }
 @end
 
+ at interface SubTest1Ext : Test1
+-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
+ at end
+// Mark 'init' as unavailable in the extension to silence warning.
+ at interface SubTest1Ext()
+-(instancetype)init NS_UNAVAILABLE;
+ at end
+ at implementation SubTest1Ext
+-(instancetype)initWithRequiredParameter:(id)foo {
+  return [super init];
+}
+ at end
+
 @interface Test2 : NSObject
 @end
 @interface SubTest2 : Test2




More information about the cfe-commits mailing list