diff --git a/stl/inc/xlocnum b/stl/inc/xlocnum index 617e42d051d..86c19b22c9c 100644 --- a/stl/inc/xlocnum +++ b/stl/inc/xlocnum @@ -1019,10 +1019,6 @@ private: _Seendigit = true; } - if (_Seendigit) { - *_Ptr++ = '0'; // put one back - } - for (size_t _Idx; _First != _Last && (_Idx = _STD _Find_elem(_Atoms, *_First)) < _Offset_dec_digit_end; _Seendigit = true, (void) ++_First) { if (_Exponent_part < PTRDIFF_MAX / 10 diff --git a/tests/std/tests/LWG2381_num_get_floating_point/test.cpp b/tests/std/tests/LWG2381_num_get_floating_point/test.cpp index f6c03babb5d..7f0615f97e2 100644 --- a/tests/std/tests/LWG2381_num_get_floating_point/test.cpp +++ b/tests/std/tests/LWG2381_num_get_floating_point/test.cpp @@ -532,6 +532,23 @@ void test_gh_3378() { } } +// Also test GH-3980 : Wrong reading of float values +template +void test_gh_3980() { + auto test_case = [](const char* str, double expected) { + Flt val = 0; + istringstream{str} >> val; + assert((ostringstream{} << val).str() == (ostringstream{} << expected).str()); + }; + + test_case("0x1p+07", 0x1p+07); + test_case("1e+07", 1e+07); + test_case("1e+0", 1); + test_case("1e-0", 1); + test_case("1e-07", 1e-07); + test_case("0x1p-07", 0x1p-07); +} + #if _HAS_CXX17 void test_float_from_char_cases() { for (const auto& test_case : float_from_chars_test_cases) { @@ -589,6 +606,10 @@ int main() { test_gh_3378(); test_gh_3378(); + test_gh_3980(); + test_gh_3980(); + test_gh_3980(); + #if _HAS_CXX17 test_float_from_char_cases(); test_double_from_char_cases();