blob: b1ffb4fc9008e4c871c949d58db9697f7882b148 [file] [log] [blame]
Fariborz Jahanian09100592012-06-21 21:35:15 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3typedef 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
16static void func() {
17
18 id x;
19
20 // rdar://8290002
Fariborz Jahanian7e352742013-03-27 21:19:25 +000021 [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
22 [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000023
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 //
John McCall2fbe92c2013-03-01 09:20:14 +000029 // FIXME: see if we can avoid the warning that follows the error.
Fariborz Jahanian09100592012-06-21 21:35:15 +000030 [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
John McCall2fbe92c2013-03-01 09:20:14 +000031 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000032 [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
John McCall2fbe92c2013-03-01 09:20:14 +000033 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000034}
35
36// rdar://11702488
37// If an ivar is (1) the first ivar in a root class and (2) named `isa`,
38// then it should get the same warnings that id->isa gets.
39
40@interface BaseClass {
41@public
Fariborz Jahanian99a72d22013-03-28 23:39:11 +000042 Class isa; // expected-note 4 {{instance variable is declared here}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000043}
44@end
45
46@interface OtherClass {
47@public
48 id firstIvar;
49 Class isa; // note, not first ivar;
50}
51@end
52
53@interface Subclass : BaseClass @end
54
55@interface SiblingClass : BaseClass @end
56
57@interface Root @end
58
59@interface hasIsa : Root {
60@public
61 Class isa; // note, isa is not in root class
62}
63@end
64
65@implementation Subclass
66-(void)method {
67 hasIsa *u;
68 id v;
69 BaseClass *w;
70 Subclass *x;
71 SiblingClass *y;
72 OtherClass *z;
Fariborz Jahanian99a72d22013-03-28 23:39:11 +000073 (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
74 (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
75 (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
76 (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000077 (void)z->isa;
78 (void)u->isa;
Fariborz Jahanian99a72d22013-03-28 23:39:11 +000079
80 w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}}
Fariborz Jahanian09100592012-06-21 21:35:15 +000081}
82@end
83