Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.

91. Description of operator>> and getline() for string<> might cause endless loop

Section: 27.4.4.4[string.io]Status:CD1Submitter: Nico JosuttisOpened: 1998-09-29Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [string.io].

View all issues withCD1 status.

Discussion:

Operator >> and getline() for strings read until eof()in the input stream is true. However, this might never happen, if thestream can't read anymore without reaching EOF. So shouldn't it bechanged into that it reads until !good() ?

Proposed resolution:

In 27.4.4.4[string.io], paragraph 1, replace:

Effects: Begins by constructing a sentry object k as if k wereconstructed by typename basic_istream<charT,traits>::sentry k( is). Ifbool( k) is true, it calls str.erase() and then extracts charactersfrom is and appends them to str as if by calling str.append(1, c). Ifis.width() is greater than zero, the maximum number n of charactersappended is is.width(); otherwise n is str.max_size(). Characters areextracted and appended until any of the following occurs:

with:

Effects: Behaves as a formatted input function (31.7.5.3.1[istream.formatted.reqmts]). After constructing a sentry object, if thesentry converts to true, calls str.erase() and then extractscharacters from is and appends them to str as if by callingstr.append(1,c). If is.width() is greater than zero, the maximumnumber n of characters appended is is.width(); otherwise n isstr.max_size(). Characters are extracted and appended until any of thefollowing occurs:

In 27.4.4.4[string.io], paragraph 6, replace

Effects: Begins by constructing a sentry object k as if by typenamebasic_istream<charT,traits>::sentry k( is, true). If bool( k) is true,it calls str.erase() and then extracts characters from is and appendsthem to str as if by calling str.append(1, c) until any of thefollowing occurs:

with:

Effects: Behaves as an unformatted input function (31.7.5.4[istream.unformatted]), except that it does not affect the value returnedby subsequent calls to basic_istream<>::gcount(). Afterconstructing a sentry object, if the sentry converts to true, callsstr.erase() and then extracts characters from is and appends them tostr as if by calling str.append(1,c) until any of the followingoccurs:

[Redmond: Made changes in proposed resolution.operator>>should be a formatted input function, not an unformatted input function.getline should not be required to setgcount, sincethere is no mechanism forgcount to be set except by one ofbasic_istream's member functions.]

[Curaçao: Nico agrees with proposed resolution.]

Rationale:

The real issue here is whether or not these string input functionsget their characters from a streambuf, rather than by calling anistream's member functions, a streambuf signals failure either byreturning eof or by throwing an exception; there are no otherpossibilities. The proposed resolution makes it clear that these twofunctions do get characters from a streambuf.


[8]ページ先頭

©2009-2026 Movatter.jp