Fix crash (segfault) on a missing closing parenthesis when parsing the
expressions in a block. The returned `expr` was missing a check before being
used.
Add corresponding test.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block):
Check if `expr` is valid after parsing it.
gcc/testsuite/ChangeLog:
* rust/compile/missing_closing_paren.rs: New test.
// must be expression statement
lexer.skip_token ();
- std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
- new AST::ExprStmtWithoutBlock (std::move (expr),
- t->get_locus ()));
- return ExprOrStmt (std::move (stmt));
+ if (expr)
+ {
+ std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
+ new AST::ExprStmtWithoutBlock (std::move (expr),
+ t->get_locus ()));
+ return ExprOrStmt (std::move (stmt));
+ }
+ else
+ {
+ return ExprOrStmt::create_error ();
+ }
}
// return expression
--- /dev/null
+fn foo() {
+ (""; // { dg-error "unexpected token .*" }
+}