| 1 |
/* Test handling of the NSObject attribute. */ |
| 2 |
/* { dg-additional-options "-fsyntax-only -Wno-objc-root-class" } */ |
| 3 |
|
| 4 |
typedef struct AnObj * __attribute__ ((NSObject)) AnObjRef; |
| 5 |
typedef struct AnObj * __attribute__ ((__NSObject__)) AnotherObjRef; |
| 6 |
|
| 7 |
/* We allow a void * to be labeled as NSObject. */ |
| 8 |
typedef void * __attribute__((NSObject)) AnonRef; |
| 9 |
|
| 10 |
typedef struct AnObj * __attribute__((NSObject("foo"))) Bad; // { dg-error {wrong number of arguments specified for 'NSObject' attribute} } |
| 11 |
typedef struct AnObj * __attribute__((NSObject(42))) Wrong; // { dg-error {wrong number of arguments specified for 'NSObject' attribute} } |
| 12 |
|
| 13 |
/* Must be a pointer. */ |
| 14 |
typedef struct AnObj __attribute__((NSObject)) BadRef; // { dg-error {'NSObject' attribute is for pointer types only} } |
| 15 |
|
| 16 |
typedef void * VPtr; |
| 17 |
|
| 18 |
@interface CheckAttrNSObject |
| 19 |
{ |
| 20 |
@public |
| 21 |
AnObjRef aor; |
| 22 |
/* TODO: synthesize without pre-defined ivars. */ |
| 23 |
VPtr obj_v; |
| 24 |
int bar; |
| 25 |
/* TODO: This should warn, even tho the property does not */ |
| 26 |
__attribute__((NSObject)) struct AnObj *Thing; |
| 27 |
} |
| 28 |
|
| 29 |
@property(copy) AnObjRef aor; |
| 30 |
|
| 31 |
typedef struct AnObj * __attribute__((NSObject)) AnObjPtr3; |
| 32 |
@property (nonatomic, retain) AnObjPtr3 obj_3; |
| 33 |
|
| 34 |
@property (retain) __attribute__((NSObject)) VPtr obj_v; |
| 35 |
|
| 36 |
//@property (strong, nullable) AnObjPtr3 objp_4; |
| 37 |
|
| 38 |
@property(retain) __attribute__((NSObject)) int bar; |
| 39 |
// { dg-error {'NSObject' attribute is for pointer types only} "" { target *-*-* } .-1 } |
| 40 |
// { dg-error {'retain' attribute is only valid for Objective-C objects} "" { target *-*-* } .-2 } |
| 41 |
|
| 42 |
@end |
| 43 |
|
| 44 |
void foo () |
| 45 |
{ |
| 46 |
__attribute__((NSObject)) struct AnObj *AnotherThing; // { dg-warning {'NSObject' attribute may be put on a typedef only; attribute is ignored} } |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
setProperty(id self, id value) |
| 51 |
{ |
| 52 |
((CheckAttrNSObject *)self)->aor = value; |
| 53 |
} |
| 54 |
|
| 55 |
id |
| 56 |
getProperty(id self) |
| 57 |
{ |
| 58 |
return (id)((CheckAttrNSObject *)self)->aor; |
| 59 |
} |
| 60 |
|
| 61 |
@implementation CheckAttrNSObject |
| 62 |
@synthesize aor; |
| 63 |
@dynamic obj_3; |
| 64 |
@synthesize obj_v; |
| 65 |
@synthesize bar; |
| 66 |
@end // { dg-error {invalid conversion} } |