| 1 |
/* Test instance variable scope. */ |
| 2 |
/* Author: Dimitris Papavasiliou <[email protected]>. */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-additional-options "-fno-local-ivars" } */ |
| 5 |
#include <objc/objc.h> |
| 6 |
|
| 7 |
#if defined(__has_attribute) && __has_attribute(objc_root_class) |
| 8 |
__attribute__((objc_root_class)) |
| 9 |
#endif |
| 10 |
@interface MyClass |
| 11 |
{ |
| 12 |
int someivar; |
| 13 |
} |
| 14 |
- (void) testscope; |
| 15 |
- (void) testshadowing; |
| 16 |
@end |
| 17 |
|
| 18 |
@implementation MyClass |
| 19 |
- (void) testscope |
| 20 |
{ |
| 21 |
int a; |
| 22 |
|
| 23 |
a = self->someivar; /* No warning or error. */ |
| 24 |
a = someivar; /* { dg-error ".someivar. undeclared" } */ |
| 25 |
} |
| 26 |
|
| 27 |
- (void) testshadowing |
| 28 |
{ |
| 29 |
int someivar = 1; |
| 30 |
int a; |
| 31 |
|
| 32 |
/* Since instance variables don't have local scope no shadowing |
| 33 |
should occur. */ |
| 34 |
|
| 35 |
a = someivar; /* No warning. */ |
| 36 |
} |
| 37 |
@end |