diff options
| author | Ted Kremenek <kremenek@apple.com> | 2013-04-22 22:09:21 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2013-04-22 22:09:21 +0000 |
| commit | 760b5e360d6528af5454df27c71896737a0acaa5 (patch) | |
| tree | 9140597a782baa6d6a4c37486a8900988e47a25a /clang/test/SemaObjC/deprecated-objc-introspection.m | |
| parent | 7359d4793e9d808d331fa78ba5e7cc3bc5d4103c (diff) | |
| download | bcm5719-llvm-760b5e360d6528af5454df27c71896737a0acaa5.tar.gz bcm5719-llvm-760b5e360d6528af5454df27c71896737a0acaa5.zip | |
Rename this test to make it more general for including more tests.
llvm-svn: 180056
Diffstat (limited to 'clang/test/SemaObjC/deprecated-objc-introspection.m')
| -rw-r--r-- | clang/test/SemaObjC/deprecated-objc-introspection.m | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/deprecated-objc-introspection.m b/clang/test/SemaObjC/deprecated-objc-introspection.m new file mode 100644 index 00000000000..6d67641a814 --- /dev/null +++ b/clang/test/SemaObjC/deprecated-objc-introspection.m @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s + +//====------------------------------------------------------------====// +// Test deprecated direct usage of the 'isa' pointer. +//====------------------------------------------------------------====// + +typedef unsigned long NSUInteger; + +typedef struct objc_object { + struct objc_class *isa; +} *id; + +@interface NSObject { + id firstobj; + struct objc_class *isa; +} +@end +@interface Whatever : NSObject ++self; +@end + +static void func() { + + id x; + + // rdar://8290002 + [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + + Whatever *y; + + // GCC allows this, with the following warning: + // instance variable 'isa' is @protected; this will be a hard error in the future + // + // FIXME: see if we can avoid the warning that follows the error. + [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \ + expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} + [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \ + expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} +} + +// rdar://11702488 +// If an ivar is (1) the first ivar in a root class and (2) named `isa`, +// then it should get the same warnings that id->isa gets. + +@interface BaseClass { +@public + Class isa; // expected-note 4 {{instance variable is declared here}} +} +@end + +@interface OtherClass { +@public + id firstIvar; + Class isa; // note, not first ivar; +} +@end + +@interface Subclass : BaseClass @end + +@interface SiblingClass : BaseClass @end + +@interface Root @end + +@interface hasIsa : Root { +@public + Class isa; // note, isa is not in root class +} +@end + +@implementation Subclass +-(void)method { + hasIsa *u; + id v; + BaseClass *w; + Subclass *x; + SiblingClass *y; + OtherClass *z; + (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}} + (void)z->isa; + (void)u->isa; + + w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}} +} +@end + |

