public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107901] New: std::format isn't usable on 16-bit targets
@ 2022-11-28 21:05 redi at gcc dot gnu.org
2022-11-28 21:11 ` [Bug libstdc++/107901] " redi at gcc dot gnu.org
2022-11-28 21:11 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-28 21:05 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/107901] std::format isn't usable on 16-bit targets
2022-11-28 21:05 [Bug libstdc++/107901] New: std::format isn't usable on 16-bit targets redi at gcc dot gnu.org
@ 2022-11-28 21:11 ` redi at gcc dot gnu.org
2022-11-28 21:11 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-28 21:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107901
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-11-28
Status|UNCONFIRMED |NEW
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This allows the file to be compiled:
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3035,12 +3035,21 @@ namespace __format
case _Arg_ull:
return std::forward<_Visitor>(__vis)(_M_val._M_ull);
case _Arg_flt:
- return std::forward<_Visitor>(__vis)(_M_val._M_flt);
+ if constexpr (__formattable_float<float>)
+ return std::forward<_Visitor>(__vis)(_M_val._M_flt);
+ else
+ return std::forward<_Visitor>(__vis)(_M_val._M_none);
case _Arg_dbl:
- return std::forward<_Visitor>(__vis)(_M_val._M_dbl);
+ if constexpr (__formattable_float<double>)
+ return std::forward<_Visitor>(__vis)(_M_val._M_dbl);
+ else
+ return std::forward<_Visitor>(__vis)(_M_val._M_none);
#ifndef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
case _Arg_ldbl:
- return std::forward<_Visitor>(__vis)(_M_val._M_ldbl);
+ if constexpr (__formattable_float<long double>)
+ return std::forward<_Visitor>(__vis)(_M_val._M_ldbl);
+ else
+ return std::forward<_Visitor>(__vis)(_M_val._M_none);
#else
case _Arg_f128:
return std::forward<_Visitor>(__vis)(_M_val._M_f128);
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/107901] std::format isn't usable on 16-bit targets
2022-11-28 21:05 [Bug libstdc++/107901] New: std::format isn't usable on 16-bit targets redi at gcc dot gnu.org
2022-11-28 21:11 ` [Bug libstdc++/107901] " redi at gcc dot gnu.org
@ 2022-11-28 21:11 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-28 21:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107901
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Or simply:
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3034,6 +3034,7 @@ namespace __format
return std::forward<_Visitor>(__vis)(_M_val._M_ll);
case _Arg_ull:
return std::forward<_Visitor>(__vis)(_M_val._M_ull);
+#if __cpp_lib_to_chars
case _Arg_flt:
return std::forward<_Visitor>(__vis)(_M_val._M_flt);
case _Arg_dbl:
@@ -3046,6 +3047,7 @@ namespace __format
return std::forward<_Visitor>(__vis)(_M_val._M_f128);
case _Arg_ibm128:
return std::forward<_Visitor>(__vis)(_M_val._M_ibm128);
+#endif
#endif
case _Arg_str:
return std::forward<_Visitor>(__vis)(_M_val._M_str);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-28 21:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 21:05 [Bug libstdc++/107901] New: std::format isn't usable on 16-bit targets redi at gcc dot gnu.org
2022-11-28 21:11 ` [Bug libstdc++/107901] " redi at gcc dot gnu.org
2022-11-28 21:11 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).