Author: akirtzidis Date: Thu Jul 30 14:06:04 2015 New Revision: 243676 URL: http://llvm.org/viewvc/llvm-project?rev=243676&view=rev Log: [sema] Allow to opt-out of overriding the super class's designated initializers by marking the initializer as unavailable in the subclass.
rdar://20281322 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=243676&r1=243675&r2=243676&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original) +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Jul 30 14:06:04 2015 @@ -1950,10 +1950,16 @@ void Sema::DiagnoseMissingDesignatedInit I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) { const ObjCMethodDecl *MD = *I; if (!InitSelSet.count(MD->getSelector())) { - Diag(ImplD->getLocation(), - diag::warn_objc_implementation_missing_designated_init_override) - << MD->getSelector(); - Diag(MD->getLocation(), diag::note_objc_designated_init_marked_here); + bool Ignore = false; + if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) { + Ignore = IMD->isUnavailable(); + } + if (!Ignore) { + Diag(ImplD->getLocation(), + diag::warn_objc_implementation_missing_designated_init_override) + << MD->getSelector(); + Diag(MD->getLocation(), diag::note_objc_designated_init_marked_here); + } } } } 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=243676&r1=243675&r2=243676&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/attr-designated-init.m (original) +++ cfe/trunk/test/SemaObjC/attr-designated-init.m Thu Jul 30 14:06:04 2015 @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -Wno-incomplete-implementation -verify -fblocks %s #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) +#define NS_UNAVAILABLE __attribute__((unavailable)) void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}} @@ -253,7 +254,7 @@ __attribute__((objc_root_class)) __attribute__((objc_root_class)) @interface MyObject - (instancetype)initWithStuff:(id)stuff __attribute__((objc_designated_initializer)); -- (instancetype)init __attribute__((unavailable)); +- (instancetype)init NS_UNAVAILABLE; @end @implementation MyObject @@ -378,6 +379,15 @@ __attribute__((objc_root_class)) } @end +@interface SubTest1 : Test1 +-(instancetype)init NS_UNAVAILABLE; +-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER; +@end +@implementation SubTest1 +-(instancetype)initWithRequiredParameter:(id)foo { + return [super init]; +} +@end @interface Test2 : NSObject @end _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits