This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.
Section: 22.214.171.124 [istream.unformatted] Status: CD1 Submitter: Martin Sebor Opened: 2005-11-23 Last modified: 2016-02-10
Priority: Not Prioritized
View all other issues in [istream.unformatted].
View all issues with CD1 status.
The array forms of unformatted input functions don't seem to have well-defined semantics for zero-element arrays in a couple of cases. The affected ones (istream::get() and istream::getline()) are supposed to terminate when (n - 1) characters are stored, which obviously can never be true when (n == 0) holds to start with. See c++std-lib-16071.
I suggest changing 126.96.36.199, p7 (istream::get()), bullet 1 to read:
Change 188.8.131.52, p9:
If the function stores no characters, it calls setstate(failbit) (which may throw ios_base::failure (184.108.40.206)). In any case, it then stores a null character into the next successive location of the array.
and similarly p17 (istream::getline()), bullet 3 to:
In addition, to clarify that istream::getline() must not store the terminating NUL character unless the the array has non-zero size, Robert Klarer suggests in c++std-lib-16082 to change 220.127.116.11, p20 to read:
In any case, provided (n > 0) is true, it then stores a null character (using charT()) into the next successive location of the array.
[ post-Redmond: Pete noticed that the current resolution for get requires writing to out of bounds memory when n == 0. Martin provided fix. ]