| 1 |
/* Test warnings for shadowing instance variables. */ |
| 2 |
/* Based on work by: Nicola Pero <[email protected]>. */ |
| 3 |
|
| 4 |
/* { dg-do compile } */ |
| 5 |
// { dg-additional-options "-Wno-objc-root-class" } |
| 6 |
|
| 7 |
#include <objc/objc.h> |
| 8 |
|
| 9 |
@interface MySuperClass |
| 10 |
{ |
| 11 |
@private |
| 12 |
int _private; |
| 13 |
|
| 14 |
@protected |
| 15 |
int _protected; |
| 16 |
|
| 17 |
@public |
| 18 |
int _public; |
| 19 |
} |
| 20 |
- (void) test; |
| 21 |
@end |
| 22 |
|
| 23 |
@implementation MySuperClass |
| 24 |
- (void) test |
| 25 |
{ |
| 26 |
/* FIXME: I wonder if the warnings shouldn't be better generated |
| 27 |
when the variable is declared, rather than used! */ |
| 28 |
int _private = 12; |
| 29 |
int _protected = 12; |
| 30 |
int _public = 12; |
| 31 |
int a; |
| 32 |
|
| 33 |
a = _private; /* { dg-warning "hides instance variable" } */ |
| 34 |
a = _protected; /* { dg-warning "hides instance variable" } */ |
| 35 |
a = _public; /* { dg-warning "hides instance variable" } */ |
| 36 |
} |
| 37 |
@end |
| 38 |
|
| 39 |
|
| 40 |
@interface MyClass : MySuperClass |
| 41 |
@end |
| 42 |
|
| 43 |
@implementation MyClass |
| 44 |
- (void) test |
| 45 |
{ |
| 46 |
int _private = 12; |
| 47 |
int _protected = 12; |
| 48 |
int _public = 12; |
| 49 |
int a; |
| 50 |
|
| 51 |
/* The private variable can be shadowed without warnings, because |
| 52 |
* it's invisible, and not accessible, to the subclass! */ |
| 53 |
a = _private; /* Ok */ |
| 54 |
a = _protected; /* { dg-warning "hides instance variable" } */ |
| 55 |
a = _public; /* { dg-warning "hides instance variable" } */ |
| 56 |
} |
| 57 |
@end |