Skip to content

Commit d8ed990

Browse files
burblebeetkoeppe
authored andcommitted
P1264R2 Revising the wording of stream input operations
Partially fixes NB FR 004 (C++23 CD).
1 parent cceac72 commit d8ed990

File tree

3 files changed

+88
-149
lines changed

3 files changed

+88
-149
lines changed

source/iostreams.tex

Lines changed: 76 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,32 +4391,6 @@
43914391
They may use other public members of
43924392
\tcode{istream}.
43934393

4394-
\pnum
4395-
If
4396-
\tcode{rdbuf()->sbumpc()}
4397-
or
4398-
\tcode{rdbuf()->sgetc()}
4399-
returns
4400-
\tcode{traits::eof()},
4401-
then the input function, except as explicitly noted otherwise, completes its actions and does
4402-
\tcode{setstate(eofbit)},
4403-
which may throw
4404-
\tcode{ios_base::failure}\iref{iostate.flags}, before returning.
4405-
4406-
\pnum
4407-
If one of these called functions throws an exception, then unless explicitly noted otherwise,
4408-
the input function sets
4409-
\tcode{badbit}
4410-
in the error state.
4411-
If
4412-
\tcode{badbit}
4413-
is set in
4414-
\tcode{exceptions()},
4415-
the input function
4416-
rethrows the exception without completing its actions, otherwise
4417-
it does not throw anything and proceeds as if the called function had returned
4418-
a failure indication.
4419-
44204394
\rSec4[istream.cons]{Constructors}
44214395

44224396
\indexlibraryctor{basic_istream}%
@@ -4647,7 +4621,10 @@
46474621
\rSec4[istream.formatted.reqmts]{Common requirements}
46484622

46494623
\pnum
4650-
Each formatted input function begins execution by constructing an object of class
4624+
Each formatted input function begins execution by constructing
4625+
an object of type \tcode{ios_base::iostate}, termed the local error state, and
4626+
initializing it to \tcode{ios_base::goodbit}.
4627+
It then creates an object of class
46514628
\tcode{sentry}
46524629
with the
46534630
\tcode{noskipws}
@@ -4661,20 +4638,22 @@
46614638
\tcode{bool},
46624639
the function endeavors
46634640
to obtain the requested input.
4641+
Otherwise,
4642+
if the \tcode{sentry} constructor exits by throwing an exception or
4643+
if the \tcode{sentry} object produces \tcode{false}
4644+
when converted to a value of type \tcode{bool},
4645+
the function returns without attempting to obtain any input.
4646+
If \tcode{rdbuf()->sbumpc()} or \tcode{rdbuf()->sgetc()}
4647+
returns \tcode{traits::eof()}, then
4648+
\tcode{ios_base::eofbit} is set in the local error state and
4649+
the input function stops trying to obtain the requested input.
46644650
If an exception is thrown during input then
4665-
\tcode{ios_base::badbit}
4666-
is turned on
4667-
\begin{footnote}
4668-
This is done without causing an
4669-
\tcode{ios_base::failure}
4670-
to be thrown.
4671-
\end{footnote}
4672-
in
4673-
\tcode{*this}'s
4674-
error state.
4675-
If
4676-
\tcode{(exceptions()\&badbit) != 0}
4677-
then the exception is rethrown.
4651+
\tcode{ios_base::badbit} is set in the local error state,
4652+
\tcode{*this}'s error state is set to the local error state, and
4653+
the exception is rethrown if \tcode{(exceptions() \& badbit) != 0}.
4654+
After extraction is done, the input function calls \tcode{setstate}, which
4655+
sets \tcode{*this}'s error state to the local error state, and
4656+
may throw an exception.
46784657
In any case, the formatted input function destroys the
46794658
\tcode{sentry}
46804659
object.
@@ -4705,12 +4684,11 @@
47054684
\tcode{num_get<>}\iref{locale.num.get} object to perform parsing the input
47064685
stream data.
47074686
These extractors behave as formatted input functions (as described in~\ref{istream.formatted.reqmts}). After a \tcode{sentry} object is constructed, the
4708-
conversion occurs as if performed by the following code fragment:
4687+
conversion occurs as if performed by the following code fragment,
4688+
where \tcode{state} represents the input function's local error state:
47094689
\begin{codeblock}
47104690
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
4711-
iostate err = iostate::goodbit;
4712-
use_facet<numget>(loc).get(*this, 0, *this, err, val);
4713-
setstate(err);
4691+
use_facet<numget>(loc).get(*this, 0, *this, state, val);
47144692
\end{codeblock}
47154693
In the above fragment,
47164694
\tcode{loc}
@@ -4743,18 +4721,16 @@
47434721
(using the same notation as for the preceding code fragment):
47444722
\begin{codeblock}
47454723
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
4746-
iostate err = ios_base::goodbit;
47474724
long lval;
4748-
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
4725+
use_facet<numget>(loc).get(*this, 0, *this, state, lval);
47494726
if (lval < numeric_limits<short>::min()) {
4750-
err |= ios_base::failbit;
4727+
state |= ios_base::failbit;
47514728
val = numeric_limits<short>::min();
47524729
} else if (numeric_limits<short>::max() < lval) {
4753-
err |= ios_base::failbit;
4730+
state |= ios_base::failbit;
47544731
val = numeric_limits<short>::max();
47554732
} else
47564733
val = static_cast<short>(lval);
4757-
setstate(err);
47584734
\end{codeblock}
47594735
\end{itemdescr}
47604736

