[PATCH] D51268: [libc++] Implement P0487R1 - Fixing operator>>(basic_istream&, CharT*)

Zhihao Yuan via Phabricator reviews at reviews.llvm.org
Mon Nov 19 22:41:13 PST 2018

lichray added a comment.

In https://reviews.llvm.org/D51268#1303217, @ldionne wrote:

> Please also update https://libcxx.llvm.org/cxx2a_status.html.


Comment at: include/istream:601
+    streamsize __n = __is.width();
+    if (__n <= 0)
+        __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
ldionne wrote:
> Should this instead be `if (__n == 0)`? Can `width()` ever return a negative number? cppreference says this about `streamsize`:
> > Except in the constructors of `std::strstreambuf`, negative values of `std::streamsize` are never used.
> I couldn't find a matching statement in the standard, however there's this footnote in `30.5.2`:
> > `streamsize` is used in most places where ISO C would use `size_t`. Most of the uses of `streamsize` could use `size_t`, except for the `strstreambuf` constructors, which require negative values. It should probably be the signed type corresponding to `size_t` (which is what Posix.2 calls `ssize_t`).
> This does not clearly say that negative values are never used, but it does suggest it. Maybe it's safer to still use `__n <= 0`.
My interpretation of is that you can retrieve the value you set through `width(streamsize)`.  And the wording here (unmodified) says "If `width()` is greater than zero, [...]," so the opposite should be `width() <= 0`.

  rCXX libc++


More information about the libcxx-commits mailing list