[PATCH] D51268: [libc++] Implement P0487R1 - Fixing operator>>(basic_istream&, CharT*)
Louis Dionne via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 19 10:59:18 PST 2018
ldionne accepted this revision.
ldionne added inline comments.
This revision is now accepted and ready to land.
================
Comment at: include/istream:601
+ streamsize __n = __is.width();
+ if (__n <= 0)
+ __n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
----------------
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`.
Repository:
rCXX libc++
https://reviews.llvm.org/D51268
More information about the cfe-commits
mailing list