If 'jump_target' is local to this function and still set at the end, we can't correctly evaluate it, and we don't need to try.
* constexpr.c (cxx_eval_statement_list): Jumping out of a statement-expr is non-constant. Tested x86_64-pc-linux-gnu, applying to trunk. --- gcc/cp/constexpr.c | 9 +++++++++ gcc/testsuite/g++.dg/ext/stmtexpr23.C | 10 ++++++++++ gcc/cp/ChangeLog | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/stmtexpr23.C diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 53854a8acd4..0ce5618a2fc 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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 index 00000000000..c6aaea76f23 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/stmtexpr23.C @@ -0,0 +1,10 @@ +// PR c++/89948 +// { dg-options "" } + +void f () +{ + int a = 0; + for (;;) + for (;a=+({break;1;});) + {} +} diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ad4dba46bfe..6bfd26c6a2e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-04-04 Jason Merrill <ja...@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 <ja...@redhat.com> PR c++/89966 - error with non-type auto tparm. base-commit: 1a08779b89cee120afe057ba013ad7e92e62798f -- 2.20.1