blob: 6bd2d5dabc4b9ad0e17d98da258a559049a13ed0 [file] [log] [blame]
Patrick Beardb2f68202012-04-06 18:12:22 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +00002
3typedef struct CGColor * __attribute__ ((NSObject)) CGColorRef;
Aaron Ballmanbaec7782013-07-23 19:30:11 +00004typedef struct CGColor * __attribute__((NSObject(12))) Illegal; // expected-error {{'NSObject' attribute takes no arguments}}
Aaron Ballman081c8832013-07-23 12:13:14 +00005
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +00006static int count;
7static CGColorRef tmp = 0;
8
Stephen Hines651f13c2014-04-23 16:59:28 -07009typedef struct S1 __attribute__ ((NSObject)) CGColorRef1; // expected-error {{'NSObject' attribute is for pointer types only}}
Ted Kremenek9af91222012-08-29 22:54:47 +000010typedef void * __attribute__ ((NSObject)) CGColorRef2; // no-warning
11typedef void * CFTypeRef;
Fariborz Jahanian842f07b2010-03-30 22:40:11 +000012
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000013@interface HandTested {
14@public
15 CGColorRef x;
16}
Fariborz Jahanian842f07b2010-03-30 22:40:11 +000017
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000018@property(copy) CGColorRef x;
Ted Kremenek9af91222012-08-29 22:54:47 +000019// rdar://problem/7809460
20typedef struct CGColor * __attribute__((NSObject)) CGColorRefNoNSObject; // no-warning
Fariborz Jahanian9b2eb7b2011-11-29 01:48:40 +000021@property (nonatomic, retain) CGColorRefNoNSObject color;
Ted Kremenek9af91222012-08-29 22:54:47 +000022// rdar://problem/12197822
23@property (strong) __attribute__((NSObject)) CFTypeRef myObj; // no-warning
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000024@end
25
26void setProperty(id self, id value) {
27 ((HandTested *)self)->x = value;
28}
29
30id getProperty(id self) {
31 return (id)((HandTested *)self)->x;
32}
33
34@implementation HandTested
35@synthesize x=x;
Ted Kremenek97573772012-08-30 00:27:25 +000036@synthesize myObj;
Fariborz Jahanian842f07b2010-03-30 22:40:11 +000037@dynamic color;
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000038@end
39
John McCall13591ed2009-07-25 04:36:53 +000040int main(int argc, char *argv[]) {
Fariborz Jahanianfa23c1d2009-01-13 23:34:40 +000041 HandTested *to;
42 to.x = tmp; // setter
43 if (tmp != to.x)
44 to.x = tmp;
45 return 0;
46}
47
Fariborz Jahanian9b2eb7b2011-11-29 01:48:40 +000048// rdar://10453342
49@interface I
50{
Stephen Hines651f13c2014-04-23 16:59:28 -070051 __attribute__((NSObject)) void * color; // expected-warning {{'NSObject' attribute may be put on a typedef only; attribute is ignored}}
Fariborz Jahanian9b2eb7b2011-11-29 01:48:40 +000052}
Ted Kremenekf6e88d72012-03-01 01:40:32 +000053 // <rdar://problem/10930507>
Fariborz Jahanian34276822012-05-31 23:18:32 +000054@property (nonatomic, retain) __attribute__((NSObject)) CGColorRefNoNSObject color; // // no-warning
Fariborz Jahanian9b2eb7b2011-11-29 01:48:40 +000055@end
56void test_10453342() {
Stephen Hines651f13c2014-04-23 16:59:28 -070057 char* __attribute__((NSObject)) string2 = 0; // expected-warning {{'NSObject' attribute may be put on a typedef only; attribute is ignored}}
Fariborz Jahanian9b2eb7b2011-11-29 01:48:40 +000058}
59
Fariborz Jahanian34276822012-05-31 23:18:32 +000060// rdar://11569860
61@interface A { int i; }
Stephen Hines651f13c2014-04-23 16:59:28 -070062@property(retain) __attribute__((NSObject)) int i; // expected-error {{'NSObject' attribute is for pointer types only}} \
Fariborz Jahanian34276822012-05-31 23:18:32 +000063 // expected-error {{property with 'retain (or strong)' attribute must be of object type}}
64@end
65
66@implementation A
67@synthesize i;
68@end
69