diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d411be5d9d8..9ccdfbe594f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-05-29 Marek Polacek + + PR c++/85883 + * init.c (build_new): Handle deducing a class with new + with more than one argument. + 2018-05-29 Jakub Jelinek PR c++/85952 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index de1bfee54bb..b925e843432 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3586,11 +3586,27 @@ build_new (vec **placement, tree type, tree nelts, if (auto_node) { tree d_init = NULL_TREE; - if (vec_safe_length (*init) == 1) + const size_t len = vec_safe_length (*init); + /* E.g. new auto(x) must have exactly one element, or + a {} initializer will have one element. */ + if (len == 1) { d_init = (**init)[0]; d_init = resolve_nondeduced_context (d_init, complain); } + /* For the rest, e.g. new A(1, 2, 3), create a list. */ + else if (len > 1) + { + unsigned int n; + tree t; + tree *pp = &d_init; + FOR_EACH_VEC_ELT (**init, n, t) + { + t = resolve_nondeduced_context (t, complain); + *pp = build_tree_list (NULL_TREE, t); + pp = &TREE_CHAIN (*pp); + } + } type = do_auto_deduction (type, d_init, auto_node, complain); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d71991fb646..83f16eec480 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-05-29 Marek Polacek + + PR c++/85883 + * g++.dg/cpp1z/class-deduction55.C: New test. + * g++.dg/cpp1z/class-deduction56.C: New test. + * g++.dg/cpp1z/class-deduction57.C: New test. + 2018-05-29 Jakub Jelinek PR c++/85952 diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction55.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction55.C new file mode 100644 index 00000000000..a93d7203681 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction55.C @@ -0,0 +1,15 @@ +// PR c++/85883 +// { dg-options -std=c++17 } + +template +struct Bar +{ + Bar(T) { } +}; + +int +main () +{ + auto x = Bar(1); + auto y = new Bar(3); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction56.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction56.C new file mode 100644 index 00000000000..71dbfa1904d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction56.C @@ -0,0 +1,15 @@ +// PR c++/85883 +// { dg-options -std=c++17 } + +template +struct Bar +{ + Bar(T1, T2) { } +}; + +int +main () +{ + auto x = Bar(1, 2); + auto y = new Bar(3, 4); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction57.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction57.C new file mode 100644 index 00000000000..200ba6c3536 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction57.C @@ -0,0 +1,15 @@ +// PR c++/85883 +// { dg-options -std=c++17 } + +template +struct Bar +{ + Bar(T1, T2, T3) { } +}; + +int +main () +{ + auto x = Bar(1, 2, 3); + auto y = new Bar(3, 4, 5); +}