| 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 that setter/getters for dot-syntax are properly found even if |
| 6 |
not declared in the @interface, but available in the local |
| 7 |
@implementation before the current line (ie, [object name] can be |
| 8 |
compiled in that case, so object.name should be compiled too). */ |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <objc/objc.h> |
| 12 |
#include <objc/runtime.h> |
| 13 |
|
| 14 |
static int c; |
| 15 |
|
| 16 |
@interface MyRootClass |
| 17 |
{ |
| 18 |
Class isa; |
| 19 |
int a; |
| 20 |
} |
| 21 |
+ (id) initialize; |
| 22 |
+ (id) alloc; |
| 23 |
- (id) init; |
| 24 |
@end |
| 25 |
|
| 26 |
@implementation MyRootClass |
| 27 |
+ (id) initialize { return self; } |
| 28 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 29 |
- (id) init { return self; } |
| 30 |
- (int) count |
| 31 |
{ |
| 32 |
return a; |
| 33 |
} |
| 34 |
- (void) setCount: (int)count |
| 35 |
{ |
| 36 |
a = count; |
| 37 |
} |
| 38 |
+ (int) classCount |
| 39 |
{ |
| 40 |
return c; |
| 41 |
} |
| 42 |
+ (void) setClassCount: (int)count |
| 43 |
{ |
| 44 |
c = count; |
| 45 |
} |
| 46 |
- (int) testMe |
| 47 |
{ |
| 48 |
self.count = 400; |
| 49 |
if (self.count != 400) |
| 50 |
abort (); |
| 51 |
|
| 52 |
return self.count; |
| 53 |
} |
| 54 |
+ (int) testMe |
| 55 |
{ |
| 56 |
self.classCount = 4000; |
| 57 |
if (self.classCount != 4000) |
| 58 |
abort (); |
| 59 |
|
| 60 |
return self.classCount; |
| 61 |
} |
| 62 |
@end |
| 63 |
|
| 64 |
int main (void) |
| 65 |
{ |
| 66 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 67 |
|
| 68 |
if ([object testMe] != 400) |
| 69 |
abort (); |
| 70 |
|
| 71 |
if ([MyRootClass testMe] != 4000) |
| 72 |
abort (); |
| 73 |
|
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
|