aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/ivar-scope-3.m
blob: 0bf7aa1a114ad2ab53d7f56962839162115fbc80 (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 instance variable scope.  */
/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>.  */
/* { dg-do run } */
/* { dg-additional-options "-Wno-shadow-ivar" } */
#include "../objc-obj-c++-shared/TestsuiteObject.m"
#include <objc/objc.h>

extern void abort(void);

int someivar = 1;

@interface MyClass: TestsuiteObject
{
  int someivar;
}
- (int) get;
- (int) getHidden;
@end

@implementation MyClass
- init
{
  someivar = 2;

  return self;
}

- (int) get
{
  return someivar;
}

- (int) getHidden
{
  int someivar = 3;
  
  return someivar;
}
@end

int main(void)
{
  MyClass *object;

  object = [[MyClass alloc] init];

  /* Check whether the instance variable hides the global variable. */
  
  if ([object get] != 2) {
    abort();
  }

  /* Check whether the local variable hides the instance variable. */
  
  if ([object getHidden] != 3) {
    abort();
  }

  return 0;
}