tree type = TREE_TYPE (tmpl);
bool try_list_ctor = false;
+ bool list_init_p = false;
releasing_vec rv_args = NULL;
vec<tree,va_gc> *&args = *&rv_args;
args = make_tree_vector ();
else if (BRACE_ENCLOSED_INITIALIZER_P (init))
{
+ list_init_p = true;
try_list_ctor = TYPE_HAS_LIST_CTOR (type);
if (try_list_ctor && CONSTRUCTOR_NELTS (init) == 1)
{
if (cands == error_mark_node)
return error_mark_node;
- /* Prune explicit deduction guides in copy-initialization context. */
+ /* Prune explicit deduction guides in copy-initialization context (but
+ not copy-list-initialization). */
bool elided = false;
- if (flags & LOOKUP_ONLYCONVERTING)
+ if (!list_init_p && (flags & LOOKUP_ONLYCONVERTING))
{
for (lkp_iterator iter (cands); !elided && iter; ++iter)
if (DECL_NONCONVERTING_P (STRIP_TEMPLATE (*iter)))
--cp_unevaluated_operand;
}
- if (call == error_mark_node
- && (complain & tf_warning_or_error))
+ if (call == error_mark_node)
{
- error ("class template argument deduction failed:");
+ if (complain & tf_warning_or_error)
+ {
+ error ("class template argument deduction failed:");
- ++cp_unevaluated_operand;
- call = build_new_function_call (cands, &args, complain | tf_decltype);
- --cp_unevaluated_operand;
+ ++cp_unevaluated_operand;
+ call = build_new_function_call (cands, &args,
+ complain | tf_decltype);
+ --cp_unevaluated_operand;
- if (elided)
- inform (input_location, "explicit deduction guides not considered "
- "for copy-initialization");
+ if (elided)
+ inform (input_location, "explicit deduction guides not considered "
+ "for copy-initialization");
+ }
+ return error_mark_node;
+ }
+ /* [over.match.list]/1: In copy-list-initialization, if an explicit
+ constructor is chosen, the initialization is ill-formed. */
+ else if (flags & LOOKUP_ONLYCONVERTING)
+ {
+ tree fndecl = cp_get_callee_fndecl_nofold (call);
+ if (fndecl && DECL_NONCONVERTING_P (fndecl))
+ {
+ if (complain & tf_warning_or_error)
+ {
+ // TODO: Pass down location from cp_finish_decl.
+ error ("class template argument deduction for %qT failed: "
+ "explicit deduction guide selected in "
+ "copy-list-initialization", type);
+ inform (DECL_SOURCE_LOCATION (fndecl),
+ "explicit deduction guide declared here");
+
+ }
+ return error_mark_node;
+ }
}
/* If CTAD succeeded but the type doesn't have any explicit deduction
--- /dev/null
+// PR c++/90210
+// { dg-do compile { target c++17 } }
+
+template<typename T> struct tuple { tuple(T); };
+template<typename T> explicit tuple(T t) -> tuple<T>;
+tuple t = { 1 }; // { dg-error "explicit deduction guide selected" }
+tuple t1 = tuple{ 1 };
+tuple t2{ 1 };
+
+template<typename T> struct A { A(T, T); };
+template<typename T> explicit A(T, T) -> A<int>;
+A a = {1, 1}; // { dg-error "explicit deduction guide selected" }
+A a1 = A{1, 1};
+A a2{1, 1};
+
+template<typename T, typename U>
+struct B {
+ B(T, U);
+};
+template<typename T, typename U>
+B(T, U) -> B<T, typename U::type>; // SFINAEd-out
+B b = { 1, 2 }; // OK
+B b1 = B{ 1, 2 }; // OK
+B b2{ 1, 2 }; // OK
+
+// Overriden implicit default constructor deduction guide:
+template<typename T>
+struct C { };
+explicit C() -> C<int>;
+C c = {}; // { dg-error "explicit deduction guide selected" }
+C c1 = C{};
+C c2{};
+
+// Overriden copy guide:
+template<typename T>
+struct D { };
+template<typename T> explicit D(D<T>) -> D<T>;
+D<int> d;
+D d1 = {d}; // { dg-error "explicit deduction guide selected" }
+D d2 = D{d};
+D d3{d};