| 1 |
/* Test errors for accessing @private and @protected variables. */ |
| 2 |
/* Based on work by: Nicola Pero <[email protected]>. */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
// { dg-additional-options "-Wno-objc-root-class" } |
| 5 |
#include <objc/objc.h> |
| 6 |
|
| 7 |
@interface MySuperClass |
| 8 |
{ |
| 9 |
@private |
| 10 |
int _private; |
| 11 |
|
| 12 |
@protected |
| 13 |
int _protected; |
| 14 |
|
| 15 |
@public |
| 16 |
int _public; |
| 17 |
} |
| 18 |
- (void) test; |
| 19 |
@end |
| 20 |
|
| 21 |
@implementation MySuperClass |
| 22 |
- (void) test |
| 23 |
{ |
| 24 |
_private = 12; /* Ok */ |
| 25 |
_protected = 12; /* Ok */ |
| 26 |
_public = 12; /* Ok */ |
| 27 |
} |
| 28 |
@end |
| 29 |
|
| 30 |
|
| 31 |
@interface MyClass : MySuperClass |
| 32 |
@end |
| 33 |
|
| 34 |
@implementation MyClass |
| 35 |
- (void) test |
| 36 |
{ |
| 37 |
/* Private variables simply don't exist in the subclass. */ |
| 38 |
_private = 12; /* { dg-error "instance variable \\'_private\\' is declared private" } */ |
| 39 |
|
| 40 |
_protected = 12; /* Ok */ |
| 41 |
_public = 12; /* Ok */ |
| 42 |
} |
| 43 |
@end |
| 44 |
|
| 45 |
int main (void) |
| 46 |
{ |
| 47 |
MyClass *m = nil; |
| 48 |
|
| 49 |
if (m != nil) |
| 50 |
{ |
| 51 |
int access; |
| 52 |
|
| 53 |
access = m->_private; /* { dg-warning "is @private" } */ |
| 54 |
access = m->_protected; /* { dg-warning "is @protected" } */ |
| 55 |
access = m->_public; /* Ok */ |
| 56 |
} |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |