Commit 5f901ccf by Jason Merrill Committed by Jason Merrill

re PR c++/32019 (Conditional operator ?: and ambiguous convertions)

	PR c++/32019
	* call.c (build_conditional_expr_1): Improve ambiguity diagnostic.

	PR c++/54348
	* call.c (build_conditional_expr_1): If overload resolution finds
	no match, just say "different types".

From-SVN: r210282
parent bb8b1f69
2014-05-09 Jason Merrill <jason@redhat.com> 2014-05-09 Jason Merrill <jason@redhat.com>
PR c++/54348
* call.c (build_conditional_expr_1): If overload resolution finds
no match, just say "different types".
PR c++/32019
* call.c (build_conditional_expr_1): Improve ambiguity diagnostic.
PR c++/22434 PR c++/22434
* call.c (build_conditional_expr_1): Don't try to pool cv-quals * call.c (build_conditional_expr_1): Don't try to pool cv-quals
if we didn't find a conversion. if we didn't find a conversion.
......
...@@ -4710,8 +4710,16 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, ...@@ -4710,8 +4710,16 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
|| (conv3 && conv3->kind == ck_ambig)) || (conv3 && conv3->kind == ck_ambig))
{ {
if (complain & tf_error) if (complain & tf_error)
error_at (loc, "operands to ?: have different types %qT and %qT", {
arg2_type, arg3_type); error_at (loc, "operands to ?: have different types %qT and %qT",
arg2_type, arg3_type);
if (conv2 && !conv2->bad_p && conv3 && !conv3->bad_p)
inform (loc, " and each type can be converted to the other");
else if (conv2 && conv2->kind == ck_ambig)
convert_like (conv2, arg2, complain);
else
convert_like (conv3, arg3, complain);
}
result = error_mark_node; result = error_mark_node;
} }
else if (conv2 && !conv2->bad_p) else if (conv2 && !conv2->bad_p)
...@@ -4818,10 +4826,8 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, ...@@ -4818,10 +4826,8 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
if (!any_viable_p) if (!any_viable_p)
{ {
if (complain & tf_error) if (complain & tf_error)
{ error_at (loc, "operands to ?: have different types %qT and %qT",
op_error (loc, COND_EXPR, NOP_EXPR, arg1, arg2, arg3, FALSE); arg2_type, arg3_type);
print_z_candidates (loc, candidates);
}
return error_mark_node; return error_mark_node;
} }
cand = tourney (candidates, complain); cand = tourney (candidates, complain);
......
...@@ -45,6 +45,6 @@ int main() ...@@ -45,6 +45,6 @@ int main()
f(a); // { dg-error "" } f(a); // { dg-error "" }
B b2 = { a }; // { dg-error "" } B b2 = { a }; // { dg-error "" }
a + true; // { dg-error "5:no match" } a + true; // { dg-error "5:no match" }
b ? a : true; // { dg-error "5:no match" } b ? a : true; // { dg-error "5:?:" }
a ? a : true; // { dg-error "5:no match" } a ? a : true; // { dg-error "5:?:" }
} }
// PR c++/32019
struct C
{
C(const char *);
operator const char *();
};
extern C c;
extern const char * s;
void
foo (bool b)
{
b ? c : s; // { dg-error "?:" }
// { dg-message "convert" "" { target *-*-* } 15 }
}
struct A;
struct C
{
operator A();
};
struct A
{
A(C);
};
extern A a;
extern C c;
void
foo (bool b)
{
b ? c : a; // { dg-error "?:" }
// { dg-message "ambiguous" "" { target *-*-* } 18 }
}
// PR c++/54348
struct A {} a;
struct B {} b;
void f()
{
false ? a : b; // { dg-error "different types" }
}
...@@ -5,4 +5,4 @@ struct A ...@@ -5,4 +5,4 @@ struct A
A(int)(); // { dg-error "declared" } A(int)(); // { dg-error "declared" }
}; };
template<int> void foo(bool b, A a) { b ? a : 0; } // { dg-error "no match" } template<int> void foo(bool b, A a) { b ? a : 0; } // { dg-error "?:" }
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