From b9d6b0153cbd3fc5a5d451ffa1a44313ba56e24a Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 30 Jun 2011 20:03:34 -0400 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/tree.c | 16 ++++++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/initlist54.C | 13 +++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist54.C 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({""}); +} -- 2.30.2