re PR c++/84927 (ICE with NSDMI and reference)
authorMarek Polacek <polacek@redhat.com>
Mon, 19 Mar 2018 20:46:16 +0000 (20:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 19 Mar 2018 20:46:16 +0000 (20:46 +0000)
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
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/nsdmi-aggr9.C [new file with mode: 0644]

index 712d4d8bc2d31ecd6b221511a8017decc508356c..236ea215452c0e5ef7a588cd4df94ac507bb30fc 100644 (file)
@@ -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  <jason@redhat.com>
 
        PR c++/71834 - template-id with too few arguments.
index 05a1cb64d61e2c6c84b27a564ddd8ae0ddb31326..894bcd0bb3e44796308955b12527330eccf32801 100644 (file)
@@ -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);
        }
index 882dc9ab92d32897fee63bf6aa60b115099dcfd2..7638ca162f4d817eff888892cff8fea924c7d44b 100644 (file)
@@ -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  <m.ostapenko@samsung.com>
 
        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 (file)
index 0000000..4e13fc5
--- /dev/null
@@ -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};
+}