aboutsummaryrefslogtreecommitdiff
path: root/gcc/objc
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-12-30 22:02:09 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-12-30 22:02:09 +0000
commit27e09ff9fc87bbf27ffe0b169f5941d528309a25 (patch)
tree2b68cee452716cd6590c101e2bf623f31cc5738c /gcc/objc
parent8abf21313f8b26d07bc6772348096360df984e26 (diff)
downloadgcc-27e09ff9fc87bbf27ffe0b169f5941d528309a25.zip
gcc-27e09ff9fc87bbf27ffe0b169f5941d528309a25.tar.gz
gcc-27e09ff9fc87bbf27ffe0b169f5941d528309a25.tar.bz2
In gcc/objc/: 2010-12-30 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/objc/: 2010-12-30 Nicola Pero <nicola.pero@meta-innovation.com> * objc-act.c (objc_types_are_equivalent): Fixed comparing protocol lists. Check them two-ways to fix comparisons when one protocol implements the other one, or when one list contains duplicated protocols. In gcc/testsuite/: 2010-12-30 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/method-conflict-3.m: New. * objc.dg/method-conflict-4.m: New. * obj-c++.dg/method-conflict-3.m: New. * obj-c++.dg/method-conflict-4.mm: New. From-SVN: r168356
Diffstat (limited to 'gcc/objc')
-rw-r--r--gcc/objc/ChangeLog7
-rw-r--r--gcc/objc/objc-act.c34
2 files changed, 34 insertions, 7 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog
index 43ef65d..3edb54e 100644
--- a/gcc/objc/ChangeLog
+++ b/gcc/objc/ChangeLog
@@ -1,5 +1,12 @@
2010-12-30 Nicola Pero <nicola.pero@meta-innovation.com>
+ * objc-act.c (objc_types_are_equivalent): Fixed comparing protocol
+ lists. Check them two-ways to fix comparisons when one protocol
+ implements the other one, or when one list contains duplicated
+ protocols.
+
+2010-12-30 Nicola Pero <nicola.pero@meta-innovation.com>
+
* objc-act.c (objc_add_method): When emitting an error because a
method with the same name but conflicting types is found in the
same class or category interface, print a note with the location
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index ec7fea5..a37f3d9 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -11925,9 +11925,8 @@ start_method_def (tree method)
really_start_method (objc_method_context, parm_info);
}
-/* Return 1 if TYPE1 is equivalent to TYPE2
- for purposes of method overloading. */
-
+/* Return 1 if TYPE1 is equivalent to TYPE2 for purposes of method
+ overloading. */
static int
objc_types_are_equivalent (tree type1, tree type2)
{
@@ -11941,6 +11940,7 @@ objc_types_are_equivalent (tree type1, tree type2)
if (TYPE_MAIN_VARIANT (type1) != TYPE_MAIN_VARIANT (type2))
return 0;
+ /* Compare the protocol lists. */
type1 = (TYPE_HAS_OBJC_INFO (type1)
? TYPE_OBJC_PROTOCOL_LIST (type1)
: NULL_TREE);
@@ -11948,14 +11948,34 @@ objc_types_are_equivalent (tree type1, tree type2)
? TYPE_OBJC_PROTOCOL_LIST (type2)
: NULL_TREE);
- if (list_length (type1) == list_length (type2))
+ /* If there are no protocols (most common case), the types are
+ identical. */
+ if (type1 == NULL_TREE && type2 == NULL_TREE)
+ return 1;
+
+ /* If one has protocols, and the other one hasn't, they are not
+ identical. */
+ if ((type1 == NULL_TREE && type2 != NULL_TREE)
+ || (type1 != NULL_TREE && type2 == NULL_TREE))
+ return 0;
+ else
{
- for (; type2; type2 = TREE_CHAIN (type2))
- if (!lookup_protocol_in_reflist (type1, TREE_VALUE (type2)))
+ /* Else, both have protocols, and we need to do the full
+ comparison. It is possible that either type1 or type2
+ contain some duplicate protocols in the list, so we can't
+ even just compare list_length as a first check. */
+ tree t;
+
+ for (t = type2; t; t = TREE_CHAIN (t))
+ if (!lookup_protocol_in_reflist (type1, TREE_VALUE (t)))
+ return 0;
+
+ for (t = type1; t; t = TREE_CHAIN (t))
+ if (!lookup_protocol_in_reflist (type2, TREE_VALUE (t)))
return 0;
+
return 1;
}
- return 0;
}
/* Return 1 if TYPE1 has the same size and alignment as TYPE2. */