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