On 10/13/25 11:17 AM, Jakub Jelinek wrote:
Hi!
When working on reflection, I've noticed that while we correctly translate
__FUNCTION__ content into the execution charset, for C++ we don't translate
__PRETTY_FUNCTION__ content and leave it in the SOURCE_CHARSET encoding:
const char *
file ()
{
return __FILE__;
}
const char *
func ()
{
return __func__;
}
const char *
function ()
{
return __FUNCTION__;
}
const char *
pretty_function ()
{
return __PRETTY_FUNCTION__;
}
./cc1 -quiet -fexec-charset=IBM1047 /tmp/0.C -o - | grep string
.string "a\243\224\227a\360K\303"
.string "\206\244\225\203"
.string "\206\244\225\203\243\211\226\225"
.string "\227\231\205\243\243\250m\206\244\225\203\243\211\226\225"
./cc1plus -quiet -fexec-charset=IBM1047 /tmp/0.C -o - | grep string
.string "a\243\224\227a\360K\303"
.string "\206\244\225\203"
.string "\206\244\225\203\243\211\226\225"
.string "const char* pretty_function()"
The following patch fixes that.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
2025-10-13 Jakub Jelinek <[email protected]>
PR c++/122228
* decl.cc (cp_make_fname_decl): When not using fname_as_decl,
attempt to translate name into ordinary literal encoding.
* g++.dg/cpp1y/func_constexpr3.C: New test.
--- gcc/cp/decl.cc.jj 2025-10-09 22:41:19.876273178 +0200
+++ gcc/cp/decl.cc 2025-10-10 07:16:43.962421962 +0200
@@ -5804,6 +5804,23 @@ cp_make_fname_decl (location_t loc, tree
name = cxx_printable_name (current_function_decl, 2);
}
+ if (!release_name)
+ {
+ cpp_string cstr = { 0, 0 }, strname;
+ size_t len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
+ char *namep = XNEWVEC (char, len);
+ snprintf (namep, len, "\"%s\"", name);
+ strname.text = (unsigned char *) namep;
+ strname.len = len - 1;
+ if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
+ {
+ name = (const char *) cstr.text;
+ release_name = true;
+ }
+
+ XDELETEVEC (namep);
+ }
+
size_t length = strlen (name);
domain = build_index_type (size_int (length));
init = build_string (length + 1, name);
--- gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C.jj 2025-10-10
07:39:11.227100908 +0200
+++ gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C 2025-10-10
07:40:18.154190847 +0200
@@ -0,0 +1,6 @@
+// PR c++/122228
+// { dg-do compile { target c++11 } }
+// { dg-require-iconv "IBM1047" }
+// { dg-options "-fexec-charset=IBM1047 -std=c++11" }
+
+#include "func_constexpr.C"
Jakub