From 1bdbef090299990b1fdef6323bb3daa48acf9349 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 21 Mar 2018 07:09:22 +0000 Subject: [PATCH] PR c++/71638, ICE with NSDMI and reference. * constexpr.c (cxx_eval_bare_aggregate): Update constructor's flags even when we replace an element. * g++.dg/cpp0x/nsdmi14.C: New test. * g++.dg/cpp1y/nsdmi-aggr10.C: New test. From-SVN: r258703 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 17 +++++++++-------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/nsdmi14.C | 19 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C | 7 +++++++ 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi14.C create mode 100644 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c4dd7d11163..f3ed02d1820 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-21 Marek Polacek + + PR c++/71638, ICE with NSDMI and reference. + * constexpr.c (cxx_eval_bare_aggregate): Update constructor's flags + even when we replace an element. + 2018-03-20 Marek Polacek PR c++/84978, ICE with NRVO. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 1f8ece89730..9e813bf0bcd 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2873,16 +2873,17 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, gcc_assert (is_empty_class (TREE_TYPE (TREE_TYPE (index)))); changed = true; } - else if (new_ctx.ctor != ctx->ctor) - { - /* We appended this element above; update the value. */ - gcc_assert ((*p)->last().index == index); - (*p)->last().value = elt; - } else { - CONSTRUCTOR_APPEND_ELT (*p, index, elt); - /* Adding an element might change the ctor's flags. */ + if (new_ctx.ctor != ctx->ctor) + { + /* We appended this element above; update the value. */ + gcc_assert ((*p)->last().index == index); + (*p)->last().value = elt; + } + else + CONSTRUCTOR_APPEND_ELT (*p, index, elt); + /* Adding or replacing an element might change the ctor's flags. */ TREE_CONSTANT (ctx->ctor) = constant_p; TREE_SIDE_EFFECTS (ctx->ctor) = side_effects_p; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2c09ded1b2..f3cc7574e9c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-03-21 Marek Polacek + + PR c++/71638, ICE with NSDMI and reference. + * g++.dg/cpp0x/nsdmi14.C: New test. + * g++.dg/cpp1y/nsdmi-aggr10.C: New test. + 2018-03-21 Chenghua Xu * gcc.dg/vect/vect-strided-shift-1.c: Add dg-skip-if for diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi14.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi14.C new file mode 100644 index 00000000000..aac6fa1c81b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi14.C @@ -0,0 +1,19 @@ +// PR c++/71638 +// { dg-do compile { target c++11 } } +// { dg-options "-Wall" } + +struct A { + struct { + int i; + int &j = i; + } b; + int a = b.j; +}; + +void bar (A); + +void +foo () +{ + bar (A{}); +} diff --git a/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C new file mode 100644 index 00000000000..1dc396d9ca5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C @@ -0,0 +1,7 @@ +// PR c++/71638 +// { dg-do compile { target c++14 } } + +struct { + int &&a; + int b{a}; +} c[] { { 2 } }; -- 2.30.2