]> granicus.if.org Git - clang/commitdiff
[objc] Consider new initializers inside @implementation when determining if the class
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Apr 2014 18:32:42 +0000 (18:32 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Apr 2014 18:32:42 +0000 (18:32 +0000)
introduces new initializers.

Part of rdar://16568441

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

lib/AST/DeclObjC.cpp
test/SemaObjC/attr-designated-init.m

index c53dba3bfdfdb980dbb40d57d9c36af0e30f161a..34c87ab982485670369194981f9fd4a84551c537 100644 (file)
@@ -364,6 +364,12 @@ static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) {
         return true;
     }
   }
+  if (const auto *ImplD = D->getImplementation()) {
+  for (const auto *MD : ImplD->instance_methods()) {
+    if (MD->getMethodFamily() == OMF_init && !MD->isOverriding())
+      return true;
+  }
+  }
   return false;
 }
 
index 6ef34390069ab2299bc1bf82448966896c19ce51..3eea849403a10a5c381e4295d45c1874e1248f2e 100644 (file)
@@ -142,12 +142,6 @@ __attribute__((objc_root_class))
   return [super initB3];
 }
 -(void)meth {}
--(id)initS1 {
-  return 0;
-}
--(id)initS2 {
-  return [super initB1];
-}
 @end
 
 @interface S6 : B1
@@ -272,7 +266,8 @@ __attribute__((objc_root_class))
 // rdar://16323233
 __attribute__((objc_root_class))
 @interface B4 
--(id)initB4 NS_DESIGNATED_INITIALIZER; 
+-(id)initB4 NS_DESIGNATED_INITIALIZER; // expected-note 4 {{method marked as designated initializer of the class here}}
+-(id)initNonDI;
 @end
 
 @interface rdar16323233 : B4
@@ -291,3 +286,85 @@ __attribute__((objc_root_class))
    return [self initS4];
 }
 @end
+
+@interface S1B4 : B4
+@end
+@implementation S1B4
+-(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
+   return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
+}
+@end
+
+@interface S2B4 : B4
+-(id)initB4;
+@end
+@implementation S2B4
+-(id)initB4 { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
+   return [super initNonDI]; // expected-warning {{designated initializer invoked a non-designated initializer}}
+}
+@end
+
+@interface S3B4 : B4
+@end
+@implementation S3B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+@end
+
+@interface S4B4 : B4
+-(id)initNew;
+@end
+@implementation S4B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+@end
+
+@interface S5B4 : B4
+-(id)initB4;
+@end
+@implementation S5B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+@end
+
+@interface S6B4 : B4
+-(id)initNew;
+-(id)initB4;
+@end
+@implementation S6B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+@end
+
+__attribute__((objc_root_class))
+@interface NSObject
+-(instancetype) init NS_DESIGNATED_INITIALIZER;
+@end
+
+@interface Test3 : NSObject
+@end
+
+@implementation Test3
+-(instancetype) initWithBasePath:(id)path {
+  return [super init];
+}
+-(instancetype) init {
+  return [self initWithBasePath:0];
+}
+@end