===================================================================
@@ -0,0 +1,33 @@
+/* Test disabling of warnings for shadowing instance variables. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-shadow-ivar" } */
+#include <objc/objc.h>
+
+@interface MyClass
+{
+@private
+ int private;
+
+@protected
+ int protected;
+
+@public
+ int public;
+}
+- (void) test;
+@end
+
+@implementation MyClass
+- (void) test
+{
+ int private = 12;
+ int protected = 12;
+ int public = 12;
+ int a;
+
+ a = private; /* { dg-warning "hides instance variable" "" { xfail *-*-* } } */
+ a = protected; /* { dg-warning "hides instance variable" "" { xfail *-*-* } } */
+ a = public; /* { dg-warning "hides instance variable" "" { xfail *-*-* } } */
+}
+@end
===================================================================
@@ -0,0 +1,21 @@
+/* Test instance variable scope. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+#include <objc/objc.h>
+
+@interface MyClass
+{
+ int someivar;
+}
+- (void) test;
+@end
+
+@implementation MyClass
+- (void) test
+{
+ int a;
+
+ a = self->someivar; /* Ok */
+ a = someivar; /* { dg-error ".someivar. undeclared" "" { xfail *-*-* } } */
+}
+@end
===================================================================
@@ -0,0 +1,34 @@
+/* Test instance variable scope. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-local-ivars" } */
+#include <objc/objc.h>
+
+@interface MyClass
+{
+ int someivar;
+}
+- (void) testscope;
+- (void) testshadowing;
+@end
+
+@implementation MyClass
+- (void) testscope
+{
+ int a;
+
+ a = self->someivar; /* Ok */
+ a = someivar; /* { dg-error ".someivar. undeclared" } */
+}
+
+- (void) testshadowing
+{
+ int someivar = 1;
+ int a;
+
+ /* Since instance variables don't have local scope no shadowing
+ should occur. */
+
+ a = someivar; /* { dg-warning "hides instance variable" "" { xfail *-*-* } } */
+}
+@end
===================================================================
@@ -0,0 +1,60 @@
+/* Test instance variable scope. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do run } */
+/* { dg-additional-options "-Wno-shadow-ivar" } */
+#include "../objc-obj-c++-shared/TestsuiteObject.m"
+#include <objc/objc.h>
+
+extern void abort(void);
+
+int someivar = 1;
+
+@interface MyClass: TestsuiteObject
+{
+ int someivar;
+}
+- (int) get;
+- (int) getHidden;
+@end
+
+@implementation MyClass
+- init
+{
+ someivar = 2;
+
+ return self;
+}
+
+- (int) get
+{
+ return someivar;
+}
+
+- (int) getHidden
+{
+ int someivar = 3;
+
+ return someivar;
+}
+@end
+
+int main(void)
+{
+ MyClass *object;
+
+ object = [[MyClass alloc] init];
+
+ /* Check whether the instance variable hides the global variable. */
+
+ if ([object get] != 2) {
+ abort();
+ }
+
+ /* Check whether the local variable hides the instance variable. */
+
+ if ([object getHidden] != 3) {
+ abort();
+ }
+
+ return 0;
+}
===================================================================
@@ -0,0 +1,86 @@
+/* Test instance variable scope. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do run } */
+/* { dg-additional-options "-Wno-shadow-ivar -fno-local-ivars" } */
+#include "../objc-obj-c++-shared/runtime.h"
+#include <objc/objc.h>
+
+extern void abort(void);
+
+int someivar = 1;
+
+@interface MyClass
+{
+ Class isa;
+ int someivar;
+}
+
++ (id) new;
++ (id) alloc;
+- (id) init;
+- (int) getGlobal;
+- (int) getInstance;
+- (int) getHidden;
+@end
+
+@implementation MyClass
++ (id) new
+{
+ return [[self alloc] init];
+}
+
++ (id) alloc
+{
+ return class_createInstance (self, 0);
+}
+
+- (id) init
+{
+ self->someivar = 2;
+
+ return self;
+}
+
+- (int) getGlobal
+{
+ return someivar;
+}
+
+- (int) getInstance
+{
+ return self->someivar;
+}
+
+- (int) getHidden
+{
+ int someivar = 3;
+
+ return someivar;
+}
+@end
+
+int main(void)
+{
+ id object;
+
+ object = [MyClass new];
+
+ /* Check for aliasing between instance variable and global
+ variable. */
+
+ if ([object getGlobal] != 1) {
+ abort();
+ }
+
+ if ([object getInstance] != 2) {
+ abort();
+ }
+
+ /* Check wheter the local variable hides the instance variable. */
+
+ if ([object getHidden] != 3) {
+ abort();
+ }
+
+ return 0;
+}
===================================================================
@@ -0,0 +1,33 @@
+/* Test instance variable visibility. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+#include <objc/objc.h>
+
+@interface MySuperClass
+{
+ int someivar;
+}
+@end
+
+@implementation MySuperClass
+@end
+
+
+@interface MyClass : MySuperClass
+@end
+
+@implementation MyClass
+@end
+
+@interface MyOtherClass
+- (void) test: (MyClass *) object;
+@end
+
+@implementation MyOtherClass
+- (void) test: (MyClass *) object
+{
+ int a;
+
+ a = object->someivar; /* { dg-error "instance variable .someivar. is declared protected" } */
+}
+@end
===================================================================
@@ -0,0 +1,34 @@
+/* Test instance variable visibility. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+/* { dg-additional-options "-fivar-visibility=protected" } */
+#include <objc/objc.h>
+
+@interface MySuperClass
+{
+ int someivar;
+}
+@end
+
+@implementation MySuperClass
+@end
+
+
+@interface MyClass : MySuperClass
+@end
+
+@implementation MyClass
+@end
+
+@interface MyOtherClass
+- (void) test: (MyClass *) object;
+@end
+
+@implementation MyOtherClass
+- (void) test: (MyClass *) object
+{
+ int a;
+
+ a = object->someivar; /* { dg-error "instance variable .someivar. is declared protected" } */
+}
+@end
===================================================================
@@ -0,0 +1,34 @@
+/* Test instance variable visibility. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+/* { dg-additional-options "-fivar-visibility=private" } */
+#include <objc/objc.h>
+
+@interface MySuperClass
+{
+ int someivar;
+}
+@end
+
+@implementation MySuperClass
+@end
+
+
+@interface MyClass : MySuperClass
+@end
+
+@implementation MyClass
+@end
+
+@interface MyOtherClass
+- (void) test: (MyClass *) object;
+@end
+
+@implementation MyOtherClass
+- (void) test: (MyClass *) object
+{
+ int a;
+
+ a = object->someivar; /* { dg-error "instance variable .someivar. is declared private" } */
+}
+@end
===================================================================
@@ -0,0 +1,34 @@
+/* Test instance variable visibility. */
+/* Author: Dimitris Papavasiliou <dpapavas@gmail.com>. */
+/* { dg-do compile } */
+/* { dg-additional-options "-fivar-visibility=public" } */
+#include <objc/objc.h>
+
+@interface MySuperClass
+{
+ int someivar;
+}
+@end
+
+@implementation MySuperClass
+@end
+
+
+@interface MyClass : MySuperClass
+@end
+
+@implementation MyClass
+@end
+
+@interface MyOtherClass
+- (void) test: (MyClass *) object;
+@end
+
+@implementation MyOtherClass
+- (void) test: (MyClass *) object
+{
+ int a;
+
+ a = object->someivar; /* { dg-error "instance variable .someivar. is declared (private|protected)" "" { xfail *-*-* } } */
+}
+@end