From: Jason Merrill Date: Wed, 26 Jul 2017 17:39:31 +0000 (-0400) Subject: P0702R1 - List deduction of vector. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6cad8c86b86637e9987a02cf84bddb1e8e397319;p=gcc.git P0702R1 - List deduction of vector. * pt.c (do_class_deduction): Special-case deduction from a single element of related type. From-SVN: r250584 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b2df1eff896..9e763ae6d62 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-07-26 Jason Merrill + + P0702R1 - List deduction of vector. + * pt.c (do_class_deduction): Special-case deduction from a single + element of related type. + 2017-07-26 Leonid Koppel PR c++/67054 - Inherited ctor with non-default-constructible members diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bb323534ec0..173ec3f303b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25331,6 +25331,24 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, else if (BRACE_ENCLOSED_INITIALIZER_P (init)) { try_list_ctor = TYPE_HAS_LIST_CTOR (type); + if (try_list_ctor && CONSTRUCTOR_NELTS (init) == 1) + { + /* As an exception, the first phase in 16.3.1.7 (considering the + initializer list as a single argument) is omitted if the + initializer list consists of a single expression of type cv U, + where U is a specialization of C or a class derived from a + specialization of C. */ + tree elt = CONSTRUCTOR_ELT (init, 0)->value; + tree etype = TREE_TYPE (elt); + + tree tparms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); + tree targs = make_tree_vec (TREE_VEC_LENGTH (tparms)); + int err = unify (tparms, targs, type, etype, + UNIFY_ALLOW_DERIVED, /*explain*/false); + if (err == 0) + try_list_ctor = false; + ggc_free (targs); + } if (try_list_ctor || is_std_init_list (type)) args = make_tree_vector_single (init); else diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction42.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction42.C new file mode 100644 index 00000000000..8217fd4d79a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction42.C @@ -0,0 +1,19 @@ +// { dg-options -std=c++1z } + +#include + +template struct same; +template struct same { }; + +template +struct A +{ + A(const A&); + A(std::initializer_list); +}; + +A a { 1 }; +A b { a }; + +same s; +