libstdc++/1834: istream manipulators and sentry
snyder@fnal.gov
snyder@fnal.gov
Sun Apr 1 00:00:00 GMT 2001
>Number: 1834
>Category: libstdc++
>Synopsis: istream manipulators and sentry
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 01 13:36:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: scott snyder
>Release: 2.97 20010129 (experimental)
>Organization:
>Environment:
System: Linux karma 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../egcs/configure --prefix=/usr/local/egcs --enable-threads=posix
>Description:
Consider the following program:
---------------------------------------------------------
#include <iostream>
int main ()
{
std::cin >> std::hex;
return 0;
}
---------------------------------------------------------
I expect this program to exit without doing anything.
However, when i run it with libstdc++, it blocks waiting for input
before it exits. This is because the operator>> implementations
for manipulators in istream.tcc construct sentry objects.
However, this is incorrect. This conclusion is clarified
by library issue #60. A couple excerpts from it:
... I
assume that 27.6.1.2.1 is intended to apply to the arithmetic
extractors (27.6.1.2.2), but I assume that it is not intended to apply
to extractors like
basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
and
basic_istream& operator>>(basic_streammbuf*);
...
Comments from Judy Ward: It seems like the problem is that the
basic_istream and basic_ostream operator <<()'s that are used for the
manipulators and streambuf* are in the wrong section and should have
their own separate section or be modified to make it clear that the
"Common requirements" listed in section 27.6.1.2.1 (for basic_istream)
and section 27.6.2.5.1 (for basic_ostream) do not apply to them.
...
Proposed Resolution:
...
In 27.6.1.2.3, [lib.istream::extractors], before paragraph 1. Add an
effects clause. "Effects: None. This extractor does not behave as a
formatted input function (as described in 27.6.1.2.1).
...
etc.
>How-To-Repeat:
See above.
>Fix:
2001-01-29 scott snyder <sss@fnal.gov>
* include/bits/istream.tcc (operator>> (manip types)): Don't do
anything other than calling __pf.
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.4
diff -u -p -c -r1.4 istream.tcc
*** istream.tcc 2001/01/16 07:55:25 1.4
--- istream.tcc 2001/02/01 20:41:14
*************** namespace std {
*** 81,100 ****
basic_istream<_CharT, _Traits>::
operator>>(__istream_type& (*__pf)(__istream_type&))
{
! sentry __cerb(*this, false);
! if (__cerb)
! {
! try {
! __pf(*this);
! }
! catch(exception& __fail){
! // 27.6.1.2.1 Common requirements.
! // Turn this on without causing an ios::failure to be thrown.
! this->setstate(ios_base::badbit);
! if ((this->exceptions() & ios_base::badbit) != 0)
! throw;
! }
! }
return *this;
}
--- 81,87 ----
basic_istream<_CharT, _Traits>::
operator>>(__istream_type& (*__pf)(__istream_type&))
{
! __pf(*this);
return *this;
}
*************** namespace std {
*** 103,122 ****
basic_istream<_CharT, _Traits>::
operator>>(__ios_type& (*__pf)(__ios_type&))
{
! sentry __cerb(*this, false);
! if (__cerb)
! {
! try {
! __pf(*this);
! }
! catch(exception& __fail){
! // 27.6.1.2.1 Common requirements.
! // Turn this on without causing an ios::failure to be thrown.
! this->setstate(ios_base::badbit);
! if ((this->exceptions() & ios_base::badbit) != 0)
! throw;
! }
! }
return *this;
}
--- 90,96 ----
basic_istream<_CharT, _Traits>::
operator>>(__ios_type& (*__pf)(__ios_type&))
{
! __pf(*this);
return *this;
}
*************** namespace std {
*** 125,144 ****
basic_istream<_CharT, _Traits>::
operator>>(ios_base& (*__pf)(ios_base&))
{
! sentry __cerb(*this, false);
! if (__cerb)
! {
! try {
! __pf(*this);
! }
! catch(exception& __fail){
! // 27.6.1.2.1 Common requirements.
! // Turn this on without causing an ios::failure to be thrown.
! this->setstate(ios_base::badbit);
! if ((this->exceptions() & ios_base::badbit) != 0)
! throw;
! }
! }
return *this;
}
--- 99,105 ----
basic_istream<_CharT, _Traits>::
operator>>(ios_base& (*__pf)(ios_base&))
{
! __pf(*this);
return *this;
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list