1/* Test errors for accessing @private and @protected variables. */ 2/* Author: 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 "undeclared" } */ 38 /* { dg-error "function it appears in" "" { target *-*-* } { 37 } } */ 39 40 protected = 12; /* Ok */ 41 public = 12; /* Ok */ 42} 43@end 44 45int main (void) 46{ 47 MyClass *m = nil; 48 49 if (m != nil) 50 { 51 int access; 52 53 access = m->private; /* { dg-error "is declared private" } */ 54 access = m->protected; /* { dg-error "is declared protected" } */ 55 access = m->public; /* Ok */ 56 } 57 58 return 0; 59} 60