From 700686faf4b0dd347b1dc735569b9fdfaef925d6 Mon Sep 17 00:00:00 2001 From: Ziemowit Laski Date: Wed, 25 Aug 2004 20:38:53 +0000 Subject: [PATCH] c-typeck.c (build_c_cast): In ObjC... [gcc/ChangeLog] 2004-08-25 Ziemowit Laski * c-typeck.c (build_c_cast): In ObjC, always preserve (and silently accept) a cast from one Objective-C pointer type to another. [gcc/testsuite/ChangeLog] 2004-08-25 Ziemowit Laski * objc.dg/proto-lossage-4.m: New test. From-SVN: r86574 --- gcc/ChangeLog | 5 +++ gcc/c-typeck.c | 6 ++- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/objc.dg/proto-lossage-4.m | 51 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/objc.dg/proto-lossage-4.m diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 56ab52c8c12..3ce3e7b1a1d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-08-25 Ziemowit Laski + + * c-typeck.c (build_c_cast): In ObjC, always preserve (and silently + accept) a cast from one Objective-C pointer type to another. + 2004-08-25 Paolo Carlini * doc/install.texi: Document that libstdc++-v3 requires diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index d71b99080ac..ca6e9f372a7 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2922,8 +2922,10 @@ build_c_cast (tree type, tree expr) /* The ObjC front-end uses TYPE_MAIN_VARIANT to tie together types differing only in qualifications. But when constructing cast expressions, the protocols do matter and must be kept around. */ - if (!c_dialect_objc () || !objc_is_object_ptr (type)) - type = TYPE_MAIN_VARIANT (type); + if (objc_is_object_ptr (type) && objc_is_object_ptr (TREE_TYPE (expr))) + return build1 (NOP_EXPR, type, expr); + + type = TYPE_MAIN_VARIANT (type); if (TREE_CODE (type) == ARRAY_TYPE) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0b6efa8dd15..ec0349e33e7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-08-25 Ziemowit Laski + + * objc.dg/proto-lossage-4.m: New test. + 2004-08-25 Mark Mitchell PR c++/17155 diff --git a/gcc/testsuite/objc.dg/proto-lossage-4.m b/gcc/testsuite/objc.dg/proto-lossage-4.m new file mode 100644 index 00000000000..5bd25a406f7 --- /dev/null +++ b/gcc/testsuite/objc.dg/proto-lossage-4.m @@ -0,0 +1,51 @@ +/* Test for situations in which protocol conformance information + may be lost while casting. */ +/* Author: Ziemowit Laski . */ +/* { dg-do compile } */ + +/* One-line substitute for objc/objc.h */ +typedef struct objc_object { struct objc_class *class_pointer; } *id; + +@protocol Proto +- (int)someValue; +@end + +@interface Obj +- (int)anotherValue; +@end + +int foo(void) { + int receiver = 2; + Obj *objrcvr; + Obj *objrcvr2; + + receiver += [receiver someValue]; /* { dg-warning "invalid receiver type .int( )?." } */ +/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 22 } */ +/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 22 } */ +/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 22 } */ +/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } 22 } */ + + receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .int( )?." } */ +/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } 28 } */ + + receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } 31 } */ + + receiver += [(Obj *)receiver anotherValue]; + receiver += [(Obj *)receiver someValue]; + receiver += [(Obj *)receiver anotherValue]; + receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } 37 } */ + + receiver += [objrcvr anotherValue]; + receiver += [(Obj *)objrcvr someValue]; + receiver += [(Obj *)objrcvr anotherValue]; + receiver += [objrcvr2 someValue]; + receiver += [objrcvr2 anotherValue]; + receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ +/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } 45 } */ + + receiver += [(Obj *)objrcvr2 anotherValue]; + + return receiver; +} -- 2.30.2