OSDN Git Service

Index: objc/ChangeLog
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / private-1.mm
1 /* Test errors for accessing @private and @protected 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   _private = 12;   /* Ok  */
26   _protected = 12; /* Ok  */
27   _public = 12;    /* Ok  */
28 }
29 @end
30
31
32 @interface MyClass : MySuperClass 
33 @end
34
35 @implementation MyClass
36 - (void) test
37 {
38   /* Private variables simply don't exist in the subclass.  */
39   _private = 12; /* { dg-error "._private. was not declared in this scope" } */
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-error "is @private" }  */
55       access = m->_protected; /* { dg-error "is @protected" }  */
56       access = m->_public;    /* Ok  */
57     }
58
59   return 0;
60 }