This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: More ObjC++ test cases


[gcc/testsuite/ChangeLog]
2005-06-23  Ziemowit Laski  <zlaski@apple.com>

* obj-c++.dg/proto-lossage-[1-4].mm: New.

Index: obj-c++.dg/proto-lossage-1.mm
===================================================================
RCS file: obj-c++.dg/proto-lossage-1.mm
diff -N obj-c++.dg/proto-lossage-1.mm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ obj-c++.dg/proto-lossage-1.mm 24 Jun 2005 01:00:58 -0000
@@ -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
Index: obj-c++.dg/proto-lossage-2.mm
===================================================================
RCS file: obj-c++.dg/proto-lossage-2.mm
diff -N obj-c++.dg/proto-lossage-2.mm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ obj-c++.dg/proto-lossage-2.mm 24 Jun 2005 01:00:58 -0000
@@ -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;
+}
+
Index: obj-c++.dg/proto-lossage-3.mm
===================================================================
RCS file: obj-c++.dg/proto-lossage-3.mm
diff -N obj-c++.dg/proto-lossage-3.mm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ obj-c++.dg/proto-lossage-3.mm 24 Jun 2005 01:00:58 -0000
@@ -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;
+}
Index: obj-c++.dg/proto-lossage-4.mm
===================================================================
RCS file: obj-c++.dg/proto-lossage-4.mm
diff -N obj-c++.dg/proto-lossage-4.mm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ obj-c++.dg/proto-lossage-4.mm 24 Jun 2005 01:00:58 -0000
@@ -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 } */


--------------------------------------------------------------
Ziemowit Laski                 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group        Cupertino, CA USA  95014-2083
Apple Computer, Inc.           +1.408.974.6229  Fax .5477


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]