Skip to content

Commit 857c8a7

Browse files
committed
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 <[email protected]>
1 parent 8ba8ced commit 857c8a7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

gcc/rust/lex/rust-lex.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,12 @@ Lexer::parse_byte_char (Location loc)
17271727
// otherwise, get character from direct input character
17281728
byte_char = current_char;
17291729

1730+
if (byte_char.value > 0x7f)
1731+
{
1732+
rust_error_at (get_current_location (),
1733+
"non-ASCII character in %<byte char%>");
1734+
}
1735+
17301736
skip_input ();
17311737
current_char = peek_input ();
17321738
length++;
@@ -1749,8 +1755,6 @@ Lexer::parse_byte_char (Location loc)
17491755
current_column += length;
17501756

17511757
loc += length - 1;
1752-
1753-
// TODO: error when byte_char is non ASCII
17541758
return Token::make_byte_char (loc, byte_char.value);
17551759
}
17561760

gcc/testsuite/rust/compile/bytecharstring.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ fn main ()
55

66
let _c = '\xef'; // { dg-error "out of range" }
77
let _s = "Foo\xEFBar"; // { dg-error "out of range" }
8+
9+
let _ = b'あ'; // { dg-error " non-ASCII character" }
10+
let _ = b'🦀'; // { dg-error " non-ASCII character" }
811
}

0 commit comments

Comments
 (0)