2013-04-23 06:09:21 +08:00
|
|
|
// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
|
|
|
|
|
|
|
|
//====------------------------------------------------------------====//
|
|
|
|
// Test deprecated direct usage of the 'isa' pointer.
|
|
|
|
//====------------------------------------------------------------====//
|
|
|
|
|
|
|
|
typedef unsigned long NSUInteger;
|
2009-07-16 08:25:06 +08:00
|
|
|
|
|
|
|
typedef struct objc_object {
|
|
|
|
struct objc_class *isa;
|
|
|
|
} *id;
|
|
|
|
|
2009-07-25 01:54:45 +08:00
|
|
|
@interface NSObject {
|
2012-06-22 05:35:15 +08:00
|
|
|
id firstobj;
|
2009-07-25 01:54:45 +08:00
|
|
|
struct objc_class *isa;
|
|
|
|
}
|
2013-06-25 05:35:39 +08:00
|
|
|
- (id)performSelector:(SEL)aSelector;;
|
2009-07-25 01:54:45 +08:00
|
|
|
@end
|
|
|
|
@interface Whatever : NSObject
|
2009-07-16 08:25:06 +08:00
|
|
|
+self;
|
2013-06-25 05:35:39 +08:00
|
|
|
-(id)foo;
|
2009-07-16 08:25:06 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
static void func() {
|
|
|
|
|
|
|
|
id x;
|
|
|
|
|
2012-01-19 03:08:56 +08:00
|
|
|
// rdar://8290002
|
2013-03-28 05:19:25 +08:00
|
|
|
[(*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()}}
|
2009-07-25 01:54:45 +08:00
|
|
|
|
|
|
|
Whatever *y;
|
|
|
|
|
|
|
|
// GCC allows this, with the following warning:
|
2011-08-12 13:49:51 +08:00
|
|
|
// instance variable 'isa' is @protected; this will be a hard error in the future
|
2009-07-25 01:54:45 +08:00
|
|
|
//
|
2013-03-01 17:20:14 +08:00
|
|
|
// FIXME: see if we can avoid the warning that follows the error.
|
2009-07-25 01:54:45 +08:00
|
|
|
[(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
|
2013-03-01 17:20:14 +08:00
|
|
|
expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
|
2009-07-25 01:54:45 +08:00
|
|
|
[y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
|
2013-03-01 17:20:14 +08:00
|
|
|
expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
|
2009-07-16 08:25:06 +08:00
|
|
|
}
|
2012-06-22 05:35:15 +08:00
|
|
|
|
|
|
|
// 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
|
2013-03-29 07:39:11 +08:00
|
|
|
Class isa; // expected-note 4 {{instance variable is declared here}}
|
2012-06-22 05:35:15 +08:00
|
|
|
}
|
|
|
|
@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;
|
2013-03-29 07:39:11 +08:00
|
|
|
(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()}}
|
2012-06-22 05:35:15 +08:00
|
|
|
(void)z->isa;
|
|
|
|
(void)u->isa;
|
2013-03-29 07:39:11 +08:00
|
|
|
|
|
|
|
w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}}
|
2012-06-22 05:35:15 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2013-04-24 14:52:20 +08:00
|
|
|
// Test for introspection of Objective-C pointers via bitmasking.
|
|
|
|
|
|
|
|
void testBitmasking(NSObject *p) {
|
|
|
|
(void) (((NSUInteger) p) & 0x1); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
|
|
(void) (0x1 & ((NSUInteger) p)); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
|
|
(void) (((NSUInteger) p) ^ 0x1); // no-warning
|
|
|
|
(void) (0x1 ^ ((NSUInteger) p)); // no-warning
|
2013-06-25 05:35:39 +08:00
|
|
|
(void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection-performSelector"
|
|
|
|
(void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // no-warning
|
|
|
|
#pragma clang diagnostic pop
|
2013-04-24 14:52:20 +08:00
|
|
|
}
|