From: Jason Merrill Date: Tue, 3 Apr 2012 22:51:08 +0000 (-0400) Subject: re PR c++/52796 ([C++11] Initialization of primitive object with 0-length parameter... X-Git-Tag: releases/gcc-4.6.4~606 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6f1732755cba4f352899e0517982eae5bf07e56;p=thirdparty%2Fgcc.git re PR c++/52796 ([C++11] Initialization of primitive object with 0-length parameter pack fails to value-initialize) PR c++/52796 * pt.c (tsubst_initializer_list): A pack expansion with no elements means value-initialization. From-SVN: r186120 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a365738c35c9..9dea1b5c1b40 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-04-03 Jason Merrill + + PR c++/52796 + * pt.c (tsubst_initializer_list): A pack expansion with no elements + means value-initialization. + 2012-03-01 Release Manager * GCC 4.6.3 released. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0760e9e23ca9..4defa853eaa6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17785,6 +17785,7 @@ tsubst_initializer_list (tree t, tree argvec) } else { + tree tmp; decl = tsubst_copy (TREE_PURPOSE (t), argvec, tf_warning_or_error, NULL_TREE); @@ -17793,10 +17794,17 @@ tsubst_initializer_list (tree t, tree argvec) in_base_initializer = 1; init = TREE_VALUE (t); + tmp = init; if (init != void_type_node) init = tsubst_expr (init, argvec, tf_warning_or_error, NULL_TREE, /*integral_constant_expression_p=*/false); + if (init == NULL_TREE && tmp != NULL_TREE) + /* If we had an initializer but it instantiated to nothing, + value-initialize the object. This will only occur when + the initializer was a pack expansion where the parameter + packs used in that expansion were of length zero. */ + init = void_type_node; in_base_initializer = 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9dcfc25b8891..a3a5f18e1180 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-04-03 Jason Merrill + + PR c++/52796 + * g++.dg/cpp0x/variadic-value1.C: New. + 2012-03-28 Joey Ye Backported from mainline diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C b/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C new file mode 100644 index 000000000000..179919a5bc76 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic-value1.C @@ -0,0 +1,24 @@ +// PR c++/52796 +// { dg-do run { target c++11 } } + +inline void *operator new(__SIZE_TYPE__ s, void *p) { return p; } + +struct A +{ + int i; + template + A(Ts&&... ts): i(ts...) { } +}; + +static union { + unsigned char c[sizeof(A)]; + int i; +}; + +int main() +{ + i = 0xdeadbeef; + new(c) A; + if (i != 0) + __builtin_abort(); +}