functions. */
static void
-print_error_for_call_failure (tree fn, vec<tree, va_gc> *args,
+print_error_for_call_failure (tree fn, const vec<tree, va_gc> *args,
struct z_candidate *candidates)
{
tree targs = NULL_TREE;
print_z_candidates (loc, candidates);
}
+/* Perform overload resolution on the set of deduction guides DGUIDES
+ using ARGS. Returns the selected deduction guide, or error_mark_node
+ if overload resolution fails. */
+
+tree
+perform_dguide_overload_resolution (tree dguides, const vec<tree, va_gc> *args,
+ tsubst_flags_t complain)
+{
+ z_candidate *candidates;
+ bool any_viable_p;
+ tree result;
+
+ gcc_assert (deduction_guide_p (OVL_FIRST (dguides)));
+
+ /* Get the high-water mark for the CONVERSION_OBSTACK. */
+ void *p = conversion_obstack_alloc (0);
+
+ z_candidate *cand = perform_overload_resolution (dguides, args, &candidates,
+ &any_viable_p, complain);
+ if (!cand)
+ {
+ if (complain & tf_error)
+ print_error_for_call_failure (dguides, args, candidates);
+ result = error_mark_node;
+ }
+ else
+ result = cand->fn;
+
+ /* Free all the conversions we allocated. */
+ obstack_free (&conversion_obstack, p);
+
+ return result;
+}
+
/* Return an expression for a call to FN (a namespace-scope function,
or a static member function) with the ARGS. This may change
ARGS. */
tree from_type, tree to_type,
tree fndecl, int parmnum);
extern void maybe_inform_about_fndecl_for_bogus_argument_init (tree, int);
+extern tree perform_dguide_overload_resolution (tree, const vec<tree, va_gc> *,
+ tsubst_flags_t);
/* A class for recording information about access failures (e.g. private
if (tree guide = maybe_aggr_guide (tmpl, init, args))
cands = lookup_add (guide, cands);
- tree call = error_mark_node;
+ tree fndecl = error_mark_node;
/* If this is list-initialization and the class has a list constructor, first
try deducing from the list as a single argument, as [over.match.list]. */
}
if (list_cands)
{
- ++cp_unevaluated_operand;
- call = build_new_function_call (list_cands, &args, tf_decltype);
- --cp_unevaluated_operand;
+ fndecl = perform_dguide_overload_resolution (list_cands, args, tf_none);
- if (call == error_mark_node)
+ if (fndecl == error_mark_node)
{
/* That didn't work, now try treating the list as a sequence of
arguments. */
"user-declared constructors", type);
return error_mark_node;
}
- else if (!cands && call == error_mark_node)
+ else if (!cands && fndecl == error_mark_node)
{
error ("cannot deduce template arguments of %qT, as it has no viable "
"deduction guides", type);
return error_mark_node;
}
- if (call == error_mark_node)
- {
- ++cp_unevaluated_operand;
- call = build_new_function_call (cands, &args, tf_decltype);
- --cp_unevaluated_operand;
- }
+ if (fndecl == error_mark_node)
+ fndecl = perform_dguide_overload_resolution (cands, args, tf_none);
- if (call == error_mark_node)
+ if (fndecl == error_mark_node)
{
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;
-
+ perform_dguide_overload_resolution (cands, args, complain);
if (elided)
inform (input_location, "explicit deduction guides not considered "
"for copy-initialization");
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 (DECL_NONCONVERTING_P (fndecl))
{
if (complain & tf_warning_or_error)
{
/* If CTAD succeeded but the type doesn't have any explicit deduction
guides, this deduction might not be what the user intended. */
- if (call != error_mark_node && !any_dguides_p)
+ if (fndecl != error_mark_node && !any_dguides_p)
{
- tree fndecl = cp_get_callee_fndecl_nofold (call);
- if (fndecl != NULL_TREE
- && (!DECL_IN_SYSTEM_HEADER (fndecl)
- || global_dc->dc_warn_system_headers)
+ if ((!DECL_IN_SYSTEM_HEADER (fndecl)
+ || global_dc->dc_warn_system_headers)
&& warning (OPT_Wctad_maybe_unsupported,
"%qT may not intend to support class template argument "
"deduction", type))
"warning");
}
- return cp_build_qualified_type (TREE_TYPE (call), cp_type_quals (ptype));
+ return cp_build_qualified_type (TREE_TYPE (TREE_TYPE (fndecl)),
+ cp_type_quals (ptype));
}
/* Replace occurrences of 'auto' in TYPE with the appropriate type deduced
--- /dev/null
+// PR c++/86439
+// { dg-do compile { target c++17 } }
+
+struct NC {
+ NC() = default;
+ NC(NC const&) = delete;
+ NC& operator=(NC const&) = delete;
+};
+
+template <int>
+struct C {
+ C(NC const&);
+};
+
+C(NC) -> C<0>;
+
+NC nc;
+C c(nc);
--- /dev/null
+// PR c++/86439
+// { dg-do compile { target c++17 } }
+
+struct B { };
+struct C { };
+
+template<class T>
+struct A {
+ A(T, B);
+};
+
+template<class T>
+A(T, C) -> A<T>;
+
+A a(0, {});
--- /dev/null
+// PR c++/86439
+// { dg-do compile { target c++17 } }
+
+struct less { };
+struct allocator { };
+
+template<class T, class U = less, class V = allocator>
+struct A {
+ A(T, U);
+ A(T, V);
+};
+
+template<class T, class U = less>
+A(T, U) -> A<T>;
+
+A a(0, {}); // { dg-error "ambiguous" }
*/
static_assert(std::is_same_v<
- decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, {}}),
+ decltype(std::map{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}}, std::less<int>{}}),
std::map<int, double>>);
/* This is not deducible, ambiguous candidates:
static_assert(std::is_same_v<
decltype(std::map(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::map<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::map(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::map<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::map(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::map<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::multimap{{std::pair{1, 2.0}, {2, 3.0}, {3, 4.0}},
- {}}),
+ std::less<int>{}}),
std::multimap<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::multimap(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::multimap<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::multimap(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::multimap<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::multimap(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::multimap<int, double>>);
static_assert(std::is_same_v<
decltype(std::multiset{{1, 2, 3}, std::less<int>{}, {}}),
std::multiset<int>>);
+/* FIXME: GCC 12 rejects this due to PR c++/101174
static_assert(std::is_same_v<
- decltype(std::multiset{{1, 2, 3}, {}}),
+ decltype(std::multiset{{1, 2, 3}, std::less<int>{}}),
std::multiset<int>>);
+*/
static_assert(std::is_same_v<
decltype(std::multiset{{1, 2, 3}, SimpleAllocator<int>{}}),
static_assert(std::is_same_v<
decltype(std::multiset(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::multiset<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::multiset(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::multiset<int>>);
static_assert(std::is_same_v<
std::less<int>{}, {}}),
std::set<int>>);
+/* FIXME: GCC 12 rejects this due to PR c++/101174
static_assert(std::is_same_v<
decltype(std::set{{1, 2, 3},
- {}}),
+ std::less<int>{}}),
std::set<int>>);
+*/
static_assert(std::is_same_v<
decltype(std::set{{1, 2, 3},
static_assert(std::is_same_v<
decltype(std::set(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::set<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::set(x.begin(), x.end(),
- {})),
+ std::less<int>{})),
std::set<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_map{{std::pair{1, 2.0},
{2, 3.0}, {3, 4.0}},
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_map<int, double>>);
+
+static_assert(std::is_same_v<
+ decltype(std::unordered_map{{std::pair{1, 2.0},
+ {2, 3.0}, {3, 4.0}},
+ {}, std::hash<int>{}, std::allocator<std::pair<const int, double>>{}}),
std::unordered_map<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_map{x.begin(), x.end(),
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
std::unordered_map<int, double>>);
-
+
+ static_assert(std::is_same_v<
+ decltype(std::unordered_map{x.begin(), x.end(),
+ {}, std::hash<int>{}, std::allocator<std::pair<const int, double>>{}}),
+ std::unordered_map<int, double>>);
+
static_assert(std::is_same_v<
decltype(std::unordered_map(x.begin(), x.end(),
{})),
static_assert(std::is_same_v<
decltype(std::unordered_multimap{{std::pair{1, 2.0},
{2, 3.0}, {3, 4.0}},
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_multimap<int, double>>);
+
+static_assert(std::is_same_v<
+ decltype(std::unordered_multimap{{std::pair{1, 2.0},
+ {2, 3.0}, {3, 4.0}},
+ {}, std::hash<int>{}, std::allocator<std::pair<const int, double>>{}}),
std::unordered_multimap<int, double>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_multimap{x.begin(), x.end(),
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
std::unordered_multimap<int, double>>);
-
+
+ static_assert(std::is_same_v<
+ decltype(std::unordered_multimap{x.begin(), x.end(),
+ {}, std::hash<int>{}, std::allocator<std::pair<const int, double>>{}}),
+ std::unordered_multimap<int, double>>);
+
static_assert(std::is_same_v<
decltype(std::unordered_multimap(x.begin(), x.end(),
{})),
static_assert(std::is_same_v<
decltype(std::unordered_multiset{{1, 2, 3},
- 0, std::hash<int>{}, {}}),
+ 0, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_multiset<int>>);
+
+static_assert(std::is_same_v<
+ decltype(std::unordered_multiset{{1, 2, 3},
+ 0, std::hash<int>{}, std::allocator<int>{}}),
std::unordered_multiset<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_multiset{x.begin(), x.end(),
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_multiset<int>>);
+
+ static_assert(std::is_same_v<
+ decltype(std::unordered_multiset{x.begin(), x.end(),
+ {}, std::hash<int>{}, std::allocator<int>{}}),
std::unordered_multiset<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_set{{1, 2, 3},
- 0, std::hash<int>{}, {}}),
+ 0, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_set<int>>);
+
+static_assert(std::is_same_v<
+ decltype(std::unordered_set{{1, 2, 3},
+ 0, std::hash<int>{}, std::allocator<int>{}}),
std::unordered_set<int>>);
static_assert(std::is_same_v<
static_assert(std::is_same_v<
decltype(std::unordered_set{x.begin(), x.end(),
- {}, std::hash<int>{}, {}}),
+ {}, std::hash<int>{}, std::equal_to<int>{}}),
+ std::unordered_set<int>>);
+
+ static_assert(std::is_same_v<
+ decltype(std::unordered_set{x.begin(), x.end(),
+ {}, std::hash<int>{}, std::allocator<int>{}}),
std::unordered_set<int>>);
static_assert(std::is_same_v<