1/* Basic test, auto-generated getter/setter based on named ivar */ 2/* { dg-do run } */ 3/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ 4 5#ifdef __cplusplus 6extern "C" { 7#endif 8 9extern int printf (const char *fmt,...); 10extern 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 var; 24} 25+ (id) initialize; 26+ (id) alloc ; 27- (id) init; 28 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@synthesize FooBar = var; 40@end 41 42int main(int argc, char *argv[]) { 43 int res; 44 Bar *f = [[Bar alloc] init]; 45 46 /* First, establish that the property getter & setter have been synthesized 47 and operate correctly. */ 48 [f setFooBar:1234]; 49 50 if (f->var != 1234) 51 { printf ("setFooBar did not set var correctly\n"); abort ();} 52 53 res = [f FooBar]; 54 55 if (res != 1234 ) 56 { printf ("[f FooBar] = %d\n", res); abort ();} 57 58 /* Now check the short-cut object.property syntax. */ 59 /* Read .... */ 60 res = f.FooBar; 61 if (res != 1234 ) 62 { printf ("f.FooBar = %d\n", res); abort ();} 63 64 /* ... and write. */ 65 f.FooBar = 0; 66 /* printf ("seems OK\n", res); */ 67 return f.FooBar; 68} 69 70