From: Tom de Vries Date: Fri, 28 Nov 2025 11:55:33 +0000 (+0100) Subject: [gdb/build, c++20] Fix UTF-8 string literal usage X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8e4eb6aaac16c42d44fa2580e59bc8017c80cef;p=thirdparty%2Fbinutils-gdb.git [gdb/build, c++20] Fix UTF-8 string literal usage PR build/33675 reports a build breaker: ... top.c: In function ‘void box_one_message(ui_file*, std::string, int)’: top.c:1368:35: error: conditional expression between distinct pointer types \ ‘const char8_t*’ and ‘const char*’ lacks a cast 1368 | const char *wall = emojis_ok () ? u8"\u2503" : "|"; | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ ... The problem is that UTF-8 string literals have type: - const char[N] (until C++20), or - const char8_t[N] (since C++20) Fix this by assigning to variables: ... static const char bd_heavy_vertical[] = u8"\u2503"; ... and using the variables instead. Tested by rebuilding on x86_64-linux, and starting gdb and checking the welcome message box. Reviewed-By: Guinevere Larsen Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33675 --- diff --git a/gdb/top.c b/gdb/top.c index 2e3b373d5e2..0798fea7a3b 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1359,13 +1359,25 @@ There is NO WARRANTY, to the extent permitted by law.", } } +/* Unicode Block “Box Drawing” chars. UTF-8 string literals have type: + - const char[N] (until C++20), or + - const char8_t[N] (since C++20). + Assign them to a variable to stabilize the type. +*/ +static const char bd_heavy_horizontal[] = u8"\u2501"; +static const char bd_heavy_vertical[] = u8"\u2503"; +static const char bd_heavy_down_and_right[] = u8"\u250f"; +static const char bd_heavy_down_and_left[] = u8"\u2513"; +static const char bd_heavy_up_and_right[] = u8"\u2517"; +static const char bd_heavy_up_and_left[] = u8"\u251b"; + /* Print MESSAGE to STREAM in lines of maximum size WIDTH, so that it fits in an ascii art box of width WIDTH+4. Messages may be broken on spaces. */ static void box_one_message (ui_file *stream, std::string message, int width) { - const char *wall = emojis_ok () ? u8"\u2503" : "|"; + const char *wall = emojis_ok () ? bd_heavy_vertical : "|"; while (!message.empty ()) { std::string line; @@ -1444,10 +1456,10 @@ print_gdb_hints (struct ui_file *stream) if (emojis_ok ()) { - gdb_printf (stream, u8"\u250f"); + gdb_printf (stream, "%s", bd_heavy_down_and_right); for (int i = 0; i < (width - 2); i++) - gdb_printf (stream, u8"\u2501"); - gdb_printf (stream, u8"\u2513\n"); + gdb_printf (stream, "%s", bd_heavy_horizontal); + gdb_printf (stream, "%s\n", bd_heavy_down_and_left); } else gdb_printf (stream, "+%s+\n", sep.c_str ()); @@ -1457,10 +1469,10 @@ print_gdb_hints (struct ui_file *stream) if (emojis_ok ()) { - gdb_printf (stream, u8"\u2517"); + gdb_printf (stream, "%s", bd_heavy_up_and_right); for (int i = 0; i < (width - 2); i++) - gdb_printf (stream, u8"\u2501"); - gdb_printf (stream, u8"\u251b\n"); + gdb_printf (stream, "%s", bd_heavy_horizontal); + gdb_printf (stream, "%s\n", bd_heavy_up_and_left); } else gdb_printf (stream, "+%s+\n", sep.c_str ());