diff options
author | Tomasz Kamiński <tkaminsk@redhat.com> | 2025-04-25 20:10:52 +0200 |
---|---|---|
committer | Tomasz Kamiński <tkaminsk@redhat.com> | 2025-04-30 06:13:11 +0200 |
commit | 2ca5725e104d432317a44ad45183a4f555da3b82 (patch) | |
tree | e75e3574c56e237ed34993d1890c64964a9f60d1 /libstdc++-v3/testsuite/std | |
parent | 55b01e17c793688a2878fa43a76df1266153b438 (diff) | |
download | gcc-2ca5725e104d432317a44ad45183a4f555da3b82.zip gcc-2ca5725e104d432317a44ad45183a4f555da3b82.tar.gz gcc-2ca5725e104d432317a44ad45183a4f555da3b82.tar.bz2 |
libstdc++: Fix _Padding_sink in case when predicted width is between padwidth and maxwidth [PR109162]
The _Padding_sink was behaving incorrectly, when the predicted width (based on
code units count) was higher than _M_maxwidth, but lower than _M_padwidth.
In this case _M_update() returned without calling _M_force_update() and computing
field width for Unicode encoding, because _M_buffering() returned 'true'.
As a consequence we switched to _M_ignoring() mode, while storing a sequence
with more code units but smaller field width than _M_maxwidth.
We now call _M_force_update() if predicted width is greater or equal to either
_M_padwidth or _M_maxwidth.
This happened for existing test case on 32bit architecture.
PR libstdc++/109162
libstdc++-v3/ChangeLog:
* include/std/format (_Padding_sink::_M_update): Fixed condition for
calling _M_force_update.
* testsuite/std/format/debug.cc: Add test that reproduces this issue
on 64bit architecture.
* testsuite/std/format/ranges/sequence.cc: Another edge value test.
Diffstat (limited to 'libstdc++-v3/testsuite/std')
-rw-r--r-- | libstdc++-v3/testsuite/std/format/debug.cc | 9 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/std/format/ranges/sequence.cc | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/std/format/debug.cc b/libstdc++-v3/testsuite/std/format/debug.cc index d3402f8..6165a29 100644 --- a/libstdc++-v3/testsuite/std/format/debug.cc +++ b/libstdc++-v3/testsuite/std/format/debug.cc @@ -596,6 +596,10 @@ void test_padding() VERIFY( strip_prefix(resv, 48, '*') ); VERIFY( resv == inv ); + resv = res = std::format("{:*>300.200s}", in); + VERIFY( strip_prefix(resv, 108, '*') ); + VERIFY( resv == inv ); + resv = res = std::format("{:*>240.200s}", in); VERIFY( strip_prefix(resv, 48, '*') ); VERIFY( resv == inv ); @@ -678,6 +682,11 @@ void test_padding() VERIFY( strip_quotes(resv) ); VERIFY( resv == inv ); + resv = res = std::format("{:*>300.200?}", in); + VERIFY( strip_prefix(resv, 106, '*') ); + VERIFY( strip_quotes(resv) ); + VERIFY( resv == inv ); + resv = res = std::format("{:*>240.200?}", in); VERIFY( strip_prefix(resv, 46, '*') ); VERIFY( strip_quotes(resv) ); diff --git a/libstdc++-v3/testsuite/std/format/ranges/sequence.cc b/libstdc++-v3/testsuite/std/format/ranges/sequence.cc index 75fe4c1..3224286 100644 --- a/libstdc++-v3/testsuite/std/format/ranges/sequence.cc +++ b/libstdc++-v3/testsuite/std/format/ranges/sequence.cc @@ -295,6 +295,15 @@ void test_padding() resv = res = std::format("{:*>10n:}", vs); VERIFY( check_elems(resv, false) ); + resv = res = std::format("{:*>256}", vs); + VERIFY( strip_prefix(resv, 48, '*') ); + VERIFY( strip_squares(resv) ); + VERIFY( check_elems(resv, true) ); + + resv = res = std::format("{:*>256n}", vs); + VERIFY( strip_prefix(resv, 50, '*') ); + VERIFY( check_elems(resv, true) ); + resv = res = std::format("{:*>240}", vs); VERIFY( strip_prefix(resv, 32, '*') ); VERIFY( strip_squares(resv) ); |