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

            Bug ID: 52155
           Summary: Calling sync() when rdbuf() is a null pointer should
                    return -1.
           Product: libc++
           Version: 11.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

The Standard doc for the sync() function states:
if rdbuf() is a null pointer, returns -1.

It appears libc++ is missing this check.   

Here's a cut/paste from a cygwin session:

$ cat t1.cpp
#include <istream>
extern "C" int printf(const char *a,...);
using namespace std;
int main() {
  istream x(0);
  int s = x.sync();
  printf("value is %d\n",s);
}

VogelEd@XLB3502Q4E ~/tests
$ clang++  t1.cpp -o a.out

VogelEd@XLB3502Q4E ~/tests
$ ./a.out
value is -1

VogelEd@XLB3502Q4E ~/tests
$ clang++  -stdlib=libc++ t1.cpp -o a.out                                       
VogelEd@XLB3502Q4E ~/tests
$ ./a.out
value is 0


Note that the g++ library gets this right, but libc++ does not.  Visual Studio
2019 also gives the correct answer.

Not a big deal, but I thought I'd post it.

Thanks,

Ed Vogel

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to