summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/private-1.m
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-01 07:40:02 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-01 07:40:02 +0000
commit2bd21a29979e347a838ea8c645376f660a0f4e65 (patch)
tree139086f8092179d1478c674d6dd17965d6d53178 /gcc/testsuite/objc.dg/private-1.m
parent7a20f1a02a00029812901f16a9fc65f3b3d4c68c (diff)
downloadgcc-2bd21a29979e347a838ea8c645376f660a0f4e65.tar.gz
2004-06-01 Nicola Pero <nicola@brainstorm.co.uk>
Fix PR objc/7993: * objc-act.c (is_private): Do not emit the 'instance variable %s is declared private' error. (is_public): Emit the error after calling is_private. (lookup_objc_ivar): If the instance variable is private, return 0 - the instance variable is invisible here. testsuite: * objc.dg/private-1.m, objc-dg/private-2.m: New testcases. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82532 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/objc.dg/private-1.m')
-rw-r--r--gcc/testsuite/objc.dg/private-1.m59
1 files changed, 59 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/private-1.m b/gcc/testsuite/objc.dg/private-1.m
new file mode 100644
index 00000000000..f4d8a5268ba
--- /dev/null
+++ b/gcc/testsuite/objc.dg/private-1.m
@@ -0,0 +1,59 @@
+/* Test errors for accessing @private and @protected variables. */
+/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
+/* { dg-do compile } */
+#include <objc/objc.h>
+
+@interface MySuperClass
+{
+@private
+ int private;
+
+@protected
+ int protected;
+
+@public
+ int public;
+}
+- (void) test;
+@end
+
+@implementation MySuperClass
+- (void) test
+{
+ private = 12; /* Ok */
+ protected = 12; /* Ok */
+ public = 12; /* Ok */
+}
+@end
+
+
+@interface MyClass : MySuperClass
+@end
+
+@implementation MyClass
+- (void) test
+{
+ /* Private variables simply don't exist in the subclass. */
+ private = 12;/* { dg-error "undeclared" } */
+ /* { dg-error "function it appears in" "" { target *-*-* } { 37 } } */
+
+ protected = 12; /* Ok */
+ public = 12; /* Ok */
+}
+@end
+
+int main (void)
+{
+ MyClass *m = nil;
+
+ if (m != nil)
+ {
+ int access;
+
+ access = m->private; /* { dg-error "is @private" } */
+ access = m->protected; /* { dg-error "is @protected" } */
+ access = m->public; /* Ok */
+ }
+
+ return 0;
+}