Fariborz Jahanian | 0910059 | 2012-06-21 21:35:15 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
| 3 | typedef struct objc_object { |
| 4 | struct objc_class *isa; |
| 5 | } *id; |
| 6 | |
| 7 | @interface NSObject { |
| 8 | id firstobj; |
| 9 | struct objc_class *isa; |
| 10 | } |
| 11 | @end |
| 12 | @interface Whatever : NSObject |
| 13 | +self; |
| 14 | @end |
| 15 | |
| 16 | static void func() { |
| 17 | |
| 18 | id x; |
| 19 | |
| 20 | // rdar://8290002 |
| 21 | [(*x).isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} |
| 22 | [x->isa self]; // expected-warning {{direct access to objective-c's isa is deprecated in favor of object_setClass() and object_getClass()}} |
| 23 | |
| 24 | Whatever *y; |
| 25 | |
| 26 | // GCC allows this, with the following warning: |
| 27 | // instance variable 'isa' is @protected; this will be a hard error in the future |
| 28 | // |
| 29 | // FIXME: see if we can avoid the 2 warnings that follow the error. |
| 30 | [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \ |
| 31 | expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \ |
| 32 | expected-warning{{method '-self' not found (return type defaults to 'id')}} |
| 33 | [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \ |
| 34 | expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}} \ |
| 35 | expected-warning{{method '-self' not found (return type defaults to 'id')}} |
| 36 | } |
| 37 | |
| 38 | // rdar://11702488 |
| 39 | // If an ivar is (1) the first ivar in a root class and (2) named `isa`, |
| 40 | // then it should get the same warnings that id->isa gets. |
| 41 | |
| 42 | @interface BaseClass { |
| 43 | @public |
| 44 | Class isa; // expected-note 3 {{ivar is declared here}} |
| 45 | } |
| 46 | @end |
| 47 | |
| 48 | @interface OtherClass { |
| 49 | @public |
| 50 | id firstIvar; |
| 51 | Class isa; // note, not first ivar; |
| 52 | } |
| 53 | @end |
| 54 | |
| 55 | @interface Subclass : BaseClass @end |
| 56 | |
| 57 | @interface SiblingClass : BaseClass @end |
| 58 | |
| 59 | @interface Root @end |
| 60 | |
| 61 | @interface hasIsa : Root { |
| 62 | @public |
| 63 | Class isa; // note, isa is not in root class |
| 64 | } |
| 65 | @end |
| 66 | |
| 67 | @implementation Subclass |
| 68 | -(void)method { |
| 69 | hasIsa *u; |
| 70 | id v; |
| 71 | BaseClass *w; |
| 72 | Subclass *x; |
| 73 | SiblingClass *y; |
| 74 | OtherClass *z; |
| 75 | (void)v->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} |
| 76 | (void)w->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} |
| 77 | (void)x->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} |
| 78 | (void)y->isa; // expected-warning {{direct access to objective-c's isa is deprecated}} |
| 79 | (void)z->isa; |
| 80 | (void)u->isa; |
| 81 | } |
| 82 | @end |
| 83 | |