summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/private-2.m
blob: eff376a0c84bbbc396442ccc047ee7fddb4a8974 (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
/* Test warnings for shadowing instance variables.  */
/* Author: 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
{
  /* FIXME: I wonder if the warnings shouldn't be better generated
     when the variable is declared, rather than used!  */
  int private = 12;
  int protected = 12;
  int public = 12;
  int a;
  
  a = private;    /* { dg-warning "hides instance variable" } */
  a = protected;  /* { dg-warning "hides instance variable" } */
  a = public;     /* { dg-warning "hides instance variable" } */
}
@end


@interface MyClass : MySuperClass 
@end

@implementation MyClass
- (void) test
{
  int private = 12;
  int protected = 12;
  int public = 12;
  int a;

  /* The private variable can be shadowed without warnings, because
   * it's invisible, and not accessible, to the subclass!  */
  a = private;   /* Ok  */
  a = protected; /* { dg-warning "hides instance variable" } */
  a = public;    /* { dg-warning "hides instance variable" } */
}
@end