aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/ivar-scope-2.m
blob: 1149d735d127bdb71cb354acbb2284747fe912cb (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
/* Test instance variable scope.  */
/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>.  */
/* { dg-do compile } */
/* { dg-additional-options "-fno-local-ivars" } */
#include <objc/objc.h>

#if defined(__has_attribute) && __has_attribute(objc_root_class)
__attribute__((objc_root_class))
#endif
@interface MyClass
{
  int someivar;
}
- (void) testscope;
- (void) testshadowing;
@end

@implementation MyClass
- (void) testscope
{
  int a;

  a = self->someivar;  /* No warning or error. */
  a = someivar;        /* { dg-error ".someivar. undeclared" } */
}

- (void) testshadowing
{
  int someivar = 1;
  int a;

  /* Since instance variables don't have local scope no shadowing
     should occur. */
  
  a = someivar; /* No warning. */
}
@end