From 6bc46c4670008161e63d663e50ce07ac27b2c99e Mon Sep 17 00:00:00 2001 From: jakub Date: Tue, 2 Jan 2018 18:04:19 +0000 Subject: [PATCH] PR c++/83556 * tree.c (replace_placeholders_r): Pass NULL as last argument to cp_walk_tree instead of d->pset. If non-TREE_CONSTANT and non-PLACEHOLDER_EXPR tree has been seen already, set *walk_subtrees to false and return. (replace_placeholders): Pass NULL instead of &pset as last argument to cp_walk_tree. * g++.dg/cpp0x/pr83556.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256086 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/tree.c | 11 +++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/pr83556.C | 28 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr83556.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 985f8716f74..a0da31c6481 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2018-01-02 Jakub Jelinek + + PR c++/83556 + * tree.c (replace_placeholders_r): Pass NULL as last argument to + cp_walk_tree instead of d->pset. If non-TREE_CONSTANT and + non-PLACEHOLDER_EXPR tree has been seen already, set *walk_subtrees + to false and return. + (replace_placeholders): Pass NULL instead of &pset as last argument + to cp_walk_tree. + 2018-01-02 Nathan Sidwell * constexpr.c (cxx_bind_parameters_in_call): Remove unneeded local diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 5528fa96fb7..37f54847e62 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3106,6 +3106,11 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) { constructor_elt *ce; vec *v = CONSTRUCTOR_ELTS (*t); + if (d->pset->add (*t)) + { + *walk_subtrees = false; + return NULL_TREE; + } for (unsigned i = 0; vec_safe_iterate (v, i, &ce); ++i) { tree *valp = &ce->value; @@ -3125,7 +3130,7 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) valp = &TARGET_EXPR_INITIAL (*valp); } d->obj = subob; - cp_walk_tree (valp, replace_placeholders_r, data_, d->pset); + cp_walk_tree (valp, replace_placeholders_r, data_, NULL); d->obj = obj; } *walk_subtrees = false; @@ -3133,6 +3138,8 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) } default: + if (d->pset->add (*t)) + *walk_subtrees = false; break; } @@ -3161,7 +3168,7 @@ replace_placeholders (tree exp, tree obj, bool *seen_p) replace_placeholders_t data = { obj, false, &pset }; if (TREE_CODE (exp) == TARGET_EXPR) tp = &TARGET_EXPR_INITIAL (exp); - cp_walk_tree (tp, replace_placeholders_r, &data, &pset); + cp_walk_tree (tp, replace_placeholders_r, &data, NULL); if (seen_p) *seen_p = data.seen; return exp; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b77e73f8bbc..684a99355a4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-02 Jakub Jelinek + + PR c++/83556 + * g++.dg/cpp0x/pr83556.C: New test. + 2018-01-02 Thomas Koenig PR fortran/45689 diff --git a/gcc/testsuite/g++.dg/cpp0x/pr83556.C b/gcc/testsuite/g++.dg/cpp0x/pr83556.C new file mode 100644 index 00000000000..bab06a5b943 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr83556.C @@ -0,0 +1,28 @@ +// PR c++/83556 +// { dg-do run { target c++11 } } + +int +foo () +{ + return 1; +} + +struct A +{ + int a = foo (); + int b = 1; + int c = a ? 1 * b : 2 * b; +}; + +struct B +{ + A d {}; +}; + +int +main () +{ + B e {}; + if (e.d.c != 1) + __builtin_abort (); +} -- 2.11.4.GIT