Commit f8986275 by Nathan Sidwell Committed by Nathan Sidwell

re PR c++/10337 ("ambiguous overload"-error for non-ambiguous situation)

cp:
	PR c++/10337
	* call.c (joust): Don't warn about conversion ops that are exact
	or cv-conversions. Rearrange to avoid multiple type comparisons.
testsuite:
	PR c++/10337
	* g++.dg/warn/conv1.C: New test.
	* g++.old-deja/g++.other/conv7.C: Adjust.
	* g++.old-deja/g++.other/overload14.C: Adjust.

From-SVN: r66038
parent 26f74aa3
2003-04-24 Nathan Sidwell <nathan@codesourcery.com>
PR c++/10337
* call.c (joust): Don't warn about conversion ops that are exact
or cv-conversions. Rearrange to avoid multiple type comparisons.
2003-04-23 Mark Mitchell <mark@codesourcery.com> 2003-04-23 Mark Mitchell <mark@codesourcery.com>
PR c++/10471 PR c++/10471
......
...@@ -5757,31 +5757,39 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn) ...@@ -5757,31 +5757,39 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
either between a constructor and a conversion op, or between two either between a constructor and a conversion op, or between two
conversion ops. */ conversion ops. */
if (winner && cand1->second_conv if (winner && cand1->second_conv
&& ((DECL_CONSTRUCTOR_P (cand1->fn) && (!DECL_CONSTRUCTOR_P (cand1->fn) || !DECL_CONSTRUCTOR_P (cand2->fn))
!= DECL_CONSTRUCTOR_P (cand2->fn)) && winner != compare_ics (cand1->second_conv, cand2->second_conv))
/* Don't warn if the two conv ops convert to the same type... */
|| (! DECL_CONSTRUCTOR_P (cand1->fn)
&& ! same_type_p (TREE_TYPE (TREE_TYPE (cand1->fn)),
TREE_TYPE (TREE_TYPE (cand2->fn))))))
{
int comp = compare_ics (cand1->second_conv, cand2->second_conv);
if (comp != winner)
{ {
struct z_candidate *w, *l; struct z_candidate *w, *l;
tree convn; bool give_warning = false;
if (winner == 1) if (winner == 1)
w = cand1, l = cand2; w = cand1, l = cand2;
else else
w = cand2, l = cand1; w = cand2, l = cand1;
if (DECL_CONTEXT (cand1->fn) == DECL_CONTEXT (cand2->fn)
&& ! DECL_CONSTRUCTOR_P (cand1->fn) /* We don't want to complain about `X::operator T1 ()'
&& ! DECL_CONSTRUCTOR_P (cand2->fn) beating `X::operator T2 () const', when T2 is a no less
&& (convn = standard_conversion cv-qualified version of T1. */
(TREE_TYPE (TREE_TYPE (l->fn)), if (DECL_CONTEXT (w->fn) == DECL_CONTEXT (l->fn)
TREE_TYPE (TREE_TYPE (w->fn)), NULL_TREE)) && !DECL_CONSTRUCTOR_P (w->fn) && !DECL_CONSTRUCTOR_P (l->fn))
&& TREE_CODE (convn) == QUAL_CONV) {
/* Don't complain about `operator char *()' beating tree t = TREE_TYPE (TREE_TYPE (l->fn));
`operator const char *() const'. */; tree f = TREE_TYPE (TREE_TYPE (w->fn));
if (TREE_CODE (t) == TREE_CODE (f) && POINTER_TYPE_P (t))
{
t = TREE_TYPE (t);
f = TREE_TYPE (f);
}
if (!comp_ptr_ttypes (t, f))
give_warning = true;
}
else
give_warning = true;
if (!give_warning)
/*NOP*/;
else if (warn) else if (warn)
{ {
tree source = source_type (TREE_VEC_ELT (w->convs, 0)); tree source = source_type (TREE_VEC_ELT (w->convs, 0));
...@@ -5795,7 +5803,6 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn) ...@@ -5795,7 +5803,6 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn)
else else
add_warning (w, l); add_warning (w, l);
} }
}
if (winner) if (winner)
return winner; return winner;
......
2003-04-24 Nathan Sidwell <nathan@codesourcery.com>
PR c++/10337
* g++.dg/warn/conv1.C: New test.
* g++.old-deja/g++.other/conv7.C: Adjust.
* g++.old-deja/g++.other/overload14.C: Adjust.
2003-04-23 Mark Mitchell <mark@codesourcery.com> 2003-04-23 Mark Mitchell <mark@codesourcery.com>
PR c++/10471 PR c++/10471
......
// { dg-do compile }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 20 Apr 2003 <nathan@codesourcery.com>
// PR 10337, unneeded warning
class A {
public:
A() {}
};
class B : public A {
public:
B() {}
void operator=(const A& b) {}
void operator=(const B& b) {}
};
class C {
public:
C() {}
operator B &() { return _b; }
operator const B &() const { return _b; }
B _b;
};
int main() {
B b;
C c;
b = c;
}
...@@ -40,6 +40,6 @@ yyparse() ...@@ -40,6 +40,6 @@ yyparse()
{ {
iterator_template<IdlDeclarator_bar,IdlDeclarator_bar&,foo*,foo*> declIter; iterator_template<IdlDeclarator_bar,IdlDeclarator_bar&,foo*,foo*> declIter;
const IdlDeclarator& declarator = *declIter; // WARNING - choosing const IdlDeclarator& declarator = *declIter;
return 1; return 1;
} }
...@@ -26,6 +26,6 @@ A::operator A::B () ...@@ -26,6 +26,6 @@ A::operator A::B ()
int main () int main ()
{ {
(A::C) A (); // WARNING - (A::C) A ();
return 0; return 0;
} }
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