xref: /aosp_15_r20/external/clang/test/SemaObjC/nsobject-attribute.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li
3*67e74705SXin Litypedef struct CGColor * __attribute__ ((NSObject)) CGColorRef;
4*67e74705SXin Litypedef struct CGColor * __attribute__((NSObject(12))) Illegal;  // expected-error {{'NSObject' attribute takes no arguments}}
5*67e74705SXin Li
6*67e74705SXin Listatic int count;
7*67e74705SXin Listatic CGColorRef tmp = 0;
8*67e74705SXin Li
9*67e74705SXin Litypedef struct S1  __attribute__ ((NSObject)) CGColorRef1; // expected-error {{'NSObject' attribute is for pointer types only}}
10*67e74705SXin Litypedef void *  __attribute__ ((NSObject)) CGColorRef2; // no-warning
11*67e74705SXin Litypedef void * CFTypeRef;
12*67e74705SXin Li
13*67e74705SXin Li@interface HandTested {
14*67e74705SXin Li@public
15*67e74705SXin Li    CGColorRef x;
16*67e74705SXin Li}
17*67e74705SXin Li
18*67e74705SXin Li@property(copy) CGColorRef x;
19*67e74705SXin Li// rdar://problem/7809460
20*67e74705SXin Litypedef struct CGColor * __attribute__((NSObject)) CGColorRefNoNSObject; // no-warning
21*67e74705SXin Li@property (nonatomic, retain) CGColorRefNoNSObject color;
22*67e74705SXin Li// rdar://problem/12197822
23*67e74705SXin Li@property (strong) __attribute__((NSObject)) CFTypeRef myObj; // no-warning
24*67e74705SXin Li@end
25*67e74705SXin Li
26*67e74705SXin Livoid setProperty(id self, id value)  {
27*67e74705SXin Li  ((HandTested *)self)->x = value;
28*67e74705SXin Li}
29*67e74705SXin Li
30*67e74705SXin Liid getProperty(id self) {
31*67e74705SXin Li     return (id)((HandTested *)self)->x;
32*67e74705SXin Li}
33*67e74705SXin Li
34*67e74705SXin Li@implementation HandTested
35*67e74705SXin Li@synthesize x=x;
36*67e74705SXin Li@synthesize myObj;
37*67e74705SXin Li@dynamic color;
38*67e74705SXin Li@end
39*67e74705SXin Li
40*67e74705SXin Liint main(int argc, char *argv[]) {
41*67e74705SXin Li    HandTested *to;
42*67e74705SXin Li    to.x = tmp;  // setter
43*67e74705SXin Li    if (tmp != to.x)
44*67e74705SXin Li      to.x = tmp;
45*67e74705SXin Li    return 0;
46*67e74705SXin Li}
47*67e74705SXin Li
48*67e74705SXin Li// rdar://10453342
49*67e74705SXin Li@interface I
50*67e74705SXin Li{
51*67e74705SXin Li   __attribute__((NSObject)) void * color; // expected-warning {{'NSObject' attribute may be put on a typedef only; attribute is ignored}}
52*67e74705SXin Li}
53*67e74705SXin Li  // <rdar://problem/10930507>
54*67e74705SXin Li@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color; // // no-warning
55*67e74705SXin Li@end
56*67e74705SXin Livoid test_10453342() {
57*67e74705SXin Li    char* __attribute__((NSObject)) string2 = 0; // expected-warning {{'NSObject' attribute may be put on a typedef only; attribute is ignored}}
58*67e74705SXin Li}
59*67e74705SXin Li
60*67e74705SXin Li// rdar://11569860
61*67e74705SXin Li@interface A { int i; }
62*67e74705SXin Li@property(retain) __attribute__((NSObject)) int i; // expected-error {{'NSObject' attribute is for pointer types only}} \
63*67e74705SXin Li  						   // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
64*67e74705SXin Li@end
65*67e74705SXin Li
66*67e74705SXin Li@implementation A
67*67e74705SXin Li@synthesize i;
68*67e74705SXin Li@end
69*67e74705SXin Li
70