aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-10-03 18:04:37 +0200
committerJakub Jelinek <jakub@redhat.com>2022-10-03 18:04:37 +0200
commitc823366fdb9069a54a37a3b18b65a4fa69feabfd (patch)
tree284c769f2c9d889c8544317303262be6baec790c /gcc/cp/parser.cc
parent7ba34c4e869e83a8d2a2e02b9a2e6727bf662bb4 (diff)
downloadgcc-c823366fdb9069a54a37a3b18b65a4fa69feabfd.zip
gcc-c823366fdb9069a54a37a3b18b65a4fa69feabfd.tar.gz
gcc-c823366fdb9069a54a37a3b18b65a4fa69feabfd.tar.bz2
c++: Disallow jumps into statement expressions
On Fri, Sep 30, 2022 at 04:39:25PM -0400, Jason Merrill wrote: > > --- gcc/cp/decl.cc.jj 2022-09-22 00:14:55.478599363 +0200 > > +++ gcc/cp/decl.cc 2022-09-22 00:24:01.121178256 +0200 > > @@ -223,6 +223,7 @@ struct GTY((for_user)) named_label_entry > > bool in_transaction_scope; > > bool in_constexpr_if; > > bool in_consteval_if; > > + bool in_assume; > > I think it would be better to reject jumps into statement-expressions like > the C front-end. Ok, here is a self-contained patch that does that. 2022-10-03 Jakub Jelinek <jakub@redhat.com> * cp-tree.h (BCS_STMT_EXPR): New enumerator. * name-lookup.h (enum scope_kind): Add sk_stmt_expr. * name-lookup.cc (begin_scope): Handle sk_stmt_expr like sk_block. * semantics.cc (begin_compound_stmt): For BCS_STMT_EXPR use sk_stmt_expr. * parser.cc (cp_parser_statement_expr): Use BCS_STMT_EXPR instead of BCS_NORMAL. * decl.cc (struct named_label_entry): Add in_stmt_expr. (poplevel_named_label_1): Handle sk_stmt_expr. (check_previous_goto_1): Diagnose entering of statement expression. (check_goto): Likewise. * g++.dg/ext/stmtexpr24.C: New test.
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r--gcc/cp/parser.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 8d0e0fa..6c4f840 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -5272,7 +5272,7 @@ cp_parser_statement_expr (cp_parser *parser)
/* Start the statement-expression. */
tree expr = begin_stmt_expr ();
/* Parse the compound-statement. */
- cp_parser_compound_statement (parser, expr, BCS_NORMAL, false);
+ cp_parser_compound_statement (parser, expr, BCS_STMT_EXPR, false);
/* Finish up. */
expr = finish_stmt_expr (expr, false);
/* Consume the ')'. */