Daily bump.
[official-gcc.git] / gcc / testsuite / objc.dg / ivar-scope-4.m
blobdf1c8927586ef4ede0bdb0a1750ff4b5168ea5be
1 /* Test instance variable scope.  */
2 /* Author: Dimitris Papavasiliou <dpapavas@gmail.com>.  */
3 /* { dg-do run } */
4 /* { dg-additional-options "-Wno-shadow-ivar -fno-local-ivars -Wno-objc-root-class" } */
6 #include "../objc-obj-c++-shared/runtime.h"
7 #include <objc/objc.h>
9 extern void abort(void);
11 int someivar = 1;
13 /* The testsuite object depends on local variable scope so we need to
14    implement our own minimal base object here. */
16 @interface MyClass
18   Class isa;
19   int someivar;
22 + (id) initialize;
23 + (id) alloc;
24 - (id) init;
25 - (int) getGlobal;
26 - (int) getInstance;
27 - (int) getHidden;
28 @end
30 @implementation MyClass
31 + (id) initialize
33   return self;
36 + (id) alloc
38   return class_createInstance (self, 0);
41 - (id) init
43   self->someivar = 2;
45   return self;
48 - (int) getGlobal
50   return someivar;
53 - (int) getInstance
55   return self->someivar;
58 - (int) getHidden
60   int someivar = 3;
61   
62   return someivar;
64 @end
66 int main(void)
68   id object;
70   object = [[MyClass alloc] init];
72   /* Check for aliasing between instance variable and global
73      variable. */
75   if ([object getGlobal] != 1) {
76     abort();
77   }
78   
79   if ([object getInstance] != 2) {
80     abort();
81   }
83   /* Check whether the local variable hides the instance variable. */
84   
85   if ([object getHidden] != 3) {
86     abort();
87   }
89   return 0;