| 1 |
/* Basic test, auto-generated getter/setter based on property name. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 4 |
|
| 5 |
#ifdef __cplusplus |
| 6 |
extern "C" { |
| 7 |
#endif |
| 8 |
|
| 9 |
extern int printf (const char *fmt,...); |
| 10 |
extern void abort (void); |
| 11 |
|
| 12 |
#include <objc/objc.h> |
| 13 |
#include <objc/runtime.h> |
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
} |
| 17 |
#endif |
| 18 |
|
| 19 |
@interface Bar |
| 20 |
{ |
| 21 |
@public |
| 22 |
Class isa; |
| 23 |
int FooBar; |
| 24 |
} |
| 25 |
+ (id) initialize; |
| 26 |
+ (id) alloc ; |
| 27 |
- (id) init; |
| 28 |
- (int) whatIsFooBar; |
| 29 |
@property int FooBar; |
| 30 |
@end |
| 31 |
|
| 32 |
@implementation Bar |
| 33 |
|
| 34 |
+initialize { return self;} |
| 35 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 36 |
|
| 37 |
- (id) init {return self;} |
| 38 |
|
| 39 |
- (int) whatIsFooBar { return self->FooBar; } |
| 40 |
@synthesize FooBar; |
| 41 |
@end |
| 42 |
|
| 43 |
int main(int argc, char *argv[]) { |
| 44 |
int res; |
| 45 |
Bar *f = [[Bar alloc] init]; |
| 46 |
|
| 47 |
/* First, establish that the property getter & setter have been synthesized |
| 48 |
and operate correctly. */ |
| 49 |
[f setFooBar:1]; |
| 50 |
|
| 51 |
if ([f whatIsFooBar] != 1) |
| 52 |
{ printf ("setFooBar did not set FooBar\n"); abort ();} |
| 53 |
|
| 54 |
res = [f FooBar]; |
| 55 |
|
| 56 |
if (res != 1 ) |
| 57 |
{ printf ("[f FooBar] = %d\n", res); abort ();} |
| 58 |
|
| 59 |
/* Now check the short-cut object.property syntax. */ |
| 60 |
/* Read... */ |
| 61 |
res = f.FooBar; |
| 62 |
if (res != 1 ) |
| 63 |
{ printf ("f.FooBar = %d\n", res); abort ();} |
| 64 |
|
| 65 |
/* .... write. */ |
| 66 |
f.FooBar = 0; |
| 67 |
/* printf ("seems OK\n", res); */ |
| 68 |
return f.FooBar; |
| 69 |
} |
| 70 |
|