[PATCH] D57712: [SemaObjC] Don't infer the availabilty of messages to +new from -init if the receiver has Class type

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 4 13:55:20 PST 2019


erik.pilkington created this revision.
erik.pilkington added a reviewer: arphaman.
Herald added subscribers: dexonsmith, jkorous.
Herald added a project: clang.

Fixes rdar://47713266

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D57712

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


Index: clang/test/SemaObjC/infer-availability-from-init.m
===================================================================
--- clang/test/SemaObjC/infer-availability-from-init.m
+++ clang/test/SemaObjC/infer-availability-from-init.m
@@ -56,3 +56,16 @@
   [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
Index: clang/lib/Sema/SemaExprObjC.cpp
===================================================================
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2805,8 +2805,8 @@
       } 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 @@
             if (!Method)
               Method = ClassDecl->lookupPrivateClassMethod(Sel);
 
-            if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, nullptr,
-                                            false, false, ClassDecl))
+            if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
               return ExprError();
           }
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57712.185150.patch
Type: text/x-patch
Size: 1824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190204/9b1e090f/attachment.bin>


More information about the cfe-commits mailing list