[Bug c/93239] Enhancement: allow unevaluated statement expressions at filescope

pskocik at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jan 16 21:02:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93239

--- Comment #1 from pskocik at gmail dot com ---
Fixing this seems as simple as removing/commenting-out:

gcc/c/c-parser.c:8195     /* If we've not yet started the current function's
statement list,
gcc/c/c-parser.c:8196        or we're in the parameter scope of an old-style
function
gcc/c/c-parser.c:8197        declaration, statement expressions are not
allowed.  */
gcc/c/c-parser.c:8198     if (!building_stmt_list_p () ||
old_style_parameter_scope ())
gcc/c/c-parser.c:8199       {
gcc/c/c-parser.c:8200         error_at (loc, "braced-group within expression
allowed "
gcc/c/c-parser.c:8201                   "only inside a function");
gcc/c/c-parser.c:8202         parser->error = true;
gcc/c/c-parser.c:8203         c_parser_skip_until_found (parser,
CPP_CLOSE_BRACE, NULL);
gcc/c/c-parser.c:8204         c_parser_skip_until_found (parser,
CPP_CLOSE_PAREN, NULL);
gcc/c/c-parser.c:8205         expr.set_error ();
gcc/c/c-parser.c:8206         break;
gcc/c/c-parser.c:8207       }

This would be both very useful, and it makes all kind of sense, because other
expression constructs (function calls, comma expressions, ...) aren't
restricted syntactically either (just semantically), which means they _can_ be
inside untaken branches of constant-forming _Generic/__builtin_choose_expr, and
I can think of no good reason why statement expressions shouldn't be allowed
there too.


More information about the Gcc-bugs mailing list