@@ -4769,18 +4745,16 @@
47694745
(using the same notation as for the preceding code fragment):
47704746
\begin{codeblock}
47714747
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
4772-
iostate err = ios_base::goodbit;
47734748
long lval;
4774-
use_facet<numget>(loc).get(*this, 0, *this, err, lval);
4749+
use_facet<numget>(loc).get(*this, 0, *this, state, lval);
47754750
if (lval < numeric_limits<int>::min()) {
4776-
err |= ios_base::failbit;
4751+
state |= ios_base::failbit;
47774752
val = numeric_limits<int>::min();
47784753
} else if (numeric_limits<int>::max() < lval) {
4779-
err |= ios_base::failbit;
4754+
state |= ios_base::failbit;
47804755
val = numeric_limits<int>::max();
47814756
} else
47824757
val = static_cast<int>(lval);
4783-
setstate(err);
47844758
\end{codeblock}
47854759
\end{itemdescr}
47864760

@@ -4818,19 +4792,17 @@
48184792
(using the same notation as for the preceding code fragment):
48194793
\begin{codeblock}
48204794
using numget = num_get<charT, istreambuf_iterator<charT, traits>>;
4821-
iostate err = ios_base::goodbit;
48224795
FP fval;
4823-
use_facet<numget>(loc).get(*this, 0, *this, err, fval);
4796+
use_facet<numget>(loc).get(*this, 0, *this, state, fval);
48244797
if (fval < -numeric_limits<@\placeholder{extended-floating-point-type}@>::max()) {
4825-
err |= ios_base::failbit;
4798+
state |= ios_base::failbit;
48264799
val = -numeric_limits<@\placeholder{extended-floating-point-type}@>::max();
48274800
} else if (numeric_limits<@\placeholder{extended-floating-point-type}@>::max() < fval) {
4828-
err |= ios_base::failbit;
4801+
state |= ios_base::failbit;
48294802
val = numeric_limits<@\placeholder{extended-floating-point-type}@>::max();
48304803
} else {
48314804
val = static_cast<@\placeholder{extended-floating-point-type}@>(fval);
48324805
}
4833-
setstate(err);
48344806
\end{codeblock}
48354807
\begin{note}
48364808
When the extended floating-point type has
@@ -4954,10 +4926,9 @@
49544926
\tcode{width(0)}.
49554927

49564928
\pnum
4957-
If the function extracted no characters, it calls
4958-
\tcode{setstate(failbit)},
4959-
which may throw
4960-
\tcode{ios_base::\brk{}failure}\iref{iostate.flags}.
4929+
If the function extracted no characters,
4930+
\tcode{ios_base::failbit} is set in the input function's local error state
4931+
before \tcode{setstate} is called.
49614932

