r206409 - [objc] Consider new initializers inside @implementation when determining if the class

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Apr 16 11:32:42 PDT 2014


Author: akirtzidis
Date: Wed Apr 16 13:32:42 2014
New Revision: 206409

URL: http://llvm.org/viewvc/llvm-project?rev=206409&view=rev
Log:
[objc] Consider new initializers inside @implementation when determining if the class
introduces new initializers.

Part of rdar://16568441

Modified:
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/test/SemaObjC/attr-designated-init.m

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=206409&r1=206408&r2=206409&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Apr 16 13:32:42 2014
@@ -364,6 +364,12 @@ static bool isIntroducingInitializers(co
         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;
 }
 

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=206409&r1=206408&r2=206409&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/trunk/test/SemaObjC/attr-designated-init.m Wed Apr 16 13:32:42 2014
@@ -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
+
+ at interface S1B4 : B4
+ at end
+ at 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}}
+}
+ at end
+
+ at interface S2B4 : B4
+-(id)initB4;
+ at end
+ at 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}}
+}
+ at end
+
+ at interface S3B4 : B4
+ at end
+ at implementation S3B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+ at end
+
+ at interface S4B4 : B4
+-(id)initNew;
+ at end
+ at implementation S4B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+ at end
+
+ at interface S5B4 : B4
+-(id)initB4;
+ at end
+ at implementation S5B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+ at end
+
+ at interface S6B4 : B4
+-(id)initNew;
+-(id)initB4;
+ at end
+ at implementation S6B4
+-(id)initNew {
+  return [super initB4];
+}
+-(id)initB4 {
+   return [self initNew];
+}
+ at end
+
+__attribute__((objc_root_class))
+ at interface NSObject
+-(instancetype) init NS_DESIGNATED_INITIALIZER;
+ at end
+
+ at interface Test3 : NSObject
+ at end
+
+ at implementation Test3
+-(instancetype) initWithBasePath:(id)path {
+  return [super init];
+}
+-(instancetype) init {
+  return [self initWithBasePath:0];
+}
+ at end





More information about the cfe-commits mailing list