[llvm-bugs] [Bug 39012] New: ostream writes a double that istream can't read

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 20 01:02:07 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39012

            Bug ID: 39012
           Summary: ostream writes a double that istream can't read
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: daniel.cooke at me.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

It appears libc++ incorrectly sets input stream failbit when reading subnormal
floating point numbers. Here's an example:

#include <iostream>
#include <string>
#include <sstream>

int main()
{
    constexpr double x {1e-320};
    std::ostringstream oss {};
    oss << x;
    const auto str_x = oss.str();
    std::istringstream iss {str_x};
    double y;
    if (iss >> y) {
        std::cout << y << std::endl;
    } else {
        std::cout << "Nope" << std::endl;
    }
}

Compiling with Clang/libc++, results in "Nope" being printed, while with
GCC/libstdc++, the value of the double is printed - as I would expect.

I also reported this behaviour in StackOverflow:
https://stackoverflow.com/questions/52410931/why-does-clang-stdostream-write-a-double-that-stdistream-cant-read.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180920/9be85feb/attachment.html>


More information about the llvm-bugs mailing list