49624933
\pnum
49634934
\returns
@@ -4979,12 +4950,10 @@
49794950
\effects
49804951
Behaves like a formatted input member (as described in~\ref{istream.formatted.reqmts})
49814952
of \tcode{in}.
4982-
After a
4983-
\tcode{sentry}
4984-
object is constructed
4985-
a character is extracted from \tcode{in}, if one is available, and stored in \tcode{c}.
4986-
Otherwise, the function calls
4987-
\tcode{in.setstate(fail\-bit)}.
4953+
A character is extracted from \tcode{in}, if one is available, and stored in \tcode{c}.
4954+
Otherwise,
4955+
\tcode{ios_base::failbit} is set in the input function's local error state
4956+
before \tcode{setstate} is called.
49884957

49894958
\pnum
49904959
\returns
@@ -5020,18 +4989,9 @@
50204989
\end{itemize}
50214990

50224991
\pnum
5023-
If the function inserts no characters, it calls
5024-
\tcode{setstate(failbit)},
5025-
which may throw
5026-
\tcode{ios_base::\brk{}failure}\iref{iostate.flags}.
5027-
If it inserted no characters because it caught
5028-
an exception thrown while extracting characters from
5029-
\tcode{*this}
5030-
and
5031-
\tcode{failbit}
5032-
is set in
5033-
\tcode{exceptions()}\iref{iostate.flags},
5034-
then the caught exception is rethrown.
4992+
If the function inserts no characters,
4993+
\tcode{ios_base::failbit} is set in the input function's local error state
4994+
before \tcode{setstate} is called.
50354995

50364996
\pnum
50374997
\returns
@@ -5041,7 +5001,10 @@
50415001
\rSec3[istream.unformatted]{Unformatted input functions}
50425002

50435003
\pnum
5044-
Each unformatted input function begins execution by constructing an object of class
5004+
Each unformatted input function begins execution by constructing
5005+
an object of type \tcode{ios_base::iostate}, termed the local error state, and
5006+
initializing it to \tcode{ios_base::goodbit}.
5007+
It then creates an object of class
50455008
\tcode{sentry}
50465009
with the default argument
50475010
\tcode{noskipws}
@@ -5056,35 +5019,28 @@
50565019
the function endeavors
50575020
to obtain the requested input.
50585021
Otherwise, if the \tcode{sentry} constructor exits by throwing an exception or if
5059-
the \tcode{sentry} object returns \tcode{false}, when converted to a value of type
5022+
the \tcode{sentry} object produces \tcode{false}, when converted to a value of type
50605023
\tcode{bool},
50615024
the function returns without attempting to obtain any input.
50625025
In either case the number of extracted characters is set to 0;
50635026
unformatted input functions taking a character array of nonzero size as
50645027
an argument shall also store a null character (using
50655028
\tcode{charT()})
50665029
in the first location of the array.
5030+
If \tcode{rdbuf()->sbumpc()} or \tcode{rdbuf()->sgetc()}
5031+
returns \tcode{traits::eof()}, then
5032+
\tcode{ios_base::eofbit} is set in the local error state and
5033+
the input function stops trying to obtain the requested input.
50675034
If an exception is thrown during input then
5068-
\tcode{ios_base::badbit}
5069-
is turned on
5070-
\begin{footnote}
5071-
This is done without causing an
5072-
\tcode{ios_base::failure}
5073-
to be thrown.
5074-
\end{footnote}
5075-
in
5076-
\tcode{*this}'s
5077-
error state.
5078-
(Exceptions thrown from
5079-
\tcode{basic_ios<>::clear()}
5080-
are not caught or rethrown.)
5081-
If
5082-
\tcode{(exceptions()\&badbit) != 0}
5083-
then the exception is rethrown.
5084-
It also counts the number of characters extracted.
5085-
If no exception has been thrown it ends
5086-
by storing the count in a member object
5087-
and returning the value specified.
5035+
\tcode{ios_base::badbit} is set in the local error state,
5036+
\tcode{*this}'s error state is set to the local error state, and
5037+
the exception is rethrown if \tcode{(exceptions() \& badbit) != 0}.
5038+
If no exception has been thrown it
5039+
stores the number of characters extracted
5040+
in a member object.
5041+
After extraction is done, the input function calls \tcode{setstate}, which
5042+
sets \tcode{*this}'s error state to the local error state, and
5043+
may throw an exception.
50885044
In any event the
50895045
\tcode{sentry}
50905046
object
@@ -5122,10 +5078,9 @@
51225078
(as described above).
51235079
After constructing a \tcode{sentry} object, extracts
51245080
a character \tcode{c}, if one is available.
5125-
Otherwise, the function calls
5126-
\tcode{setstate(failbit)},
5127-
which may throw
5128-
\tcode{ios_base::failure}\iref{iostate.flags}.
5081+
Otherwise,
5082+
\tcode{ios_base::failbit} is set in the input function's local error state
5083+
before \tcode{setstate} is called.
51295084

