]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Disallow jumps into statement expressions
authorJakub Jelinek <jakub@redhat.com>
Mon, 3 Oct 2022 16:04:37 +0000 (18:04 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 3 Oct 2022 16:04:37 +0000 (18:04 +0200)
commitc823366fdb9069a54a37a3b18b65a4fa69feabfd
tree284c769f2c9d889c8544317303262be6baec790c
parent7ba34c4e869e83a8d2a2e02b9a2e6727bf662bb4
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.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/name-lookup.cc
gcc/cp/name-lookup.h
gcc/cp/parser.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/ext/stmtexpr24.C [new file with mode: 0644]