Issue 180495
Summary libc++ implementation of basic_filebuf::sync() doesn't ensure a call to overflow()
Labels libc++
Assignees
Reporter Bhramar-vatsa
    The standard states that the function [std::basic_filebuf<CharT,Traits>::sync()](https://en.cppreference.com/w/cpp/io/basic_filebuf/sync.html) will always call [std::basic_streambuf<CharT,Traits>::overflow()](https://en.cppreference.com/w/cpp/io/basic_streambuf/overflow.html) (actually should be [an overridden version ](https://github.com/llvm/llvm-project/blob/a07347f60997b971314563c7427aff5153677d95/libcxx/include/fstream#L843) within std::basic_filebuf):
- https://en.cppreference.com/w/cpp/io/basic_filebuf/sync.html
- https://isocpp.org/files/papers/N4860.pdf#page=1438

But in the [implementation of libcxx/include/fstream](https://github.com/llvm/llvm-project/blob/a07347f60997b971314563c7427aff5153677d95/libcxx/include/fstream#L1031C5-L1031C39) (any version), the call to overflow() is always conditional:

```
  if (__cm_ & ios_base::out) {
    if (this->pptr() != this->pbase())    // Should be removed?
      if (overflow() == traits_type::eof())
 return -1;
```
It seems wrong and a test specifically written to test this pedantic behavior will fail. This can be seen in this godbolt example: https://godbolt.org/z/ss8cqqqTo (with GNU standard library, it passes).

The resolution to this issue should be simply the removal of that condition.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to