PR c++/71638, ICE with NSDMI and reference.
authorMarek Polacek <polacek@redhat.com>
Wed, 21 Mar 2018 07:09:22 +0000 (07:09 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 21 Mar 2018 07:09:22 +0000 (07:09 +0000)
* 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
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr10.C [new file with mode: 0644]

index c4dd7d11163edee97a6b67240093d162bcad01a5..f3ed02d1820f639e4da204bb98daf85e22ffb588 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-21  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.
+
 2018-03-20  Marek Polacek  <polacek@redhat.com>
 
        PR c++/84978, ICE with NRVO.
index 1f8ece89730613e08bd20c6b85d4452641b88cf8..9e813bf0bcd385005942e81213ce4a4e95a36e71 100644 (file)
@@ -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;
        }
index d2c09ded1b2c9f33ec703c43ab3e525bf7043574..f3cc7574e9caad14f729b4cc99d32d85b23a67d2 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-21  Marek Polacek  <polacek@redhat.com>
+
+       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  <paul.hua.gm@gmail.com>
 
        * 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 (file)
index 0000000..aac6fa1
--- /dev/null
@@ -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 (file)
index 0000000..1dc396d
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/71638
+// { dg-do compile { target c++14 } }
+
+struct {
+  int &&a;
+  int b{a};
+} c[] { { 2 } };