mirror of git://gcc.gnu.org/git/gcc.git
++: Fix up __PRETTY_FUNCTION__ for -fexec-charset= [PR122228]
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. 2025-10-13 Jakub Jelinek <jakub@redhat.com> 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.
This commit is contained in:
parent
65acf3665e
commit
4afb257fc2
|
@ -5806,6 +5806,23 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
|
|||
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);
|
||||
|
|
|
@ -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"
|
Loading…
Reference in New Issue