Skip to content

Fix the incorrect width that occurred when formatting a floating number in the locale specific form #4421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,7 @@ _NODISCARD _OutputIt _Fmt_write(
if (_Specs._Localized) {
_Groups = _STD use_facet<numpunct<_CharT>>(_Locale._Get()).grouping();
_Separators = _Count_separators(static_cast<size_t>(_Integral_end - _Buffer_start), _Groups);
_Width += _Separators;
}
}

Expand Down
4 changes: 0 additions & 4 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,6 @@ std/input.output/string.streams/stringbuf/stringbuf.members/view.pass.cpp FAIL
std/input.output/syncstream/syncbuf/syncstream.syncbuf.cons/dtor.pass.cpp FAIL
std/input.output/syncstream/syncbuf/syncstream.syncbuf.members/emit.pass.cpp FAIL

# GH-4316: <format>: The width of output is miscalculated when formatting a floating-point number in the locale-specific form
std/input.output/iostream.format/output.streams/ostream.formatted/ostream.formatted.print/locale-specific_form.pass.cpp FAIL
std/utilities/format/format.functions/locale-specific_form.pass.cpp FAIL


# *** VCRUNTIME BUGS ***
# DevCom-10373274 VSO-1824997 "vcruntime nothrow array operator new falls back on the wrong function"
Expand Down
13 changes: 13 additions & 0 deletions tests/std/tests/P0645R10_text_formatting_formatting/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,14 @@ constexpr bool test_format_string() {
return true;
}

// Also test GH-4316 <format>: The width of output is miscalculated
// when formatting a floating-point number in the locale-specific form
template <class charT>
void test_gh_4316() {
assert(format(locale{"en-US"}, STR("{:@>8L}"), 12345) == STR("@@12,345"));
assert(format(locale{"en-US"}, STR("{:@>8L}"), 12345.0) == STR("@@12,345"));
}

// Also test GH-4319: incorrect output for some floating-point values
template <class charT>
void test_gh_4319() {
Expand Down Expand Up @@ -1589,6 +1597,11 @@ void test() {
test_localized_char<wchar_t, char>();
test_localized_char<wchar_t, wchar_t>();

#if !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING
test_gh_4316<char>();
test_gh_4316<wchar_t>();
#endif // !defined(_DLL) || _ITERATOR_DEBUG_LEVEL == DEFAULT_IDL_SETTING

test_gh_4319<char>();
test_gh_4319<wchar_t>();
}
Expand Down