]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-lang.c (objc_is_id): New stub.
authorZiemowit Laski <zlaski@apple.com>
Fri, 6 Sep 2002 23:32:13 +0000 (23:32 +0000)
committerZiemowit Laski <zlaski@gcc.gnu.org>
Fri, 6 Sep 2002 23:32:13 +0000 (23:32 +0000)
[gcc/ChangeLog]
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.

[gcc/testsuite/ChangeLog]
2002-09-05  Ziemowit Laski <zlaski@apple.com>

        * objc.dg/proto-lossage-1.m: New test.

From-SVN: r56905

gcc/ChangeLog
gcc/c-lang.c
gcc/c-tree.h
gcc/c-typeck.c
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/proto-lossage-1.m [new file with mode: 0644]

index 86f3fb225699a8ef3a68257e92ba8b33d1235085..695809d33f3529f76d1bb00e2b05bcda710984d4 100644 (file)
@@ -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.
index ec17f505bea3066ddbd50ee7909296a6df448b00..8614e2500e5ece8fea50af377c8c16c2bf51af13 100644 (file)
@@ -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;
index 2976e65250aa88fe8be0413404cc15673a23de3a..aa2fda5d5ea32652c1c92567e6a55edcece220f7 100644 (file)
@@ -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));
index 131eecd322166aac423bf72c65f2feb29cd45327..ac77bc234c7d7d11b52f905cd913588f6c347f22 100644 (file)
@@ -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.  */
index 6b4d76c2ec1d8bb8e05c2a4098494092280b607a..42861685b11cab9cda6fb2bbd83d612d69666cb6 100644 (file)
@@ -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);
@@ -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;
index 6c60fc4a9f7aed7e50347c243cde1e41877bcc64..18696d09e521dcb027ec933b1181213e654dd599 100644 (file)
@@ -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 (file)
index 0000000..d312039
--- /dev/null
@@ -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