Mark de Wever 54daf6af57
[libc++] Fixes istream::sync. (#76467)
This fixes two issues.

The return value
----------------

Based on the wording

[istream.unformatted]/37
Effects: Behaves as an unformatted input function (as described above),
  except that it does not count the number of characters extracted and
  does not affect the value returned by subsequent calls to gcount().
  After constructing a sentry object, if rdbuf() is a null pointer,
  returns -1.

[istream.unformatted]/1
... It then creates an object of class sentry with the default argument
noskipws (second) argument true. If the sentry object returns true, when
converted to a value of type bool, the function endeavors to obtain the
  requested input. ...

It could be argued the current behaviour is correct, however
constructing a istream rdbuf() == nullptr creates a sentry that returns
false; its state is always bad in this case.

As mentioned in the bug report, after this change the 3 major
implementations behave the same.

The setting of the state
------------------------

When pubsync returned -1 it updated the local __state variable and
returned. This early return caused the state up the istream not to be
updated to the new state.

Fixes: https://github.com/llvm/llvm-project/issues/51497
Fixes: https://github.com/llvm/llvm-project/issues/51499

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-02-18 17:20:49 +01:00
..