You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (; _Zeroes_to_append > 0; --_Zeroes_to_append) {
*_Out++ = '0';
}
However, we need to completely understand the problem and all possible codepaths before developing a fix (i.e. we can't just clamp it to zero and call it a day). Note that the chars_format::general codepath further adjusts _Zeroes_to_append:
For the g specifier (which corresponds to chars_format::general, which corresponds to printf's %g), a precision of 0 should behave as if it were 1. It seems that we are missing this adjustment.
Reported to me by Attila Feher. https://godbolt.org/z/djh5KxjW6
libstdc++ and libc++ behave as expected, but MSVC prints:
🕵️ Analysis
I debugged into this, and although I'm not absolutely certain of the root cause yet, this line appears to be involved:
STL/stl/inc/format
Line 2278 in 926d458
_Zeroes_to_append
is computed as-1
because_Extra_precision
and_Precision
are both0
, and_Digits
is1
.We've correctly computed
_Width
to be6
, but the negative_Zeroes_to_append
damages it, which appears to be the proximate cause of the bug:STL/stl/inc/format
Line 2297 in 926d458
Later, we use
_Zeroes_to_append
in a clamped manner (i.e. negative values are treated as zero):STL/stl/inc/format
Lines 2328 to 2330 in 926d458
However, we need to completely understand the problem and all possible codepaths before developing a fix (i.e. we can't just clamp it to zero and call it a day). Note that the
chars_format::general
codepath further adjusts_Zeroes_to_append
:STL/stl/inc/format
Lines 2278 to 2289 in 926d458
The text was updated successfully, but these errors were encountered: