Author: epilk Date: Mon Feb 4 15:30:57 2019 New Revision: 353115 URL: http://llvm.org/viewvc/llvm-project?rev=353115&view=rev Log: [SemaObjC] Don't infer the availabilty of +new from -init if the receiver has Class type
rdar://47713266 Differential revision: https://reviews.llvm.org/D57712 Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp cfe/trunk/test/SemaObjC/infer-availability-from-init.m Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=353115&r1=353114&r2=353115&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Feb 4 15:30:57 2019 @@ -2805,8 +2805,8 @@ ExprResult Sema::BuildInstanceMessage(Ex } else { if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) { if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) { - // FIXME: Is this correct? Why are we assuming that a message to - // Class will call a method in the current interface? + // As a guess, try looking for the method in the current interface. + // This very well may not produce the "right" method. // First check the public methods in the class interface. Method = ClassDecl->lookupClassMethod(Sel); @@ -2814,8 +2814,7 @@ ExprResult Sema::BuildInstanceMessage(Ex if (!Method) Method = ClassDecl->lookupPrivateClassMethod(Sel); - if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, nullptr, - false, false, ClassDecl)) + if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs)) return ExprError(); } } Modified: cfe/trunk/test/SemaObjC/infer-availability-from-init.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/infer-availability-from-init.m?rev=353115&r1=353114&r2=353115&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/infer-availability-from-init.m (original) +++ cfe/trunk/test/SemaObjC/infer-availability-from-init.m Mon Feb 4 15:30:57 2019 @@ -56,3 +56,16 @@ void usenotmyobject() { [self new]; } @end + +@interface NoInit : NSObject +-(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}} +@end + +@interface NoInitSub : NoInit @end + +@implementation NoInitSub +-(void)meth:(Class)c { + [c new]; // No error; unknown interface. + [NoInitSub new]; // expected-error {{'new' is unavailable}} +} +@end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits