]> granicus.if.org Git - clang/commitdiff
[SemaObjC] Don't infer the availabilty of +new from -init if the receiver has Class...
authorErik Pilkington <erik.pilkington@gmail.com>
Mon, 4 Feb 2019 23:30:57 +0000 (23:30 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Mon, 4 Feb 2019 23:30:57 +0000 (23:30 +0000)
rdar://47713266

Differential revision: https://reviews.llvm.org/D57712

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353115 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/infer-availability-from-init.m

index fdb59874cc9647faa69c268b642c29e468905e38..4b7e320b15d6da59db2530ab1f08706cd84bd7b6 100644 (file)
@@ -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();
           }
         }
index 7aa1e53c09109e4373902cd45be3304af83d4e67..6719400a9f4287a881a80ba005a4a6583d0080ee 100644 (file)
@@ -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