https://gcc.gnu.org/g:4afb257fc29f72a34eb1328aa217d891f975d631

commit r16-4399-g4afb257fc29f72a34eb1328aa217d891f975d631
Author: Jakub Jelinek <[email protected]>
Date:   Mon Oct 13 21:36:47 2025 +0200

    ++: 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  <[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.

Diff:
---
 gcc/cp/decl.cc                               | 17 +++++++++++++++++
 gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 05791076d878..2089e4c21acc 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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);
diff --git a/gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C 
b/gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C
new file mode 100644
index 000000000000..f2963f1de84b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/func_constexpr3.C
@@ -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"

Reply via email to