summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/c-lang.c7
-rw-r--r--gcc/c-tree.h1
-rw-r--r--gcc/c-typeck.c7
-rw-r--r--gcc/objc/objc-act.c26
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/objc.dg/proto-lossage-1.m43
7 files changed, 91 insertions, 7 deletions
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 <zlaski@apple.com>
+
+ * 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 <protocol> 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<MyProt> 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<MyProt> 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);
@@ -2262,6 +2265,17 @@ is_class_name (ident)
}
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 <zlaski@apple.com>
+
+ * objc.dg/proto-lossage-1.m: New test.
+
2002-09-06 Neil Booth <neil@daikokuya.co.uk>
* 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 <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 "not implemented by protocol" } */
+ int j = [(id <NSObject>)plate1 someValue]; /* { dg-bogus "not implemented by protocol" } */
+ int k = [(id)plate1 someValue]; /* { dg-bogus "not implemented by protocol" } */
+ return i + j + k;
+}
+@end