diff options
author | Raiki Tamura <tamaron1203@gmail.com> | 2023-06-29 12:06:44 +0900 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-06-30 14:19:32 +0000 |
commit | abfb39e2c6942efb6a60fc25bd6fe9fee2c15392 (patch) | |
tree | e0908de15aa8b17e2891f84a21dce662f8f13ec0 /gcc | |
parent | 2e1f190573aab7b4c055999dda3f857233fd50a9 (diff) | |
download | gcc-abfb39e2c6942efb6a60fc25bd6fe9fee2c15392.zip gcc-abfb39e2c6942efb6a60fc25bd6fe9fee2c15392.tar.gz gcc-abfb39e2c6942efb6a60fc25bd6fe9fee2c15392.tar.bz2 |
gccrs: fix lexing byte literal
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::parse_byte_char):add check for range of codepoint
gcc/testsuite/ChangeLog:
* rust/compile/bytecharstring.rs:add test for it
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/lex/rust-lex.cc | 8 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/bytecharstring.rs | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 28f3863..a921204 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1736,6 +1736,12 @@ Lexer::parse_byte_char (Location loc) // otherwise, get character from direct input character byte_char = current_char; + if (byte_char.value > 0x7f) + { + rust_error_at (get_current_location (), + "non-ASCII character in %<byte char%>"); + } + skip_input (); current_char = peek_input (); length++; @@ -1758,8 +1764,6 @@ Lexer::parse_byte_char (Location loc) current_column += length; loc += length - 1; - - // TODO: error when byte_char is non ASCII return Token::make_byte_char (loc, byte_char.value); } diff --git a/gcc/testsuite/rust/compile/bytecharstring.rs b/gcc/testsuite/rust/compile/bytecharstring.rs index 9242e2c..928dc0c 100644 --- a/gcc/testsuite/rust/compile/bytecharstring.rs +++ b/gcc/testsuite/rust/compile/bytecharstring.rs @@ -5,4 +5,7 @@ fn main () let _c = '\xef'; // { dg-error "out of range" } let _s = "Foo\xEFBar"; // { dg-error "out of range" } + + let _ = b'あ'; // { dg-error " non-ASCII character" } + let _ = b'🦀'; // { dg-error " non-ASCII character" } } |