[cfe-commits] r68517 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp test/SemaObjC/call-super-2.m test/SemaObjC/protocol-qualified-class-unsupported.m

Steve Naroff snaroff at apple.com
Tue Apr 7 08:08:19 PDT 2009


Author: snaroff
Date: Tue Apr  7 10:07:57 2009
New Revision: 68517

URL: http://llvm.org/viewvc/llvm-project?rev=68517&view=rev
Log:
Tweak Sema::ActOnInstanceMessage() to look for a class method when dealing with qualified id's. This change is motivated by our desire to not support the "Class<foo>" idiom. Note that the change makes perfect sense (since all ObjC classes are also id/instances).

This allow us to document a simple migration path...change "Class <foo>" to "id <foo>".

This effects: 
- <rdar://problem/6761939> TASK: File source change radars for "qualified Class" errors
- <rdar://problem/6761864> Protocol qualified Class is unsupported

Added:
    cfe/trunk/test/SemaObjC/protocol-qualified-class-unsupported.m
Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/call-super-2.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=68517&r1=68516&r2=68517&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Apr  7 10:07:57 2009
@@ -548,6 +548,9 @@
       ObjCProtocolDecl *PDecl = QIT->getProtocols(i);
       if (PDecl && (Method = PDecl->lookupInstanceMethod(Sel)))
         break;
+      // Since we aren't supporting "Class<foo>", look for a class method.
+      if (PDecl && (Method = PDecl->lookupClassMethod(Sel)))
+        break;
     }
   } else if (const ObjCInterfaceType *OCIType = 
                 ReceiverCType->getAsPointerToObjCInterfaceType()) {

Modified: cfe/trunk/test/SemaObjC/call-super-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/call-super-2.m?rev=68517&r1=68516&r2=68517&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/call-super-2.m (original)
+++ cfe/trunk/test/SemaObjC/call-super-2.m Tue Apr  7 10:07:57 2009
@@ -41,8 +41,8 @@
 }
 + (int) class_func2
 {
-   int i = [(id <Func>)self class_func0];  // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion initializing 'id', expected 'int'}}
-   i += [(id <Func>)super class_func0];    // expected-warning {{casting 'super' is deprecated (it isn't an expression)}} // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
+   int i = [(id <Func>)self class_func0];
+   i += [(id <Func>)super class_func0];    // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
    i += [(Class <Func>)self class_func0];  // expected-error {{protocol qualified 'Class' is unsupported}}
    return i + [(Class <Func>)super class_func0]; // expected-error {{protocol qualified 'Class' is unsupported}} // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
 }

Added: cfe/trunk/test/SemaObjC/protocol-qualified-class-unsupported.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocol-qualified-class-unsupported.m?rev=68517&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/protocol-qualified-class-unsupported.m (added)
+++ cfe/trunk/test/SemaObjC/protocol-qualified-class-unsupported.m Tue Apr  7 10:07:57 2009
@@ -0,0 +1,40 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+#include <stddef.h>
+
+typedef struct objc_class *Class;
+typedef struct objc_object {
+    Class isa;
+} *id;
+id objc_getClass(const char *s);
+
+ at interface Object
++ self;
+ at end
+
+ at protocol Func
++ (void) class_func0;
+- (void) instance_func0;
+ at end
+
+ at interface Derived: Object <Func>
+ at end
+
+ at interface Derived2: Object <Func>
+ at end
+
+static void doSomething(Class <Func> unsupportedObjectType) { // expected-error {{protocol qualified 'Class' is unsupported}}
+  [unsupportedObjectType class_func0];
+}
+
+static void doSomethingElse(id <Func> pleaseConvertToThisType) {
+  [pleaseConvertToThisType class_func0];
+}
+
+int main(int argv, char *argc[]) {
+  doSomething([Derived self]);
+  doSomething([Derived2 self]);
+  doSomethingElse([Derived self]);
+  doSomethingElse([Derived2 self]);
+}
+





More information about the cfe-commits mailing list