From: Jason Merrill Date: Fri, 1 Jul 2011 00:03:34 +0000 (-0400) Subject: re PR c++/49355 (new T({""}) crashes G++ when struct T { std::string foobar };) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b9d6b0153cbd3fc5a5d451ffa1a44313ba56e24a;p=gcc.git re PR c++/49355 (new T({""}) crashes G++ when struct T { std::string foobar };) PR c++/49355 * tree.c (stabilize_init): Handle aggregate initialization. From-SVN: r175736 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 42c21fe2150..70b6f779bf6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2011-06-30 Jason Merrill + PR c++/49355 + * tree.c (stabilize_init): Handle aggregate initialization. + PR c++/48481 * name-lookup.c (struct arg_lookup): Add fn_set. (add_function): Check it. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index c50751f7ebb..678c7ef9bf1 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3291,10 +3291,18 @@ stabilize_init (tree init, tree *initp) t = TARGET_EXPR_INITIAL (t); if (TREE_CODE (t) == COMPOUND_EXPR) t = expr_last (t); - if (TREE_CODE (t) == CONSTRUCTOR - && EMPTY_CONSTRUCTOR_P (t)) - /* Default-initialization. */ - return true; + if (TREE_CODE (t) == CONSTRUCTOR) + { + /* Aggregate initialization: stabilize each of the field + initializers. */ + unsigned i; + tree value; + bool good = true; + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), i, value) + if (!stabilize_init (value, initp)) + good = false; + return good; + } /* If the initializer is a COND_EXPR, we can't preevaluate anything. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 66e980ac7e4..ed34b5f3c10 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-06-30 Jason Merrill + + PR c++/49355 + * g++.dg/cpp0x/initlist54.C: New. + 2011-06-30 Martin Jambor * gcc.dg/tree-ssa/sra-12.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist54.C b/gcc/testsuite/g++.dg/cpp0x/initlist54.C new file mode 100644 index 00000000000..cdb296133f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist54.C @@ -0,0 +1,13 @@ +// PR c++/49355 +// { dg-options -std=c++0x } + +#include + +struct T { + std::string foobar; +}; + +int main() +{ + T* x = new T({""}); +}