diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d77663a88d4..99b594717d2 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. + 2017-12-19 Marek Polacek Backported from mainline diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index a5f7f44200c..6501f127d7c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2804,6 +2804,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; @@ -2823,7 +2828,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; @@ -2831,6 +2836,8 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_) } default: + if (d->pset->add (*t)) + *walk_subtrees = false; break; } @@ -2859,7 +2866,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 d2a588719f7..d7298b8be55 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/83650 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 (); +}