r206410 - [objc] -[NSObject init] is documented to not do anything, don't warn if subclasses do not call [super init] on their initializers.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Apr 16 11:32:51 PDT 2014
Author: akirtzidis
Date: Wed Apr 16 13:32:51 2014
New Revision: 206410
URL: http://llvm.org/viewvc/llvm-project?rev=206410&view=rev
Log:
[objc] -[NSObject init] is documented to not do anything, don't warn if subclasses do not call [super init] on their initializers.
Part of rdar://16568441
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/attr-designated-init.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=206410&r1=206409&r2=206410&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr 16 13:32:51 2014
@@ -9976,8 +9976,20 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
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(),
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=206410&r1=206409&r2=206410&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/trunk/test/SemaObjC/attr-designated-init.m Wed Apr 16 13:32:51 2014
@@ -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
+
+ at interface Test1 : NSObject
+-(instancetype) init NS_DESIGNATED_INITIALIZER;
+ at end
+ at implementation Test1
+-(instancetype) init {
+ return self;
+}
+ at end
+
+
+ at interface Test2 : NSObject
+ at end
+ at interface SubTest2 : Test2
+ at end
+ at implementation SubTest2
+-(instancetype) init { // expected-warning {{designated initializer missing a 'super' call to a designated initializer of the super class}}
+ return self;
+}
+ at end
More information about the cfe-commits
mailing list