aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaiki Tamura <tamaron1203@gmail.com>2023-06-29 12:06:44 +0900
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:49:29 +0100
commiteebe4063c1a839a71fd21cb477c9d9a6cc906195 (patch)
tree9352271c9f95d8915efee2b7af5837e61dde6387
parent09777a69afc66fbc102bf462a9a3d6855801e817 (diff)
downloadgcc-eebe4063c1a839a71fd21cb477c9d9a6cc906195.zip
gcc-eebe4063c1a839a71fd21cb477c9d9a6cc906195.tar.gz
gcc-eebe4063c1a839a71fd21cb477c9d9a6cc906195.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>
-rw-r--r--gcc/rust/lex/rust-lex.cc8
-rw-r--r--gcc/testsuite/rust/compile/bytecharstring.rs3
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 7f7fc0c..eef022e 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" }
}