diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-07-27 14:07:09 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-07-27 15:43:39 +0100 |
commit | 50bc490c090cc95175e6068ed7438788d7fd7040 (patch) | |
tree | 511c669a4a3da4fbc6ab2361144c222679110495 /gcc | |
parent | 9bd1ee6d330b0441c165d889b6b25a5c85caf427 (diff) | |
download | gcc-50bc490c090cc95175e6068ed7438788d7fd7040.zip gcc-50bc490c090cc95175e6068ed7438788d7fd7040.tar.gz gcc-50bc490c090cc95175e6068ed7438788d7fd7040.tar.bz2 |
libstdc++: Fix std::format alternate form for floating-point [PR108046]
A decimal point was being added to the end of the string for {:#.0}
because the __expc character was not being set, for the _Pres_none
presentation type, so __s.find(__expc) didn't the 'e' in "1e+01" and so
we created "1e+01." by appending the radix char to the end.
This can be fixed by ensuring that __expc='e' is set for the _Pres_none
case. I realized we can also set __expc='P' and __expc='E' when needed,
to save a call to std::toupper later.
For the {:#.0g} format, __expc='e' was being set and so the 'e' was
found in "1e+10" but then __z = __prec - __sigfigs would wraparound to
SIZE_MAX. That meant we would decide not to add a radix char because the
number of extra characters to insert would be 1+SIZE_MAX i.e. zero.
This can be fixed by using __z == 0 when __prec == 0.
libstdc++-v3/ChangeLog:
PR libstdc++/108046
* include/std/format (__formatter_fp::format): Ensure __expc is
always set for all presentation types. Set __z correctly for
zero precision.
* testsuite/std/format/functions/format.cc: Check problem cases.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions