diff --git a/stl/inc/format b/stl/inc/format index c2af86f05a..e5ac72dcc0 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -3095,7 +3095,7 @@ _NODISCARD _OutputIt _Fmt_write( switch (_Format) { case chars_format::hex: case chars_format::scientific: - if (_Extra_precision != 0) { + if (_Extra_precision != 0 && !_Specs._Alt && !_Specs._Localized) { // Trailing zeroes are in front of the exponent while (*--_Exponent_start != _Exponent) { } diff --git a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp index c6295a44c3..0b0b569f1c 100644 --- a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp @@ -1520,6 +1520,26 @@ void test_gh_4319() { assert(format(STR("{:}"), 12345678.0) == STR("12345678")); } +// GH-4320: : crash when formatting a floating-point value with #/L and a large precision +template +void test_gh_4320() { + assert( + format(STR("{:#.1075e}"), 1.0) + == STR( + "1." + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000e+00")); +} + void test() { test_simple_formatting(); test_simple_formatting(); @@ -1604,6 +1624,8 @@ void test() { test_gh_4319(); test_gh_4319(); + test_gh_4320(); + test_gh_4320(); } int main() {