C++ PATCH for c++/71638, ICE with NSDMI and reference
Marek Polacek
polacek@redhat.com
Tue Mar 20 20:08:00 GMT 2018
This extends my previous fix for c++/84927 in that it also updates
the ctor's flags when we replace an element.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2018-03-20 Marek Polacek <polacek@redhat.com>
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.
diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index 894bcd0bb3e..e2d66498a66 100644
--- gcc/cp/constexpr.c
+++ 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 gcc/testsuite/g++.dg/cpp0x/nsdmi14.C gcc/testsuite/g++.dg/cpp0x/nsdmi14.C
index e69de29bb2d..aac6fa1c81b 100644
--- gcc/testsuite/g++.dg/cpp0x/nsdmi14.C
+++ 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 gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C
index e69de29bb2d..1dc396d9ca5 100644
--- gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C
+++ 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 } };
Marek
More information about the Gcc-patches
mailing list