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