Commit 48884537 by Nathan Sidwell Committed by Nathan Sidwell

re PR c++/23513 (overload resolution fails to select a more specialized template)

cp:
	PR c++/23513
	* call.c (joust): Adjust length count to more_specialized_fn.
	* pt.c (more_specialized_fn): Cope with non-static member vs
	non-member.
testsuite:
	PR c++/23513
	* g++.dg/template/spec22.C: Robustify test.
	* g++.dg/template/spec26.C: New.

From-SVN: r104981
parent 410e268c
2005-10-05 Nathan Sidwell <nathan@codesourcery.com>
PR c++/23513
* call.c (joust): Adjust length count to more_specialized_fn.
* pt.c (more_specialized_fn): Cope with non-static member vs
non-member.
2005-10-04 Andrew Pinski <pinskia@physics.uc.edu> 2005-10-04 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/23125 PR middle-end/23125
......
...@@ -6133,17 +6133,11 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn) ...@@ -6133,17 +6133,11 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
winner = more_specialized_fn winner = more_specialized_fn
(TI_TEMPLATE (cand1->template_decl), (TI_TEMPLATE (cand1->template_decl),
TI_TEMPLATE (cand2->template_decl), TI_TEMPLATE (cand2->template_decl),
/* Tell the deduction code how many real function arguments /* [temp.func.order]: The presence of unused ellipsis and default
we saw, not counting the implicit 'this' argument. But,
add_function_candidate() suppresses the "this" argument
for constructors.
[temp.func.order]: The presence of unused ellipsis and default
arguments has no effect on the partial ordering of function arguments has no effect on the partial ordering of function
templates. */ templates. add_function_candidate() will not have
cand1->num_convs counted the "this" argument for constructors. */
- (DECL_NONSTATIC_MEMBER_FUNCTION_P (cand1->fn) cand1->num_convs + DECL_CONSTRUCTOR_P (cand1->fn));
- DECL_CONSTRUCTOR_P (cand1->fn)));
if (winner) if (winner)
return winner; return winner;
} }
......
...@@ -10491,17 +10491,30 @@ more_specialized_fn (tree pat1, tree pat2, int len) ...@@ -10491,17 +10491,30 @@ more_specialized_fn (tree pat1, tree pat2, int len)
tree args2 = TYPE_ARG_TYPES (TREE_TYPE (decl2)); tree args2 = TYPE_ARG_TYPES (TREE_TYPE (decl2));
int better1 = 0; int better1 = 0;
int better2 = 0; int better2 = 0;
/* If only one is a member function, they are unordered. */ /* Remove the this parameter from non-static member functions. If
if (DECL_FUNCTION_MEMBER_P (decl1) != DECL_FUNCTION_MEMBER_P (decl2)) one is a non-static member function and the other is not a static
return 0; member function, remove the first parameter from that function
also. This situation occurs for operator functions where we
/* Don't consider 'this' parameter. */ locate both a member function (with this pointer) and non-member
operator (with explicit first operand). */
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1)) if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl1))
args1 = TREE_CHAIN (args1); {
if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2)) len--; /* LEN is the number of significant arguments for DECL1 */
args2 = TREE_CHAIN (args2); args1 = TREE_CHAIN (args1);
if (!DECL_STATIC_FUNCTION_P (decl2))
args2 = TREE_CHAIN (args2);
}
else if (DECL_NONSTATIC_MEMBER_FUNCTION_P (decl2))
{
args2 = TREE_CHAIN (args2);
if (!DECL_STATIC_FUNCTION_P (decl1))
{
len--;
args1 = TREE_CHAIN (args1);
}
}
/* If only one is a conversion operator, they are unordered. */ /* If only one is a conversion operator, they are unordered. */
if (DECL_CONV_FN_P (decl1) != DECL_CONV_FN_P (decl2)) if (DECL_CONV_FN_P (decl1) != DECL_CONV_FN_P (decl2))
return 0; return 0;
......
2005-10-05 Nathan Sidwell <nathan@codesourcery.com>
PR c++/23513
* g++.dg/template/spec22.C: Robustify test.
* g++.dg/template/spec26.C: New.
2005-10-05 Uros Bizjak <uros@kss-loka.si> 2005-10-05 Uros Bizjak <uros@kss-loka.si>
* gcc.dg/vect/vect-shift-1.c: Include tree-vect.h header. Check * gcc.dg/vect/vect-shift-1.c: Include tree-vect.h header. Check
...@@ -5,18 +5,17 @@ ...@@ -5,18 +5,17 @@
// Origin: Andrew Pinski <pinskia@gcc.gnu.org> // Origin: Andrew Pinski <pinskia@gcc.gnu.org>
// Nathan Sidwell <nathan@gcc.gnu.org> // Nathan Sidwell <nathan@gcc.gnu.org>
template <typename T> template <typename T> class srp;
int operator+ (T const &, int); // { dg-error "T = Foo" "" } template <typename T> struct ptr
struct Foo
{ {
template <typename T> template <typename U> ptr(const srp<U> &other); // { dg-error "ptr<T>::ptr" }
int operator+ (T) const; // { dg-error "T = int" "" }
}; };
template <typename T> struct srp
int main ()
{ {
Foo f; template <typename U> operator ptr<U>(void) const; // { dg-error "srp<T>::operator" }
};
return f + 0; // { dg-error "ambiguous overload" "" } ptr<int> parent_get()
{
srp<int> parent;
return parent; // { dg-error "is ambiguous" }
} }
// dg-do run
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 16 Sep 2005 <nathan@codesourcery.com>
// PR 23519 template specialization ordering (DR214)
// Origin: Maxim Yegorushkin <maxim.yegorushkin@gmail.com>
struct A
{
template<class T> int operator+(T&) { return 1;}
};
template<class T> struct B
{
int operator-(A&) {return 2;}
template<typename R> int operator*(R&) {return 3;}
};
template <typename T, typename R> int operator-(B<T>, R&) {return 4;}
template<class T> int operator+(A&, B<T>&) { return 5;}
template <typename T> int operator*(T &, A&){return 6;}
int main()
{
A a;
B<A> b;
if ((a + b) != 5)
return 1;
if ((b - a) != 2)
return 2;
if ((b * a) != 6)
return 3;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment