2018-03-16 Jason Merrill <jason@redhat.com>
+ PR c++/84906 - silent wrong code with ambiguous conversion.
+ * call.c (build_user_type_conversion_1): Set need_temporary_p on
+ ambiguous conversion.
+ (convert_like_real): Check it.
+
PR c++/83937 - wrong C++17 handling of init-list ctor argument.
* call.c (build_special_member_call): Don't convert an init-list
argument directly to the class type.
BOOL_BITFIELD bad_p : 1;
/* If KIND is ck_ref_bind ck_base_conv, true to indicate that a
temporary should be created to hold the result of the
- conversion. */
+ conversion. If KIND is ck_ambig, true if the context is
+ copy-initialization. */
BOOL_BITFIELD need_temporary_p : 1;
/* If KIND is ck_ptr or ck_pmem, true to indicate that a conversion
from a pointer-to-derived to pointer-to-base is being performed. */
cand->second_conv->user_conv_p = true;
if (!any_strictly_viable (candidates))
cand->second_conv->bad_p = true;
+ if (flags & LOOKUP_ONLYCONVERTING)
+ cand->second_conv->need_temporary_p = true;
/* If there are viable candidates, don't set ICS_BAD_FLAG; an
ambiguous conversion is no worse than another user-defined
conversion. */
if (complain & tf_error)
{
/* Call build_user_type_conversion again for the error. */
- build_user_type_conversion (totype, convs->u.expr, LOOKUP_IMPLICIT,
- complain);
+ int flags = (convs->need_temporary_p
+ ? LOOKUP_IMPLICIT : LOOKUP_NORMAL);
+ build_user_type_conversion (totype, convs->u.expr, flags, complain);
+ gcc_assert (seen_error ());
if (fn)
inform (DECL_SOURCE_LOCATION (fn),
" initializing argument %P of %qD", argnum, fn);