GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

`__PRETTY_FUNCTION__` now uses `cpp_translate_string` for encoding consistency.

GCC's C++ front end now uses `cpp_translate_string` for `__PRETTY_FUNCTION__` initializers, correctly handling string encoding without interpreting escape sequ…

GCC’s C++ front end now uses cpp_translate_string instead of cpp_interpret_string when translating initializers for __PRETTY_FUNCTION__. Previously, cpp_interpret_string could incorrectly process escape sequences within the function name, leading to an old bug resurfacing. The new approach correctly handles character set re-encoding without unintended interpretation, ensuring __PRETTY_FUNCTION__ provides an accurate string representation of the function’s signature.

In Details

This commit addresses a regression in the C++ front end concerning the initializer translation for __PRETTY_FUNCTION__. The previous use of cpp_interpret_string in cp_make_fname_decl (within decl.cc) to re-encode the function name could inadvertently interpret escape sequences present in the mangled function name, leading to incorrect string generation. The fix switches to cpp_translate_string, which, unlike its _interpret_ counterpart, performs character set translation without parsing or interpreting escape sequences. This ensures that __PRETTY_FUNCTION__ provides an exact and…

For Context

In C++, the special __PRETTY_FUNCTION__ macro allows programmers to get a string containing the exact signature of the current function, which is often useful for logging, debugging, or metaprogramming. Compilers sometimes need to re-encode these strings, for example, from the source code's character set to the character set used by the running program. This commit fixes a subtle bug in how GCC's C++ compiler handled this re-encoding for __PRETTY_FUNCTION__. Previously, the compiler was using a function that not only translated characters but also tried to interpret 'escape sequences' (like \n for a newline) within the function's name. This could lead to incorrect or corrupted strings when __PRETTY_FUNCTION__ was used. The fix involves using a different internal function (cpp_translate_string) that only performs the necessary character set translation without trying to second-guess or interpret any special characters, ensuring __PRETTY_FUNCTION__ always provides the correc…

Filed Under: c++bugfixencodinglanguage-feature