summaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/private-1.mm
blob: c4ec5ffb9b1baabe1442a65f8141f13098d2a168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Test errors for accessing @private and @protected variables.  */
/* Based on work by: Nicola Pero <nicola@brainstorm.co.uk>.  */

/* { dg-do compile } */

#include <objc/objc.h>

@interface MySuperClass
{
@private
  int _private;

@protected
  int _protected;

@public
  int _public;
}
- (void) test;
@end

@implementation MySuperClass
- (void) test
{
  _private = 12;   /* Ok  */
  _protected = 12; /* Ok  */
  _public = 12;    /* Ok  */
}
@end


@interface MyClass : MySuperClass 
@end

@implementation MyClass
- (void) test
{
  /* Private variables simply don't exist in the subclass.  */
  _private = 12; /* { dg-error "._private. was not declared in this scope" } */

  _protected = 12; /* Ok  */
  _public = 12;    /* Ok  */
}
@end

int main (void)
{
  MyClass *m = nil;
  
  if (m != nil)
    {
      int access;

      access = m->_private;   /* { dg-error "is @private" }  */
      access = m->_protected; /* { dg-error "is @protected" }  */
      access = m->_public;    /* Ok  */
    }

  return 0;
}