Skip to content
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
4 changes: 0 additions & 4 deletions stl/inc/xlocnum
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,6 @@ private:
_Seendigit = true;
}

if (_Seendigit) {
*_Ptr++ = '0'; // put one back
}

Comment thread
achabense marked this conversation as resolved.
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
Expand Down
21 changes: 21 additions & 0 deletions tests/std/tests/LWG2381_num_get_floating_point/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,23 @@ void test_gh_3378() {
}
}

// Also test GH-3980 <iostream>: Wrong reading of float values
template <class Flt>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth resetting testing: vwls pls.
Flt isn't that much shorter than Float. If you want a descriptive name, be descriptive. If you want a short name, T would work fine here and honestly std::floating_point T (or static_assert(std::is_floating_point_v<T>) in the function body) would be even better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Float specifically is dangerous due to the potential confusion with float. Floating or any other name avoids that hazard.

void test_gh_3980() {
auto test_case = [](const char* str, double expected) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth resetting testing: there are a log of strs floating around here, it might be nice to call this parameter "input" or something.

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) {
Expand Down Expand Up @@ -589,6 +606,10 @@ int main() {
test_gh_3378<double>();
test_gh_3378<long double>();

test_gh_3980<float>();
test_gh_3980<double>();
test_gh_3980<long double>();

#if _HAS_CXX17
test_float_from_char_cases();
test_double_from_char_cases<double>();
Expand Down