1/* Test warnings for shadowing instance variables.  */
2/* Based on work by: Nicola Pero <nicola@brainstorm.co.uk>.  */
3
4/* { dg-do compile } */
5
6#include <objc/objc.h>
7
8@interface MySuperClass
9{
10@private
11  int _private;
12
13@protected
14  int _protected;
15
16@public
17  int _public;
18}
19- (void) test;
20@end
21
22@implementation MySuperClass
23- (void) test
24{
25  /* FIXME: I wonder if the warnings shouldn't be better generated
26     when the variable is declared, rather than used!  */
27  int _private = 12;
28  int _protected = 12;
29  int _public = 12;
30  int a;
31
32  a = _private;    /* { dg-warning "hides instance variable" } */
33  a = _protected;  /* { dg-warning "hides instance variable" } */
34  a = _public;     /* { dg-warning "hides instance variable" } */
35}
36@end
37
38
39@interface MyClass : MySuperClass
40@end
41
42@implementation MyClass
43- (void) test
44{
45  int _private = 12;
46  int _protected = 12;
47  int _public = 12;
48  int a;
49
50  /* The private variable can be shadowed without warnings, because
51   * it's invisible, and not accessible, to the subclass!  */
52  a = _private;   /* Ok  */
53  a = _protected; /* { dg-warning "hides instance variable" } */
54  a = _public;    /* { dg-warning "hides instance variable" } */
55}
56@end
57