* C++ PATCH for c++/71638, ICE with NSDMI and reference
@ 2018-03-20 20:08 Marek Polacek
2018-03-20 20:38 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2018-03-20 20:08 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/71638, ICE with NSDMI and reference
2018-03-20 20:08 C++ PATCH for c++/71638, ICE with NSDMI and reference Marek Polacek
@ 2018-03-20 20:38 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-03-20 20:38 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
OK.
On Tue, Mar 20, 2018 at 3:50 PM, Marek Polacek <polacek@redhat.com> wrote:
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-20 20:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-20 20:08 C++ PATCH for c++/71638, ICE with NSDMI and reference Marek Polacek
2018-03-20 20:38 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).