]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: fix lexing byte literal
authorRaiki Tamura <tamaron1203@gmail.com>
Thu, 29 Jun 2023 03:06:44 +0000 (12:06 +0900)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:29 +0000 (18:49 +0100)
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>
gcc/rust/lex/rust-lex.cc
gcc/testsuite/rust/compile/bytecharstring.rs

index 7f7fc0c80bff7c53cb3bfb9d632acb6b8cd85d87..eef022e53aa2efd964bc5a9824bd0f51b4e73484 100644 (file)
@@ -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);
 }
 
index 9242e2c5a0bce2c3d2587505c440a33c5e916aac..928dc0cdefbda14c4da4875137033ae99168ee92 100644 (file)
@@ -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" }
 }