From e77c44ef26fdf7e66fd7129a3aa9240840344694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Tue, 23 Mar 2021 22:03:55 +0100 Subject: Fix error while unexpected EOF when scanning for end of comment Emit an error when EOF is reached before end of C-style comment. Add corresponding test for non regression. fix #300 --- gcc/rust/lex/rust-lex.cc | 8 ++++++++ .../rust.test/fail_compilation/unterminated_c_comment.rs | 1 + 2 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/rust.test/fail_compilation/unterminated_c_comment.rs (limited to 'gcc') diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 6dfaea2..26745e4 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -427,6 +427,14 @@ Lexer::build_token () current_column++; // for error-handling current_char = peek_input (); + if (current_char == EOF) + { + rust_error_at ( + loc, "unexpected EOF while looking for end of comment", + current_char); + break; + } + // if /* found if (current_char == '/' && peek_input (1) == '*') { diff --git a/gcc/testsuite/rust.test/fail_compilation/unterminated_c_comment.rs b/gcc/testsuite/rust.test/fail_compilation/unterminated_c_comment.rs new file mode 100644 index 0000000..4d04d01 --- /dev/null +++ b/gcc/testsuite/rust.test/fail_compilation/unterminated_c_comment.rs @@ -0,0 +1 @@ +/* This comment needs closure :) ! -- cgit v1.1