2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / testsuite / objc.dg / private-2.m
blobeff376a0c84bbbc396442ccc047ee7fddb4a8974
1 /* Test warnings for shadowing instance variables.  */
2 /* Author: Nicola Pero <nicola@brainstorm.co.uk>.  */
3 /* { dg-do compile } */
4 #include <objc/objc.h>
6 @interface MySuperClass
8 @private
9   int private;
11 @protected
12   int protected;
14 @public
15   int public;
17 - (void) test;
18 @end
20 @implementation MySuperClass
21 - (void) test
23   /* FIXME: I wonder if the warnings shouldn't be better generated
24      when the variable is declared, rather than used!  */
25   int private = 12;
26   int protected = 12;
27   int public = 12;
28   int a;
29   
30   a = private;    /* { dg-warning "hides instance variable" } */
31   a = protected;  /* { dg-warning "hides instance variable" } */
32   a = public;     /* { dg-warning "hides instance variable" } */
34 @end
37 @interface MyClass : MySuperClass 
38 @end
40 @implementation MyClass
41 - (void) test
43   int private = 12;
44   int protected = 12;
45   int public = 12;
46   int a;
48   /* The private variable can be shadowed without warnings, because
49    * it's invisible, and not accessible, to the subclass!  */
50   a = private;   /* Ok  */
51   a = protected; /* { dg-warning "hides instance variable" } */
52   a = public;    /* { dg-warning "hides instance variable" } */
54 @end