Commit 1474a2e5 by Jason Merrill Committed by Jason Merrill

PR c++/90190 - CTAD with list-constructor.

The passage quoted talks about an initializer list containing a single
expression, but a braced-init-list is not an expression.

	* pt.c (do_class_deduction): Don't try the single element deduction
	if the single element is also a braced list.

From-SVN: r270468
parent d395d8e7
2019-04-19 Jason Merrill <jason@redhat.com> 2019-04-19 Jason Merrill <jason@redhat.com>
PR c++/90190 - CTAD with list-constructor.
* pt.c (do_class_deduction): Don't try the single element deduction
if the single element is also a braced list.
PR c++/90171 - ICE with destroying delete with size_t parm. PR c++/90171 - ICE with destroying delete with size_t parm.
* call.c (sized_deallocation_fn_p): New. Use it instead of * call.c (sized_deallocation_fn_p): New. Use it instead of
second_parm_is_size_t in most cases. second_parm_is_size_t in most cases.
......
...@@ -27325,15 +27325,18 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, ...@@ -27325,15 +27325,18 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags,
where U is a specialization of C or a class derived from a where U is a specialization of C or a class derived from a
specialization of C. */ specialization of C. */
tree elt = CONSTRUCTOR_ELT (init, 0)->value; tree elt = CONSTRUCTOR_ELT (init, 0)->value;
tree etype = TREE_TYPE (elt); if (!BRACE_ENCLOSED_INITIALIZER_P (elt))
{
tree tparms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); tree etype = TREE_TYPE (elt);
tree targs = make_tree_vec (TREE_VEC_LENGTH (tparms)); tree tparms = (INNERMOST_TEMPLATE_PARMS
int err = unify (tparms, targs, type, etype, (DECL_TEMPLATE_PARMS (tmpl)));
UNIFY_ALLOW_DERIVED, /*explain*/false); tree targs = make_tree_vec (TREE_VEC_LENGTH (tparms));
if (err == 0) int err = unify (tparms, targs, type, etype,
try_list_ctor = false; UNIFY_ALLOW_DERIVED, /*explain*/false);
ggc_free (targs); if (err == 0)
try_list_ctor = false;
ggc_free (targs);
}
} }
if (try_list_ctor || is_std_init_list (type)) if (try_list_ctor || is_std_init_list (type))
args = make_tree_vector_single (init); args = make_tree_vector_single (init);
......
// PR c++/90190
// { dg-do compile { target c++17 } }
#include <initializer_list>
enum class X {};
struct Term {
double a;
X i;
};
template <class It = const Term *>
struct sum {
sum(std::initializer_list<Term>) {}
};
int main() {
auto c2 = sum{{1, X()}, {2, X()}};
auto c1 = sum{{1, X()}}; // fails only this
auto c0 = sum{{}};
}
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