diff options
author | mrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-05-12 20:55:54 +0000 |
---|---|---|
committer | mrs <mrs@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-05-12 20:55:54 +0000 |
commit | 68b930c4a2e7d7aa8141e726cccde16f9e281f07 (patch) | |
tree | 89e1b74abd9a0e400a35d335b11456f551ac5d9f /gcc/testsuite/objc.dg | |
parent | 0a96ce03ce106e391dcc5d36d91df67e7b98021f (diff) | |
download | gcc-68b930c4a2e7d7aa8141e726cccde16f9e281f07.tar.gz |
2014-05-12 Dimitris Papavasiliou <dpapavas@gmail.com>
* doc/invoke.texi: Document new switches -Wno-shadow-ivar,
-fno-local-ivars and -fivar-visibility.
* c-family/c.opt: Make -Wshadow also implicitly enable
-Wshadow-ivar.
testsuite:
* objc.dg/shadow-1.m: New test.
* objc.dg/shadow-2.m: New test.
* objc.dg/ivar-scope-1.m: New test.
* objc.dg/ivar-scope-2.m: New test.
* objc.dg/ivar-scope-3.m: New test.
* objc.dg/ivar-scope-4.m: New test.
* objc.dg/ivar-visibility-1.m: New test.
* objc.dg/ivar-visibility-2.m: New test.
* objc.dg/ivar-visibility-3.m: New test.
* objc.dg/ivar-visibility-4.m: New test.
Now, actuatally add the files....
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210339 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/objc.dg')
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-scope-1.m | 24 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-scope-2.m | 34 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-scope-3.m | 60 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-scope-4.m | 83 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-visibility-1.m | 33 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-visibility-2.m | 34 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-visibility-3.m | 34 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/ivar-visibility-4.m | 36 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/shadow-1.m | 33 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/shadow-2.m | 33 |
10 files changed, 404 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/ivar-scope-1.m b/gcc/testsuite/objc.dg/ivar-scope-1.m new file mode 100644 index 00000000000..34443a442fe --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-scope-1.m @@ -0,0 +1,24 @@ +/* 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; + + /* Make sure instance variables do have local scope when + -fno-local-ivar isn't specified. */ + + a = self->someivar; /* No warning or error. */ + a = someivar; /* No error. */ +} +@end diff --git a/gcc/testsuite/objc.dg/ivar-scope-2.m b/gcc/testsuite/objc.dg/ivar-scope-2.m new file mode 100644 index 00000000000..ff795d08d6a --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-scope-2.m @@ -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; /* No warning or error. */ + 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; /* No warning. */ +} +@end diff --git a/gcc/testsuite/objc.dg/ivar-scope-3.m b/gcc/testsuite/objc.dg/ivar-scope-3.m new file mode 100644 index 00000000000..0bf7aa1a114 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-scope-3.m @@ -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; +} diff --git a/gcc/testsuite/objc.dg/ivar-scope-4.m b/gcc/testsuite/objc.dg/ivar-scope-4.m new file mode 100644 index 00000000000..f7209724be9 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-scope-4.m @@ -0,0 +1,83 @@ +/* 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; + +/* The testsuite object depends on local variable scope so we need to + implement our own minimal base object here. */ + +@interface MyClass +{ + Class isa; + int someivar; +} + ++ (id) alloc; +- (id) init; +- (int) getGlobal; +- (int) getInstance; +- (int) getHidden; +@end + +@implementation MyClass ++ (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 alloc] init]; + + /* Check for aliasing between instance variable and global + variable. */ + + if ([object getGlobal] != 1) { + abort(); + } + + if ([object getInstance] != 2) { + abort(); + } + + /* Check whether the local variable hides the instance variable. */ + + if ([object getHidden] != 3) { + abort(); + } + + return 0; +} diff --git a/gcc/testsuite/objc.dg/ivar-visibility-1.m b/gcc/testsuite/objc.dg/ivar-visibility-1.m new file mode 100644 index 00000000000..5a222591d19 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-visibility-1.m @@ -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 diff --git a/gcc/testsuite/objc.dg/ivar-visibility-2.m b/gcc/testsuite/objc.dg/ivar-visibility-2.m new file mode 100644 index 00000000000..eb41c8f4db0 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-visibility-2.m @@ -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 diff --git a/gcc/testsuite/objc.dg/ivar-visibility-3.m b/gcc/testsuite/objc.dg/ivar-visibility-3.m new file mode 100644 index 00000000000..ecc6f99c760 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-visibility-3.m @@ -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 diff --git a/gcc/testsuite/objc.dg/ivar-visibility-4.m b/gcc/testsuite/objc.dg/ivar-visibility-4.m new file mode 100644 index 00000000000..adfeb449e55 --- /dev/null +++ b/gcc/testsuite/objc.dg/ivar-visibility-4.m @@ -0,0 +1,36 @@ +/* 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; + + /* someivar is public so we shouldn't get any errors here. */ + + a = object->someivar; +} +@end diff --git a/gcc/testsuite/objc.dg/shadow-1.m b/gcc/testsuite/objc.dg/shadow-1.m new file mode 100644 index 00000000000..739a0d0312e --- /dev/null +++ b/gcc/testsuite/objc.dg/shadow-1.m @@ -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; /* No warning. */ + a = protected; /* No warning. */ + a = public; /* No warning. */ +} +@end diff --git a/gcc/testsuite/objc.dg/shadow-2.m b/gcc/testsuite/objc.dg/shadow-2.m new file mode 100644 index 00000000000..16261b94a21 --- /dev/null +++ b/gcc/testsuite/objc.dg/shadow-2.m @@ -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" } */ +#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; /* No warning. */ + a = protected; /* No warning. */ + a = public; /* No warning. */ +} +@end |