This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to joust
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Subject: C++ PATCH to joust
- From: Jason Merrill <jason_merrill at redhat dot com>
- Date: 25 Jul 2001 15:05:30 +0100
We were mistakenly discarding a builtin candidate that was no better or
worse than a non-builtin, but did not have the same signature either. See
g++.dg/overload/builtin1.C.
2001-07-25 Jason Merrill <jason_merrill@redhat.com>
* call.c (joust): Only prefer a non-builtin candidate to a builtin
one if they have the same signature.
*** call.c.~1~ Wed Jul 25 02:18:30 2001
--- call.c Tue Jul 24 15:52:15 2001
*************** joust (cand1, cand2, warn)
*** 5350,5371 ****
return winner;
}
- /* a non-template user function is better than a builtin. (Pedantically
- the builtin which matched the user function should not be added to
- the overload set, but we spot it here.
-
- [over.match.oper]
- ... the builtin candidates include ...
- - do not have the same parameter type list as any non-template
- non-member candidate. */
-
- if (TREE_CODE (cand1->fn) != IDENTIFIER_NODE
- && TREE_CODE (cand2->fn) == IDENTIFIER_NODE)
- return 1;
- else if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE
- && TREE_CODE (cand2->fn) != IDENTIFIER_NODE)
- return -1;
-
/* or, if not that,
the context is an initialization by user-defined conversion (see
_dcl.init_ and _over.match.user_) and the standard conversion
--- 5350,5355 ----
*************** joust (cand1, cand2, warn)
*** 5381,5401 ****
return winner;
}
! /* If the built-in candidates are the same, arbitrarily pick one. */
! if (cand1->fn == cand2->fn
! && TREE_CODE (cand1->fn) == IDENTIFIER_NODE)
{
for (i = 0; i < len; ++i)
if (!same_type_p (TREE_TYPE (TREE_VEC_ELT (cand1->convs, i)),
TREE_TYPE (TREE_VEC_ELT (cand2->convs, i))))
break;
if (i == TREE_VEC_LENGTH (cand1->convs))
! return 1;
/* Kludge around broken overloading rules whereby
Integer a, b; test ? a : b; is ambiguous, since there's a builtin
that takes references and another that takes values. */
! if (cand1->fn == ansi_opname (COND_EXPR))
{
tree c1 = TREE_VEC_ELT (cand1->convs, 1);
tree c2 = TREE_VEC_ELT (cand2->convs, 1);
--- 5365,5406 ----
return winner;
}
! /* Check whether we can discard a builtin candidate, either because we
! have two identical ones or matching builtin and non-builtin candidates.
!
! (Pedantically in the latter case the builtin which matched the user
! function should not be added to the overload set, but we spot it here.
!
! [over.match.oper]
! ... the builtin candidates include ...
! - do not have the same parameter type list as any non-template
! non-member candidate. */
!
! if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE
! || TREE_CODE (cand2->fn) == IDENTIFIER_NODE)
{
for (i = 0; i < len; ++i)
if (!same_type_p (TREE_TYPE (TREE_VEC_ELT (cand1->convs, i)),
TREE_TYPE (TREE_VEC_ELT (cand2->convs, i))))
break;
if (i == TREE_VEC_LENGTH (cand1->convs))
! {
! if (cand1->fn == cand2->fn)
! /* Two built-in candidates; arbitrarily pick one. */
! return 1;
! else if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE)
! /* cand1 is built-in; prefer cand2. */
! return -1;
! else
! /* cand2 is built-in; prefer cand1. */
! return 1;
! }
/* Kludge around broken overloading rules whereby
Integer a, b; test ? a : b; is ambiguous, since there's a builtin
that takes references and another that takes values. */
! if (cand1->fn == cand2->fn
! && cand1->fn == ansi_opname (COND_EXPR))
{
tree c1 = TREE_VEC_ELT (cand1->convs, 1);
tree c2 = TREE_VEC_ELT (cand2->convs, 1);