From ac9ec1988a6d0add2eb724a5d1a9d06101623c51 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 19 Mar 2018 20:46:16 +0000 Subject: [PATCH] re PR c++/84927 (ICE with NSDMI and reference) PR c++/84927 * constexpr.c (cxx_eval_bare_aggregate): Update constructor's flags as we evaluate the elements. (cxx_eval_constant_expression): Verify constructor's flags unconditionally. * g++.dg/cpp1y/nsdmi-aggr9.C: New test. From-SVN: r258661 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 13 +++++++------ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 712d4d8bc2d..236ea215452 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -3,6 +3,12 @@ PR c++/84925 * pt.c (enclosing_instantiation_of): Check if fn is null. + PR c++/84927 + * constexpr.c (cxx_eval_bare_aggregate): Update constructor's flags + as we evaluate the elements. + (cxx_eval_constant_expression): Verify constructor's flags + unconditionally. + 2018-03-16 Jason Merrill PR c++/71834 - template-id with too few arguments. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 05a1cb64d61..894bcd0bb3e 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2880,7 +2880,12 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, (*p)->last().value = elt; } else - CONSTRUCTOR_APPEND_ELT (*p, index, elt); + { + CONSTRUCTOR_APPEND_ELT (*p, index, elt); + /* Adding an element might change the ctor's flags. */ + TREE_CONSTANT (ctx->ctor) = constant_p; + TREE_SIDE_EFFECTS (ctx->ctor) = side_effects_p; + } } if (*non_constant_p || !changed) return t; @@ -4530,11 +4535,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, { /* Don't re-process a constant CONSTRUCTOR, but do fold it to VECTOR_CST if applicable. */ - /* FIXME after GCC 6 branches, make the verify unconditional. */ - if (CHECKING_P) - verify_constructor_flags (t); - else - recompute_constructor_flags (t); + verify_constructor_flags (t); if (TREE_CONSTANT (t)) return fold (t); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 882dc9ab92d..7638ca162f4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ PR c++/84925 * g++.dg/cpp1z/lambda-__func__.C: New test. + PR c++/84927 + * g++.dg/cpp1y/nsdmi-aggr9.C: New test. + 2018-03-19 Maxim Ostapenko PR sanitizer/78651 diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C new file mode 100644 index 00000000000..4e13fc5c9d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C @@ -0,0 +1,14 @@ +// PR c++/84927 - ICE with NSDMI and reference +// { dg-do compile { target c++14 } } + +struct A +{ + int& r; + int i = r; +}; + +void foo() +{ + int j; + A a = A{j}; +} -- 2.30.2