| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 4 |
|
| 5 |
/* Test @dynamic in the real scenario where a class declares a |
| 6 |
@property, uses @dynamic to avoid implementing it, then subclasses |
| 7 |
implement it. */ |
| 8 |
|
| 9 |
#include <objc/objc.h> |
| 10 |
#include <objc/runtime.h> |
| 11 |
#include <stdlib.h> |
| 12 |
|
| 13 |
@interface MyRootClass |
| 14 |
{ |
| 15 |
Class isa; |
| 16 |
} |
| 17 |
@property int a; |
| 18 |
+ (id) initialize; |
| 19 |
+ (id) alloc; |
| 20 |
- (id) init; |
| 21 |
@end |
| 22 |
|
| 23 |
@implementation MyRootClass |
| 24 |
+ (id) initialize { return self; } |
| 25 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 26 |
- (id) init { return self; } |
| 27 |
@dynamic a; |
| 28 |
@end |
| 29 |
|
| 30 |
@interface Test : MyRootClass |
| 31 |
{ |
| 32 |
int v1; |
| 33 |
} |
| 34 |
@end |
| 35 |
|
| 36 |
@implementation Test |
| 37 |
@synthesize a = v1; |
| 38 |
@end |
| 39 |
|
| 40 |
int main (void) |
| 41 |
{ |
| 42 |
/* Note how 'object' is declared to be of class 'MyRootClass', but |
| 43 |
actually is of the subclass which implements the property for |
| 44 |
real. */ |
| 45 |
MyRootClass *object = [[Test alloc] init]; |
| 46 |
|
| 47 |
object.a = 40; |
| 48 |
|
| 49 |
if (object.a != 40) |
| 50 |
abort (); |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |