diff options
author | Ziemowit Laski <zlaski@apple.com> | 2005-06-24 01:03:21 +0000 |
---|---|---|
committer | Ziemowit Laski <zlaski@gcc.gnu.org> | 2005-06-24 01:03:21 +0000 |
commit | ee18782ffc3a93f9da379f652285a29972236f84 (patch) | |
tree | 4325b2700014ca08d2b701e3e38eae585599690c /gcc | |
parent | 0c9b7e9b5a0aa61d944c40759911d9b3638e1ab4 (diff) | |
download | gcc-ee18782ffc3a93f9da379f652285a29972236f84.zip gcc-ee18782ffc3a93f9da379f652285a29972236f84.tar.gz gcc-ee18782ffc3a93f9da379f652285a29972236f84.tar.bz2 |
proto-lossage-[1-4].mm: New.
[gcc/testsuite/ChangeLog]
2005-06-23 Ziemowit Laski <zlaski@apple.com>
* obj-c++.dg/proto-lossage-[1-4].mm: New.
From-SVN: r101284
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/proto-lossage-1.mm | 44 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/proto-lossage-2.mm | 20 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/proto-lossage-3.mm | 25 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/proto-lossage-4.mm | 52 |
5 files changed, 145 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4a59413..3a096e7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2005-06-23 Ziemowit Laski <zlaski@apple.com> + * obj-c++.dg/proto-lossage-[1-4].mm: New. + +2005-06-23 Ziemowit Laski <zlaski@apple.com> + * obj-c++.dg/typedef-alias-1.mm: New. * objc.dg/typedef-alias-1.m: New. diff --git a/gcc/testsuite/obj-c++.dg/proto-lossage-1.mm b/gcc/testsuite/obj-c++.dg/proto-lossage-1.mm new file mode 100644 index 0000000..2f7eb98 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/proto-lossage-1.mm @@ -0,0 +1,44 @@ +/* Test for situations in which protocol conformance information + may be lost, leading to superfluous warnings. */ +/* Author: Ziemowit Laski <zlaski@apple.com>. */ +/* { dg-do compile } */ + +/* One-line substitute for objc/objc.h */ +typedef struct objc_object { struct objc_class *class_pointer; } *id; + +@protocol NSObject +- (int)someValue; +@end + +@interface NSObject <NSObject> +@end + +@protocol PlateMethods +- (void)someMethod; +@end + +@interface Foo { + NSObject <PlateMethods> *plate; + id <PlateMethods> plate1; + NSObject *plate2; +} +- (id <PlateMethods>) getPlate; +- (id <NSObject>) getPlate1; +- (int) getValue; +@end + +@implementation Foo +- (id <PlateMethods>) getPlate { + return plate; /* { dg-bogus "does not implement" } */ +} +- (id <NSObject>) getPlate1 { + return (id <NSObject>)plate1; /* { dg-bogus "does not conform" } */ +} +- (int) getValue { + int i = [plate1 someValue]; /* { dg-warning ".\\-someValue. not found in protocol\\(s\\)" } */ + + int j = [(id <NSObject>)plate1 someValue]; /* { dg-bogus "not found in protocol" } */ + int k = [(id)plate1 someValue]; /* { dg-bogus "not found in protocol" } */ + return i + j + k; +} +@end diff --git a/gcc/testsuite/obj-c++.dg/proto-lossage-2.mm b/gcc/testsuite/obj-c++.dg/proto-lossage-2.mm new file mode 100644 index 0000000..b3ab968 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/proto-lossage-2.mm @@ -0,0 +1,20 @@ +/* Don't forget to look in protocols if a class (and its superclasses) do not + provide a suitable method. */ +/* { dg-do compile } */ + +#include <objc/Object.h> + +@protocol Zot +-(void) zot; +@end + +@interface Foo : Object <Zot> +@end + +int foo() +{ + Foo *f=nil; + [f zot]; /* There should be no warnings here! */ + return 0; +} + diff --git a/gcc/testsuite/obj-c++.dg/proto-lossage-3.mm b/gcc/testsuite/obj-c++.dg/proto-lossage-3.mm new file mode 100644 index 0000000..512a59e --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/proto-lossage-3.mm @@ -0,0 +1,25 @@ +/* Crash due to descriptionFor(Instance|Class)Method applied to + a protocol with no instance/class methods respectively. + Problem report and original fix by richard@brainstorm.co.uk. */ +/* { dg-do run } */ +#include <objc/objc.h> +#include <objc/Object.h> +#include <objc/Protocol.h> + +@protocol NoInstanceMethods ++ testMethod; +@end + +@protocol NoClassMethods +- testMethod; +@end + +int +main() +{ +[@protocol(NoInstanceMethods) descriptionForInstanceMethod: @selector(name)]; +[@protocol(NoInstanceMethods) descriptionForClassMethod: @selector(name)]; +[@protocol(NoClassMethods) descriptionForInstanceMethod: @selector(name)]; +[@protocol(NoClassMethods) descriptionForClassMethod: @selector(name)]; +return 0; +} diff --git a/gcc/testsuite/obj-c++.dg/proto-lossage-4.mm b/gcc/testsuite/obj-c++.dg/proto-lossage-4.mm new file mode 100644 index 0000000..a5092a1 --- /dev/null +++ b/gcc/testsuite/obj-c++.dg/proto-lossage-4.mm @@ -0,0 +1,52 @@ +/* Test for situations in which protocol conformance information + may be lost while casting. */ +/* Author: Ziemowit Laski <zlaski@apple.com>. */ +/* { dg-do compile } */ + +/* One-line substitute for objc/objc.h */ +typedef struct objc_object { struct objc_class *class_pointer; } *id; + +@protocol Proto +- (long)someValue; +@end + +@interface Obj +- (long)anotherValue; +@end + +long foo(void) { + long receiver = 2; + Obj *objrcvr; + Obj <Proto> *objrcvr2; + + /* NB: Since 'receiver' is an invalid ObjC message receiver, the compiler + should warn but then search for methods as if we were messaging 'id'. */ + + receiver += [receiver someValue]; /* { dg-warning "invalid receiver type .long int." } */ + receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .long int." } */ + + receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-error "invalid conversion" "" { target *-*-* } 28 } */ + + receiver += [(Obj *)receiver anotherValue]; + receiver += [(Obj <Proto> *)receiver someValue]; + receiver += [(Obj <Proto> *)receiver anotherValue]; + receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-error "invalid conversion" "" { target *-*-* } 34 } */ + + receiver += [objrcvr anotherValue]; + receiver += [(Obj <Proto> *)objrcvr someValue]; + receiver += [(Obj <Proto> *)objrcvr anotherValue]; + receiver += [objrcvr2 someValue]; + receiver += [objrcvr2 anotherValue]; + receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-warning "invalid conversion" "" { target *-*-* } 42 } */ + + receiver += [(Obj *)objrcvr2 anotherValue]; + + return receiver; +} + +/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ +/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ +/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |