From 8a7e5e8f843392c972293abb107d15d7efeebdda Mon Sep 17 00:00:00 2001 From: Alex Prabhat Bara Date: Fri, 31 Jan 2025 16:44:52 +0530 Subject: [PATCH 1/5] : Alternate form general floating-point width handling --- stl/inc/format | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/inc/format b/stl/inc/format index 53b960dbdd6..a54479bcbe8 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -2145,6 +2145,8 @@ _NODISCARD _OutputIt _Fmt_write( case 'g': if (_Precision == -1) { _Precision = 6; + } else if (_Precision == 0) { + _Precision = 1; } _Format = chars_format::general; break; From 05e3ae0d1983512e402fb74b2f25a5785a213d7b Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Sat, 1 Feb 2025 08:17:44 +0530 Subject: [PATCH 2/5] added test coverage --- .../env.lst | 4 ++++ .../test.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst create mode 100644 tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst new file mode 100644 index 00000000000..19f025bd0e6 --- /dev/null +++ b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_matrix.lst diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp new file mode 100644 index 00000000000..5763f565783 --- /dev/null +++ b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp @@ -0,0 +1,11 @@ +#include +#include +#include +using namespace std; + +int main() { + string expected = "[1.e-37]"; + string actual = format("[{:#6.0g}]", 1.234e-37); + assert(expected == actual); + return 0; +} From 86f9cfdf3688b823fc9c78029af7e8597352489a Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Sat, 1 Feb 2025 09:32:35 +0530 Subject: [PATCH 3/5] test coverage related changes --- tests/std/test.lst | 1 + .../env.lst | 2 +- .../test.cpp | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/std/test.lst b/tests/std/test.lst index 7093936102a..86d5eaaa7c8 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -784,3 +784,4 @@ tests\VSO_1804139_static_analysis_warning_with_single_element_array tests\VSO_1925201_iter_traits tests\VSO_2252142_wrong_C5046 tests\VSO_2318081_bogus_const_overloading +tests\GH_005011_format_alternate_form_general_floating_point_can_mishandle_width diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst index 19f025bd0e6..351a8293d9d 100644 --- a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst +++ b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_matrix.lst +RUNALL_INCLUDE ..\usual_20_matrix.lst diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp index 5763f565783..be1d07b455f 100644 --- a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp +++ b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp @@ -1,6 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include -#include +#include using namespace std; int main() { From 33277aa99dd5b6ac6882e5f62799b5257e6971f7 Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Sat, 1 Feb 2025 11:55:59 +0530 Subject: [PATCH 4/5] lexicographic ordering in test.lst --- tests/std/test.lst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/test.lst b/tests/std/test.lst index 86d5eaaa7c8..2d53335e902 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -253,6 +253,7 @@ tests\GH_004657_expected_constraints_permissive tests\GH_004845_logical_operator_traits_with_non_bool_constant tests\GH_004929_internal_tag_constructors tests\GH_004930_char_traits_user_specialization +tests\GH_005011_format_alternate_form_general_floating_point_can_mishandle_width tests\LWG2381_num_get_floating_point tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function @@ -784,4 +785,3 @@ tests\VSO_1804139_static_analysis_warning_with_single_element_array tests\VSO_1925201_iter_traits tests\VSO_2252142_wrong_C5046 tests\VSO_2318081_bogus_const_overloading -tests\GH_005011_format_alternate_form_general_floating_point_can_mishandle_width From a8750d8423c09faba76a53edb2f0d4bf5c8bf912 Mon Sep 17 00:00:00 2001 From: alexprabhatbara Date: Mon, 3 Feb 2025 11:00:19 +0530 Subject: [PATCH 5/5] expanded P0645R10_text_formatting_formatting test --- tests/std/test.lst | 1 - .../env.lst | 4 ---- .../test.cpp | 14 -------------- .../P0645R10_text_formatting_formatting/test.cpp | 1 + 4 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst delete mode 100644 tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp diff --git a/tests/std/test.lst b/tests/std/test.lst index 2d53335e902..7093936102a 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -253,7 +253,6 @@ tests\GH_004657_expected_constraints_permissive tests\GH_004845_logical_operator_traits_with_non_bool_constant tests\GH_004929_internal_tag_constructors tests\GH_004930_char_traits_user_specialization -tests\GH_005011_format_alternate_form_general_floating_point_can_mishandle_width tests\LWG2381_num_get_floating_point tests\LWG2597_complex_branch_cut tests\LWG3018_shared_ptr_function diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst deleted file mode 100644 index 351a8293d9d..00000000000 --- a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/env.lst +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -RUNALL_INCLUDE ..\usual_20_matrix.lst diff --git a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp b/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp deleted file mode 100644 index be1d07b455f..00000000000 --- a/tests/std/tests/GH_005011_format_alternate_form_general_floating_point_can_mishandle_width/test.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include -using namespace std; - -int main() { - string expected = "[1.e-37]"; - string actual = format("[{:#6.0g}]", 1.234e-37); - assert(expected == actual); - return 0; -} diff --git a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp index 4273f2f9909..a0b2e041bdf 100644 --- a/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_formatting/test.cpp @@ -835,6 +835,7 @@ void test_float_specs() { assert(format(STR("{:3}"), Float{0}) == STR(" 0")); assert(format(STR("{:#9G}"), Float{12.2}) == STR(" 12.2000")); assert(format(STR("{:#12g}"), Float{1'000'000}) == STR(" 1.00000e+06")); + assert(format(STR("[{:#6.0g}]"), 1.234e-37) == STR("[1.e-37]")); // Precision Float value = 1234.52734375;