1 // RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
3 //====------------------------------------------------------------====//
4 // Test deprecated direct usage of the 'isa' pointer.
5 //====------------------------------------------------------------====//
7 typedef unsigned long NSUInteger;
9 typedef struct objc_object {
10 struct objc_class *isa;
15 struct objc_class *isa;
17 - (id)performSelector:(SEL)aSelector;;
19 @interface Whatever : NSObject
24 static void func(void) {
28 [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
29 [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
33 // GCC allows this, with the following warning:
34 // instance variable 'isa' is @protected; this will be a hard error in the future
36 // FIXME: see if we can avoid the warning that follows the error.
37 [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
38 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
39 [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
40 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
43 // If an ivar is (1) the first ivar in a root class and (2) named `isa`,
44 // then it should get the same warnings that id->isa gets.
46 @interface BaseClass {
48 Class isa; // expected-note 4 {{instance variable is declared here}}
52 @interface OtherClass {
55 Class isa; // note, not first ivar;
59 @interface Subclass : BaseClass @end
61 @interface SiblingClass : BaseClass @end
65 @interface hasIsa : Root {
67 Class isa; // note, isa is not in root class
71 @implementation Subclass
79 (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
80 (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
81 (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
82 (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
86 w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}}
90 // Test for introspection of Objective-C pointers via bitmasking.
92 void testBitmasking(NSObject *p) {
93 (void) (((NSUInteger) p) & 0x1); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
94 (void) (0x1 & ((NSUInteger) p)); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
95 (void) (((NSUInteger) p) ^ 0x1); // no-warning
96 (void) (0x1 ^ ((NSUInteger) p)); // no-warning
97 (void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
98 #pragma clang diagnostic push
99 #pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection-performSelector"
100 (void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // no-warning
101 #pragma clang diagnostic pop