]> granicus.if.org Git - clang/commitdiff
[objc] -[NSObject init] is documented to not do anything, don't warn if subclasses...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Apr 2014 18:32:51 +0000 (18:32 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Apr 2014 18:32:51 +0000 (18:32 +0000)
Part of rdar://16568441

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

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

index 79794b1f9f08de899f7ab3b6f1b5abbf6e9df47b..13725dc3f390fdd792023db6c0990286f1a60f87 100644 (file)
@@ -9976,8 +9976,20 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
           MD->isDesignatedInitializerForTheInterface(&InitMethod);
       assert(isDesignated && InitMethod);
       (void)isDesignated;
-      // Don't issue this warning for unavaialable inits.
-      if (!MD->isUnavailable()) {
+
+      auto superIsNSObject = [&](const ObjCMethodDecl *MD) {
+        auto IFace = MD->getClassInterface();
+        if (!IFace)
+          return false;
+        auto SuperD = IFace->getSuperClass();
+        if (!SuperD)
+          return false;
+        return SuperD->getIdentifier() ==
+            NSAPIObj->getNSClassId(NSAPI::ClassId_NSObject);
+      };
+      // Don't issue this warning for unavailable inits or direct subclasses
+      // of NSObject.
+      if (!MD->isUnavailable() && !superIsNSObject(MD)) {
         Diag(MD->getLocation(),
              diag::warn_objc_designated_init_missing_super_call);
         Diag(InitMethod->getLocation(),
index 3eea849403a10a5c381e4295d45c1874e1248f2e..3dbc2cab12d6004652e0488c7e831c5c502626a2 100644 (file)
@@ -354,7 +354,7 @@ __attribute__((objc_root_class))
 
 __attribute__((objc_root_class))
 @interface NSObject
--(instancetype) init NS_DESIGNATED_INITIALIZER;
+-(instancetype) init NS_DESIGNATED_INITIALIZER; // expected-note {{method marked as designated initializer of the class here}}
 @end
 
 @interface Test3 : NSObject
@@ -368,3 +368,23 @@ __attribute__((objc_root_class))
   return [self initWithBasePath:0];
 }
 @end
+
+@interface Test1 : NSObject
+-(instancetype) init NS_DESIGNATED_INITIALIZER;
+@end
+@implementation Test1
+-(instancetype) init {
+  return self;
+}
+@end
+
+
+@interface Test2 : NSObject
+@end
+@interface SubTest2 : Test2
+@end
+@implementation SubTest2
+-(instancetype) init { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
+  return self;
+}
+@end