Debian Codegraph @

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

raw
1 /* Test errors for accessing @private and @protected 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 private = 12; /* Ok */
25 protected = 12; /* Ok */
26 public = 12; /* Ok */
27 }
28 @end
29
30
31 @interface MyClass : MySuperClass
32 @end
33
34 @implementation MyClass
35 - (void) test
36 {
37 /* Private variables simply don't exist in the subclass. */
38 private = 12; /* { dg-error "instance variable" } */
39 /* { dg-message "function it appears in" "" { target *-*-* } .-1 } */
40
41 protected = 12; /* Ok */
42 public = 12; /* Ok */
43 }
44 @end
45
46 int main (void)
47 {
48 MyClass *m = nil;
49
50 if (m != nil)
51 {
52 int access;
53
54 access = m->private; /* { dg-warning "is @private" } */
55 access = m->protected; /* { dg-warning "is @protected" } */
56 access = m->public; /* Ok */
57 }
58
59 return 0;
60 }