re PR c++/84927 (ICE with NSDMI and reference)
authorMarek Polacek <polacek@redhat.com>
Tue, 20 Mar 2018 18:13:38 +0000 (18:13 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 20 Mar 2018 18:13:38 +0000 (18:13 +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: r258691

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/nrv19.C [new file with mode: 0644]

index 894a33e52359c7ca2194abeb634abcbc587f5fdd..c4dd7d11163edee97a6b67240093d162bcad01a5 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-20  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84978, ICE with NRVO.
+       * constexpr.c (cxx_eval_constant_expression): Handle the case when
+       a RESULT_DECL isn't in the hash map.
+
 2018-03-20  Jason Merrill  <jason@redhat.com>
 
        PR c++/84978, ICE with NRVO.
index 894bcd0bb3e44796308955b12527330eccf32801..1f8ece89730613e08bd20c6b85d4452641b88cf8 100644 (file)
@@ -4111,7 +4111,15 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
       /* We ask for an rvalue for the RESULT_DECL when indirecting
         through an invisible reference, or in named return value
         optimization.  */
-      return (*ctx->values->get (t));
+      if (tree *p = ctx->values->get (t))
+       return *p;
+      else
+       {
+         if (!ctx->quiet)
+           error ("%qE is not a constant expression", t);
+         *non_constant_p = true;
+       }
+      break;
 
     case VAR_DECL:
       if (DECL_HAS_VALUE_EXPR_P (t))
index 21a16df4884c4725c9f781a23f20c8f1f5b866b0..edef059e7ef2e434817e616d8bc88cf11c102189 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-20  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/84978, ICE with NRVO.
+       * g++.dg/opt/nrv19.C: New test.
+
 2018-03-20  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/84962
diff --git a/gcc/testsuite/g++.dg/opt/nrv19.C b/gcc/testsuite/g++.dg/opt/nrv19.C
new file mode 100644 (file)
index 0000000..385593c
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/84978
+// { dg-do compile }
+
+struct S {
+  void (*fn)();
+  int a[10];
+};
+
+S
+foo ()
+{
+  S s;
+  s.fn ();
+  return s;
+}