From 3062887c9956f2eeabc2e017fbab5c3ab94710b9 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Mon, 4 Feb 2019 23:30:57 +0000 Subject: [PATCH] [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 llvm-svn: 353115 --- clang/lib/Sema/SemaExprObjC.cpp | 7 +++---- clang/test/SemaObjC/infer-availability-from-init.m | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index fdb5987..4b7e320 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -2805,8 +2805,8 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver, } 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(Expr *Receiver, if (!Method) Method = ClassDecl->lookupPrivateClassMethod(Sel); - if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, nullptr, - false, false, ClassDecl)) + if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs)) return ExprError(); } } diff --git a/clang/test/SemaObjC/infer-availability-from-init.m b/clang/test/SemaObjC/infer-availability-from-init.m index 7aa1e53..6719400 100644 --- a/clang/test/SemaObjC/infer-availability-from-init.m +++ b/clang/test/SemaObjC/infer-availability-from-init.m @@ -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 -- 2.7.4