r353115 - [SemaObjC] Don't infer the availabilty of +new from -init if the receiver has Class type

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 4 15:30:57 PST 2019


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
+
+ at interface NoInit : NSObject
+-(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}}
+ at end
+
+ at interface NoInitSub : NoInit @end
+
+ at implementation NoInitSub
+-(void)meth:(Class)c {
+  [c new]; // No error; unknown interface.
+  [NoInitSub new]; // expected-error {{'new' is unavailable}}
+}
+ at end




More information about the cfe-commits mailing list