Created on 2009-07-28.00:00:00 last changed 161 months ago
Rationale:
We believe that setting a nullptr stream buffer can be prevented.
Proposed resolution:
void set_rdbuf(basic_streambuf<charT, traits>* sb);?? Requires: sb != nullptr.
23 Effects: Associates the basic_streambuf object pointed to by sb with this stream without calling clear().24 Postconditions: rdbuf() == sb.
25 Throws: Nothing.
[ Adopted at 2010-11 Batavia ]
[ Post-Rapperswil ]
Several reviewers and the submitter believe that the best solution would be to add a pre-condition that the buffer shall not be a null pointer value.
Moved to Tentatively Ready with revised wording provided by Daniel after 5 positive votes on c++std-lib.
[ 2009-10-20 Martin provides wording: ]
Change [basic.ios.members] around p. 19 as indicated:
void set_rdbuf(basic_streambuf<charT, traits>* sb);
Effects: Associates the basic_streambuf object pointed to by sb with this stream without calling clear(). Postconditions: rdbuf() == sb.Effects: As if:
iostate state = rdstate(); try { rdbuf(sb); } catch(ios_base::failure) { if (0 == (state & ios_base::badbit)) unsetf(badbit); }Throws: Nothing.
We need to be able to call set_rdbuf() on stream objects for which (rdbuf() == 0) holds without causing ios_base::failure to be thrown. We also don't want badbit to be set as a result of setting rdbuf() to 0 if it wasn't set before the call. This changed Effects clause maintains the current behavior (as of N2914) without requiring that sb be non-null.
[ 2009-10 Santa Cruz: ]
Moved to Open. Martin volunteers to provide new wording, where set_rdbuf() sets the badbit but does not cause an exception to be thrown like a call to clear() would.
The protected member function set_rdbuf had been added during the process of adding move and swap semantics to IO classes. A relevant property of this function is described by it's effects in [basic.ios.members]/19:
Effects: Associates the basic_streambuf object pointed to by sb with this stream without calling clear().
This means that implementors of or those who derive from existing IO classes could cause an internal state where the stream buffer could be 0, but the IO class has the state good(). This would break several currently existing implementations which rely on the fact that setting a stream buffer via the currently only ways, i.e. either by calling
void init(basic_streambuf<charT,traits>* sb);
or by calling
basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
to set rdstate() to badbit, if the buffer is 0. This has the effect that many internal functions can simply check rdstate() instead of rdbuf() for being 0.
I therefore suggest that a requirement is added for callers of set_rdbuf to set a non-0 value.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2010-11-24 14:01:03 | admin | set | messages: + msg5418 |
2010-11-14 13:10:57 | admin | set | status: voting -> wp |
2010-11-08 14:14:39 | admin | set | status: ready -> voting |
2010-10-21 19:06:53 | admin | set | messages: + msg4763 |
2010-10-21 19:06:53 | admin | set | status: open -> ready |
2010-10-21 18:28:33 | admin | set | messages: + msg1054 |
2010-10-21 18:28:33 | admin | set | messages: + msg1053 |
2010-10-21 18:28:33 | admin | set | messages: + msg1052 |
2010-10-21 18:28:33 | admin | set | messages: + msg1051 |
2009-07-28 00:00:00 | admin | create |