Debian Codegraph @

gcc/testsuite/objc.dg/private-2.m

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