GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libstdc++

libstdc++: Provide defined behavior for unrecognized _Pres_type values

Ensures that libstdc++'s formatting functions handle unrecognized presentation types gracefully, preventing crashes.

When new _Pres_type values are introduced in std::format for future features, linking against older library versions could lead to unrecognized types. Previously, __formatter_int and __formatter_fp would trigger __builtin_unreachable in such cases, causing undefined behavior or crashes. This patch modifies these formatters to fall back to the _Pres_none behavior when an unrecognized _Pres_type is encountered, ensuring defined and safe operation.

In Details

This change addresses a potential ABI incompatibility and runtime error in libstdc++'s <format> implementation. If a program is compiled with a newer GCC that supports new _Pres_type values (e.g., for prefixed hex floats) but linked against an older libstdc++ that doesn't recognize them, the formatters (__formatter_int, __formatter_fp) would hit __builtin_unreachable. This commit modifies the default branches of their format methods to transition to _Pres_none instead, providing a safe fallback.

For Context
_Pres_type
An internal enumeration or type used by std::format in libstdc++ to represent the desired presentation format of a value (e.g., decimal, hexadecimal, scientific).
ABI incompatibility
Application Binary Interface incompatibility. Occurs when different versions of a library or object files use incompatible data structures or function calling conventions, preventing them from working together.
__builtin_unreachable
A GCC built-in function that informs the compiler that the code path reaching it should never be executed. Compilers may optimize more aggressively based on this assumption.
_Pres_none
A specific value within the _Pres_type enumeration, likely representing the default or most basic presentation format.
TU (Translation Unit)
A source file after it has been preprocessed and compiled into an intermediate object file. Linking multiple TUs forms the final executable or library.
Filed Under: libstdc++formattingABI