diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0e7bcb0ce29..81e44573032 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-01-21 Jason Merrill + + PR c++/47041 + * semantics.c (build_constexpr_constructor_member_initializers): + Handle trivial copy. + 2011-01-21 Jakub Jelinek PR c++/47388 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ba9051592bf..dc29c7a9a71 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5607,7 +5607,20 @@ build_constexpr_constructor_member_initializers (tree type, tree body) body = STATEMENT_LIST_HEAD (body)->stmt; body = BIND_EXPR_BODY (body); if (TREE_CODE (body) == CLEANUP_POINT_EXPR) - ok = build_data_member_initialization (body, &vec); + { + body = TREE_OPERAND (body, 0); + if (TREE_CODE (body) == EXPR_STMT) + body = TREE_OPERAND (body, 0); + if (TREE_CODE (body) == INIT_EXPR + && (same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (TREE_OPERAND (body, 0)), + current_class_type))) + { + /* Trivial copy. */ + return TREE_OPERAND (body, 1); + } + ok = build_data_member_initialization (body, &vec); + } else if (TREE_CODE (body) == STATEMENT_LIST) { tree_stmt_iterator i; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5e1539bf513..95d0a778c46 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-01-21 Jason Merrill + + PR c++/47041 + * g++.dg/cpp0x/constexpr-ctor6.C: New. + 2011-01-21 Jakub Jelinek PR c++/47388 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C new file mode 100644 index 00000000000..4f86f73a458 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C @@ -0,0 +1,9 @@ +// PR c++/47041 +// { dg-options "-std=c++0x -fno-elide-constructors" } + +struct S +{ + int i; +}; + +S s = S ();