From 370ce32a02500b1394456b4d1ca495e464624cc0 Mon Sep 17 00:00:00 2001 From: Ziemowit Laski Date: Fri, 6 Sep 2002 23:32:13 +0000 Subject: [PATCH] c-lang.c (objc_is_id): New stub. [gcc/ChangeLog] 2002-09-06 Ziemowit Laski * c-lang.c (objc_is_id): New stub. * c-tree.h (objc_is_id): New forward declaration. * c-typeck.c (build_c_cast): Do not strip protocol qualifiers from 'id' type. * objc/objc-act.c (objc_comptypes): Correct handling of protocol qualifiers. (objc_is_id): New. [gcc/testsuite/ChangeLog] 2002-09-05 Ziemowit Laski * objc.dg/proto-lossage-1.m: New test. From-SVN: r56905 --- gcc/ChangeLog | 10 ++++++ gcc/c-lang.c | 7 ++++ gcc/c-tree.h | 1 + gcc/c-typeck.c | 7 +++- gcc/objc/objc-act.c | 26 +++++++++++---- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/objc.dg/proto-lossage-1.m | 43 +++++++++++++++++++++++++ 7 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/objc.dg/proto-lossage-1.m diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 86f3fb22569..695809d33f3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2002-09-06 Ziemowit Laski + + * c-lang.c (objc_is_id): New stub. + * c-tree.h (objc_is_id): New forward declaration. + * c-typeck.c (build_c_cast): Do not strip protocol + qualifiers from 'id' type. + * objc/objc-act.c (objc_comptypes): Correct handling + of protocol qualifiers. + (objc_is_id): New. + Fri Sep 6 13:10:08 2002 Jeffrey A Law (law@redhat.com) * pentium.md (pentium-firstvboth): Fix typo. diff --git a/gcc/c-lang.c b/gcc/c-lang.c index ec17f505bea..8614e2500e5 100644 --- a/gcc/c-lang.c +++ b/gcc/c-lang.c @@ -174,6 +174,13 @@ is_class_name (arg) return 0; } +tree +objc_is_id (arg) + tree arg ATTRIBUTE_UNUSED; +{ + return 0; +} + void objc_check_decl (decl) tree decl ATTRIBUTE_UNUSED; diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 2976e65250a..aa2fda5d5ea 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -165,6 +165,7 @@ struct lang_type GTY(()) /* in c-lang.c and objc-act.c */ extern tree lookup_interface PARAMS ((tree)); extern tree is_class_name PARAMS ((tree)); +extern tree objc_is_id PARAMS ((tree)); extern void objc_check_decl PARAMS ((tree)); extern void finish_file PARAMS ((void)); extern int objc_comptypes PARAMS ((tree, tree, int)); diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 131eecd3221..ac77bc234c7 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3577,7 +3577,12 @@ build_c_cast (type, expr) if (type == error_mark_node || expr == error_mark_node) return error_mark_node; - type = TYPE_MAIN_VARIANT (type); + + /* 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 (!flag_objc || !objc_is_id (type)) + type = TYPE_MAIN_VARIANT (type); #if 0 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 6b4d76c2ec1..42861685b11 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -648,13 +648,16 @@ objc_comptypes (lhs, rhs, reflexive) tree cat; rproto_list = CLASS_PROTOCOL_LIST (rinter); - /* If the underlying ObjC class does not have - protocols attached to it, perhaps there are - "one-off" protocols attached to the rhs? - E.g., 'id foo;'. */ - if (!rproto_list) - rproto_list = TYPE_PROTOCOL_LIST (TREE_TYPE (rhs)); rproto = lookup_protocol_in_reflist (rproto_list, p); + /* If the underlying ObjC class does not have + the protocol we're looking for, check for "one-off" + protocols (e.g., `NSObject foo;') attached + to the rhs. */ + if (!rproto) + { + rproto_list = TYPE_PROTOCOL_LIST (TREE_TYPE (rhs)); + rproto = lookup_protocol_in_reflist (rproto_list, p); + } /* Check for protocols adopted by categories. */ cat = CLASS_CATEGORY_LIST (rinter); @@ -2261,6 +2264,17 @@ is_class_name (ident) return 0; } +tree +objc_is_id (ident) + tree ident; +{ + /* NB: This function may be called before the ObjC front-end + has been initialized, in which case ID_TYPE will be NULL. */ + return (id_type && ident && TYPE_P (ident) && IS_ID (ident)) + ? id_type + : NULL_TREE; +} + tree lookup_interface (ident) tree ident; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c60fc4a9f7..18696d09e52 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-09-05 Ziemowit Laski + + * objc.dg/proto-lossage-1.m: New test. + 2002-09-06 Neil Booth * gcc.dg/cpp/_Pragma4.c: Fix typo. diff --git a/gcc/testsuite/objc.dg/proto-lossage-1.m b/gcc/testsuite/objc.dg/proto-lossage-1.m new file mode 100644 index 00000000000..d312039262c --- /dev/null +++ b/gcc/testsuite/objc.dg/proto-lossage-1.m @@ -0,0 +1,43 @@ +/* Test for situations in which protocol conformance information + may be lost, leading to superfluous warnings. */ +/* Author: Ziemowit Laski . */ +/* { 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 +@end + +@protocol PlateMethods +- (void)someMethod; +@end + +@interface Foo { + NSObject *plate; + id plate1; + NSObject *plate2; +} +- (id ) getPlate; +- (id ) getPlate1; +- (int) getValue; +@end + +@implementation Foo +- (id ) getPlate { + return plate; /* { dg-bogus "does not implement" } */ +} +- (id ) getPlate1 { + return (id )plate1; /* { dg-bogus "does not conform" } */ +} +- (int) getValue { + int i = [plate1 someValue]; /* { dg-warning "not implemented by protocol" } */ + int j = [(id )plate1 someValue]; /* { dg-bogus "not implemented by protocol" } */ + int k = [(id)plate1 someValue]; /* { dg-bogus "not implemented by protocol" } */ + return i + j + k; +} +@end -- 2.30.2