diff options
| author | Steve Naroff <snaroff@apple.com> | 2009-04-07 15:07:57 +0000 | 
|---|---|---|
| committer | Steve Naroff <snaroff@apple.com> | 2009-04-07 15:07:57 +0000 | 
| commit | ebc790d4d80bd6aeed7a29b510071416b6509b74 (patch) | |
| tree | 4cb8eeaeafd850ef455809009458a591acdf926d | |
| parent | c4631b2809cf27fd72baf192c1b6eac942cc4f62 (diff) | |
| download | bcm5719-llvm-ebc790d4d80bd6aeed7a29b510071416b6509b74.tar.gz bcm5719-llvm-ebc790d4d80bd6aeed7a29b510071416b6509b74.zip  | |
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
llvm-svn: 68517
| -rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaObjC/call-super-2.m | 4 | ||||
| -rw-r--r-- | clang/test/SemaObjC/protocol-qualified-class-unsupported.m | 40 | 
3 files changed, 45 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index cfa279aa311..54ed709d0f4 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -548,6 +548,9 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,        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()) { diff --git a/clang/test/SemaObjC/call-super-2.m b/clang/test/SemaObjC/call-super-2.m index cc66cf3f219..f171007be07 100644 --- a/clang/test/SemaObjC/call-super-2.m +++ b/clang/test/SemaObjC/call-super-2.m @@ -41,8 +41,8 @@ id objc_getClass(const char *s);  }  + (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)}}  } diff --git a/clang/test/SemaObjC/protocol-qualified-class-unsupported.m b/clang/test/SemaObjC/protocol-qualified-class-unsupported.m new file mode 100644 index 00000000000..ad1ed5dc941 --- /dev/null +++ b/clang/test/SemaObjC/protocol-qualified-class-unsupported.m @@ -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); + +@interface Object ++ self; +@end + +@protocol Func ++ (void) class_func0; +- (void) instance_func0; +@end + +@interface Derived: Object <Func> +@end + +@interface Derived2: Object <Func> +@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]); +} +  | 

