[PATCH] [gdb/build] Add warning_prefix_default/error_prefix_default constants

Tom de Vries <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Post-commit review of commit f33422af6d8 ("[gdb/build] Fix cli/cli-style.c
build error with C++20") pointed out the need for a comment for a
reinterpret_cast [1].

While reviewing the comment in gdb/top.c for bd_heavy_horizontal et al, I
realized I could use the same style:
...
static const char bd_heavy_horizontal[] = u8"\u2501";
...
and get rid of the reinterpret_cast.

Add warning_prefix_default and error_prefix_default constants, and copy
the comment from gdb/top.c.

Tested on x86_64-linux.

[1] https://sourceware.org/pipermail/gdb-patches/2026-August/229421.html
---
 gdb/cli/cli-style.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index 5c26519c6d7..cc22b861ca0 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -449,13 +449,26 @@ no_emojis ()
   emoji_styling = AUTO_BOOLEAN_FALSE;
 }
 
-/* Emoji warning prefix:
+/* Emoji warning prefix default:
    - u26A0: Warning Sign: ⚠
    - uFE0F: Variation Selector-16 (VS16)
    The VS16 forces "Emoji" presentation.  It is needed because the default
-   presentation for Warning Sign is "Text".  Together, we get: ⚠️ .  */
-static std::string warning_prefix
-  = reinterpret_cast<const char *> (u8"\u26A0\uFE0F ");
+   presentation for Warning Sign is "Text".  Together, we get: ⚠️ .
+
+   Emoji error prefix default:
+   - u274C: Cross Mark: ❌
+   No VS16 is needed because the default presentation for Cross Mark is
+   "Emoji".
+
+   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 warning_prefix_default[] = u8"\u26A0\uFE0F ";
+static const char error_prefix_default[] = u8"\u274C ";
+
+/* Emoji warning prefix.  */
+static std::string warning_prefix = warning_prefix_default;
 
 /* Implement 'show style warning-prefix'.  */
 
@@ -476,12 +489,8 @@ print_warning_prefix (ui_file *file)
     gdb_puts (warning_prefix.c_str (), file);
 }
 
-/* Emoji error prefix:
-   - u274C: Cross Mark: ❌
-   No VS16 is needed because the default presentation for Cross Mark is
-   "Emoji".  */
-static std::string error_prefix
-  = reinterpret_cast<const char *> (u8"\u274C ");
+/* Emoji error prefix.  */
+static std::string error_prefix = error_prefix_default;
 
 /* Implement 'show style error-prefix'.  */
 

base-commit: f33422af6d81c623871f1407e2fce0794e90739a
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.