PR c++/89948 - ICE with break in statement-expr.
authorJason Merrill <jason@redhat.com>
Fri, 5 Apr 2019 02:52:23 +0000 (22:52 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 5 Apr 2019 02:52:23 +0000 (22:52 -0400)
* constexpr.c (cxx_eval_statement_list): Jumping out of a
statement-expr is non-constant.

From-SVN: r270161

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

index ad4dba46bfe8b55caa187a09316f76d914dfa749..6bfd26c6a2e061bd8c69c06d3e8552bbc429bcb3 100644 (file)
@@ -1,3 +1,9 @@
+2019-04-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/89948 - ICE with break in statement-expr.
+       * constexpr.c (cxx_eval_statement_list): Jumping out of a
+       statement-expr is non-constant.
+
 2019-04-04  Jason Merrill  <jason@redhat.com>
 
        PR c++/89966 - error with non-type auto tparm.
index 53854a8acd4a08ef5310a334584159c9f70b46bb..0ce5618a2fcb57750d1fdae687f75eccd64d0d38 100644 (file)
@@ -4153,6 +4153,15 @@ cxx_eval_statement_list (const constexpr_ctx *ctx, tree t,
       if (returns (jump_target) || breaks (jump_target))
        break;
     }
+  if (*jump_target && jump_target == &local_target)
+    {
+      /* We aren't communicating the jump to our caller, so give up.  We don't
+        need to support evaluation of jumps out of statement-exprs.  */
+      if (!ctx->quiet)
+       error_at (cp_expr_loc_or_loc (r, input_location),
+                 "statement is not a constant expression");
+      *non_constant_p = true;
+    }
   return r;
 }
 
diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr23.C b/gcc/testsuite/g++.dg/ext/stmtexpr23.C
new file mode 100644 (file)
index 0000000..c6aaea7
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/89948
+// { dg-options "" }
+
+void f ()
+{
+  int a = 0;
+  for (;;)
+    for (;a=+({break;1;});)
+      {}
+}