https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107901
Bug ID: 107901 Summary: std::format isn't usable on 16-bit targets Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- the std::to_chars overloads for floating-point types are gated on __SIZE_WIDTH__ being at least 32-bits: #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 \ && __SIZE_WIDTH__ >= 32 && _GLIBCXX_HOSTED # define __cpp_lib_to_chars 201611L #endif ... #if defined __cpp_lib_to_chars // Floating-point std::to_chars // Overloads for float. to_chars_result to_chars(char* __first, char* __last, float __value) noexcept; to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt) noexcept; to_chars_result to_chars(char* __first, char* __last, float __value, chars_format __fmt, int __precision) noexcept; This means that std::format fails to compile on targets with 16-bit size_t, because it assumes that FP types can be printed via std::to_chars: /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format: In instantiation of 'std::__format::_Formatting_scanner<std::__format::_Sink_iter<wchar_t>, wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:42&)> [with auto:42 = float]': /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format:3038:44: required from 'decltype(auto) std::basic_format_arg<_Context>::_M_visit(_Visitor&&, std::__format::_Arg_t) [with _Visitor = std::__format::_Formatting_scanner<std::__format::_Sink_iter<wchar_t>, wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:42&)>; _Context = std::basic_format_context<std::__format::_Sink_iter<wchar_t>, wchar_t>]' /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format:3082:28: required from 'decltype(auto) std::visit_format_arg(_Visitor&&, basic_format_arg<_Context>) [with _Visitor = __format::_Formatting_scanner<__format::_Sink_iter<wchar_t>, wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:42&)>; _Context = basic_format_context<__format::_Sink_iter<wchar_t>, wchar_t>]' /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format:3532:23: required from 'void std::__format::_Formatting_scanner<_Out, _CharT>::_M_format_arg(std::size_t) [with _Out = std::__format::_Sink_iter<wchar_t>; _CharT = wchar_t; std::size_t = unsigned int]' /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format:3527:7: required from here /home/jwakely/src/gcc/build-16bit/msp430-elf/libstdc++-v3/include/format:3546:37: error: static assertion failed 3546 | static_assert(__format::__formattable_with<_Type, _Context>); | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Long term, we want to support std::to_chars everywhere. In the short term, we might want to disable FP types in std::format so that other types can still be formatted.