51305085
\pnum
51315086
\returns
@@ -5153,10 +5108,9 @@
51535108
and
51545109
\tcode{unsigned char}.
51555110
\end{footnote}
5156-
Otherwise, the function calls
5157-
\tcode{setstate(failbit)}
5158-
(which may throw
5159-
\tcode{ios_base::failure}\iref{iostate.flags}).
5111+
Otherwise,
5112+
\tcode{ios_base::failbit} is set in the input function's local error state
5113+
before \tcode{setstate} is called.
51605114

51615115
\pnum
51625116
\returns
@@ -5189,9 +5143,7 @@
51895143
\tcode{n} is less than one or \tcode{n - 1}
51905144
characters are stored;
51915145
\item
5192-
end-of-file occurs on the input sequence
5193-
(in which case the function calls
5194-
\tcode{setstate(eofbit)});
5146+
end-of-file occurs on the input sequence;
51955147
\item
51965148
\tcode{traits::eq(c, delim)}
51975149
for the next available input
@@ -5200,10 +5152,9 @@
52005152
\end{itemize}
52015153

52025154
\pnum
5203-
If the function stores no characters, it calls
5204-
\tcode{setstate(failbit)}
5205-
(which may throw
5206-
\tcode{ios_base::\brk{}failure}\iref{iostate.flags}).
5155+
If the function stores no characters,
5156+
\tcode{ios_base::failbit} is set in the input function's local error state
5157+
before \tcode{setstate} is called.
52075158
In any case, if \tcode{n} is greater than zero it then stores a null character
52085159
into the next successive location of the array.
52095160

@@ -5259,10 +5210,9 @@
52595210
\end{itemize}
52605211

52615212
\pnum
5262-
If the function inserts no characters, it calls
5263-
\tcode{setstate(failbit)},
5264-
which may throw
5265-
\tcode{ios_base::\brk{}failure}\iref{iostate.flags}.
5213+
If the function inserts no characters,
5214+
\tcode{ios_base::failbit} is set in the input function's local error state
5215+
before \tcode{setstate} is called.
52665216

52675217
\pnum
52685218
\returns
@@ -5308,9 +5258,7 @@
53085258
Characters are extracted and stored until one of the following occurs:
53095259
\begin{enumerate}
53105260
\item
5311-
end-of-file occurs on the input sequence
5312-
(in which case the function calls
5313-
\tcode{setstate(eofbit)});
5261+
end-of-file occurs on the input sequence;
53145262
\item
53155263
\tcode{traits::eq(c, delim)}
53165264
for the next available input
@@ -5340,10 +5288,9 @@
53405288
\end{footnote}
53415289

53425290
\pnum
5343-
If the function extracts no characters, it calls
5344-
\tcode{setstate(failbit)}
5345-
(which may throw
5346-
\tcode{ios_base::\brk{}failure}\iref{iostate.flags}).
5291+
If the function extracts no characters,
5292+
\tcode{ios_base::failbit} is set in the input function's local error state
5293+
before \tcode{setstate} is called.
53475294
\begin{footnote}
53485295
This implies an
53495296
empty input line will not cause

0 commit comments

Comments
 (0)