https://gcc.gnu.org/g:f768b1543c36d3d0557dfb07d3c27746ee7058a7

commit r16-5680-gf768b1543c36d3d0557dfb07d3c27746ee7058a7
Author: Jakub Jelinek <[email protected]>
Date:   Thu Nov 27 19:04:58 2025 +0100

    gccrs: Partially unbreak rust build with C++20
    
    I've committed earlier today https://gcc.gnu.org/r16-5628 to switch C++ to
    -std=gnu++20 by default.  That apparently broke rust build (I don't have
    cargo installed, so am not testing rust at all).
    
    Here is a completely untested attempt to fix that.
    
    Note, in C++20 u8"abc" literal has const char8_t[4] type rather than
    const char[4] which was the case in C++17, and there is std::u8string
    etc.
    The casts below to (const char *) is what I've used in libcody as well
    to make it compilable with all of C++11 to C++26.
    Another thing is that the source for some reason expects -fexec-charset=
    to be ASCII compatible and -fwide-exec-charset= to be UTF-16 or UTF-32
    or something similar.  That is certainly not guaranteed.
    Now, if rust-lex.cc can be only compiled with C++17 or later, we
    could just use u8'_' etc., but as GCC still only requires C++14, I'd
    go with u'_' etc.
    
    2025-11-27  Jakub Jelinek  <[email protected]>
    
            * lex/rust-lex.cc (rust_input_source_test): Cast char8_t string
            literals to (const char *) to make it compilable with C++20.  Use
            char16_t or char32_t character literals instead of ordinary
            character literals or wide character literals in expected
            initializers.

Diff:
---
 gcc/rust/lex/rust-lex.cc | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 214161fcca61..4d94a202a1f4 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -2639,37 +2639,37 @@ void
 rust_input_source_test ()
 {
   // ASCII
-  std::string src = u8"_abcde\tXYZ\v\f";
+  std::string src = (const char *) u8"_abcde\tXYZ\v\f";
   std::vector<uint32_t> expected
-    = {'_', 'a', 'b', 'c', 'd', 'e', '\t', 'X', 'Y', 'Z', '\v', '\f'};
+    = {u'_', u'a', u'b', u'c', u'd', u'e', u'\t', u'X', u'Y', u'Z', u'\v', 
u'\f'};
   test_buffer_input_source (src, expected);
 
   // BOM
-  src = u8"\xef\xbb\xbfOK";
-  expected = {'O', 'K'};
+  src = (const char *) u8"\xef\xbb\xbfOK";
+  expected = {u'O', u'K'};
   test_buffer_input_source (src, expected);
 
   // Russian
-  src = u8"приве́т";
-  expected = {L'п',
-             L'р',
-             L'и',
-             L'в',
+  src = (const char *) u8"приве́т";
+  expected = {u'п',
+             u'р',
+             u'и',
+             u'в',
              0x0435 /* CYRILLIC SMALL LETTER IE е */,
              0x301 /* COMBINING ACUTE ACCENT ́ */,
-             L'т'};
+             u'т'};
   test_buffer_input_source (src, expected);
 
-  src = u8"❤️🦀";
+  src = (const char *) u8"❤️🦀";
   expected = {0x2764 /* HEAVY BLACK HEART */,
-             0xfe0f /* VARIATION SELECTOR-16 */, L'🦀'};
+             0xfe0f /* VARIATION SELECTOR-16 */, U'🦀'};
   test_buffer_input_source (src, expected);
 
-  src = u8"こんにちは";
-  expected = {L'こ', L'ん', L'に', L'ち', L'は'};
+  src = (const char *) u8"こんにちは";
+  expected = {u'こ', u'ん', u'に', u'ち', u'は'};
   test_file_input_source (src, expected);
 
-  src = u8"👮‍♂👩‍⚕";
+  src = (const char *) u8"👮‍♂👩‍⚕";
   expected
     = {0x1f46e /* POLICE OFFICER */,   0x200d /* ZERO WIDTH JOINER */,
        0x2642 /* MALE SIGN */,        0x1f469 /* WOMAN */,

Reply via email to