[v3] libstdc++/2832
Benjamin Kosnik
bkoz@redhat.com
Thu May 24 16:04:00 GMT 2001
Weighing heavily on my mind this week.......
tested x86/linux, no new regressions. Applied to trunk and branch
2001-05-22 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/2832
* include/bits/basic_ios.tcc: Small tweak.
* include/bits/std_fstream.h (ifstream): Add buffer member. Adjust
ctors and dtors, and rdbuf settings.
(ofstream): Same.
(fstream): Same.
* include/bits/std_sstream.h: Same, but for stringstream classes.
* testsuite/27_io/ostringstream_members.cc: New.
* testsuite/27_io/stringstream_members.cc: New.
* testsuite/27_io/fstream_members.cc: New.
* testsuite/27_io/ifstream_members.cc: Add test.
* testsuite/27_io/istringstream_members.cc: Add test.
* testsuite/27_io/ofstream_members.cc: Add test.
Index: include/bits/basic_ios.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.4
diff -c -p -r1.4 basic_ios.tcc
*** basic_ios.tcc 2001/03/04 21:34:00 1.4
--- basic_ios.tcc 2001/05/24 22:58:49
*************** namespace std {
*** 132,137 ****
} // namespace std
! #endif /* _CPP_BITS_BASICIOS_TCC */
--- 132,137 ----
} // namespace std
! #endif // _CPP_BITS_BASICIOS_TCC
Index: include/bits/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/std_fstream.h,v
retrieving revision 1.9
diff -c -p -r1.9 std_fstream.h
*** std_fstream.h 2001/05/22 18:48:19 1.9
--- std_fstream.h 2001/05/24 22:58:50
*************** namespace std
*** 244,284 ****
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
! // Constructors/Destructors:
basic_ifstream()
! : __istream_type(new __filebuf_type())
! { }
explicit
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
! : __istream_type(new __filebuf_type())
! { this->open(__s, __mode); }
!
! ~basic_ifstream()
{
! delete _M_streambuf;
! _M_streambuf = NULL;
}
// Members:
__filebuf_type*
rdbuf() const
! { return static_cast<__filebuf_type*>(_M_streambuf); }
bool
! is_open(void) { return rdbuf()->is_open(); }
void
open(const char* __s, ios_base::openmode __mode = ios_base::in)
{
! if (rdbuf()->open(__s, __mode | ios_base::in) == NULL)
this->setstate(ios_base::failbit);
}
void
close(void)
{
! if (!rdbuf()->close())
this->setstate(ios_base::failbit);
}
};
--- 244,288 ----
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
! private:
! __filebuf_type _M_filebuf;
!
! public:
! // Constructors/Destructors:
basic_ifstream()
! : __istream_type(NULL), _M_filebuf()
! { this->init(&_M_filebuf); }
explicit
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
! : __istream_type(NULL), _M_filebuf()
{
! this->init(&_M_filebuf);
! this->open(__s, __mode);
}
+
+ ~basic_ifstream()
+ { }
// Members:
__filebuf_type*
rdbuf() const
! { return const_cast<__filebuf_type*>(&_M_filebuf); }
bool
! is_open(void) { return _M_filebuf.is_open(); }
void
open(const char* __s, ios_base::openmode __mode = ios_base::in)
{
! if (_M_filebuf.open(__s, __mode | ios_base::in) == NULL)
this->setstate(ios_base::failbit);
}
void
close(void)
{
! if (!_M_filebuf.close())
this->setstate(ios_base::failbit);
}
};
*************** namespace std
*** 300,342 ****
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
// Constructors:
basic_ofstream()
! : __ostream_type(new __filebuf_type())
! { }
explicit
basic_ofstream(const char* __s,
ios_base::openmode __mode = ios_base::out|ios_base::trunc)
! : __ostream_type(new __filebuf_type())
! { this->open(__s, __mode); }
!
! ~basic_ofstream()
{
! delete _M_streambuf;
! _M_streambuf = NULL;
}
// Members:
__filebuf_type*
rdbuf(void) const
! { return static_cast<__filebuf_type*>(_M_streambuf); }
bool
! is_open(void) { return rdbuf()->is_open(); }
void
open(const char* __s,
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
{
! if (!rdbuf()->open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
}
void
close(void)
{
! if (!rdbuf()->close())
setstate(ios_base::failbit);
}
};
--- 304,350 ----
typedef basic_filebuf<char_type, traits_type> __filebuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
+ private:
+ __filebuf_type _M_filebuf;
+
+ public:
// Constructors:
basic_ofstream()
! : __ostream_type(NULL), _M_filebuf()
! { this->init(&_M_filebuf); }
explicit
basic_ofstream(const char* __s,
ios_base::openmode __mode = ios_base::out|ios_base::trunc)
! : __ostream_type(NULL), _M_filebuf()
{
! this->init(&_M_filebuf);
! this->open(__s, __mode);
}
+ ~basic_ofstream()
+ { }
+
// Members:
__filebuf_type*
rdbuf(void) const
! { return const_cast<__filebuf_type*>(&_M_filebuf); }
bool
! is_open(void) { return _M_filebuf.is_open(); }
void
open(const char* __s,
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
{
! if (!_M_filebuf.open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
}
void
close(void)
{
! if (!_M_filebuf.close())
setstate(ios_base::failbit);
}
};
*************** namespace std
*** 359,402 ****
typedef basic_ios<char_type, traits_type> __ios_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
// Constructors/destructor:
basic_fstream()
! : __iostream_type(new __filebuf_type())
! { }
explicit
basic_fstream(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
! : __iostream_type(new __filebuf_type())
! { this->open(__s, __mode); }
!
! ~basic_fstream()
{
! delete _M_streambuf;
! _M_streambuf = NULL;
}
// Members:
__filebuf_type*
rdbuf(void) const
! { return static_cast<__filebuf_type*>(_M_streambuf); }
bool
! is_open(void) { return rdbuf()->is_open(); }
void
open(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
{
! if (!rdbuf()->open(__s, __mode))
! setstate (ios_base::failbit);
}
void
close(void)
{
! if (!rdbuf()->close())
! setstate (ios_base::failbit);
}
};
} // namespace std
--- 367,414 ----
typedef basic_ios<char_type, traits_type> __ios_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
+ private:
+ __filebuf_type _M_filebuf;
+
+ public:
// Constructors/destructor:
basic_fstream()
! : __iostream_type(NULL), _M_filebuf()
! { this->init(&_M_filebuf); }
explicit
basic_fstream(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
! : __iostream_type(NULL), _M_filebuf()
{
! this->init(&_M_filebuf);
! this->open(__s, __mode);
}
+
+ ~basic_fstream()
+ { }
// Members:
__filebuf_type*
rdbuf(void) const
! { return const_cast<__filebuf_type*>(&_M_filebuf); }
bool
! is_open(void) { return _M_filebuf.is_open(); }
void
open(const char* __s,
ios_base::openmode __mode = ios_base::in | ios_base::out)
{
! if (!_M_filebuf.open(__s, __mode))
! setstate(ios_base::failbit);
}
void
close(void)
{
! if (!_M_filebuf.close())
! setstate(ios_base::failbit);
}
};
} // namespace std
Index: include/bits/std_sstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/std_sstream.h,v
retrieving revision 1.5
diff -c -p -r1.5 std_sstream.h
*** std_sstream.h 2001/05/22 18:48:19 1.5
--- std_sstream.h 2001/05/24 22:58:51
*************** namespace std
*** 203,239 ****
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
// Constructors:
explicit
basic_istringstream(ios_base::openmode __mode = ios_base::in)
! : __istream_type(new __stringbuf_type(__mode | ios_base::in))
! { }
explicit
basic_istringstream(const __string_type& __str,
ios_base::openmode __mode = ios_base::in)
! : __istream_type(new __stringbuf_type(__str, __mode | ios_base::in))
! { }
~basic_istringstream()
! {
! delete _M_streambuf;
! _M_streambuf = NULL;
! }
// Members:
__stringbuf_type*
rdbuf() const
! { return static_cast<__stringbuf_type*>(_M_streambuf); }
__string_type
str() const
! { return this->rdbuf()->str(); }
void
str(const __string_type& __s)
! { rdbuf()->str(__s); }
!
};
--- 203,239 ----
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_istream<char_type, traits_type> __istream_type;
+ private:
+ __stringbuf_type _M_stringbuf;
+
+ public:
// Constructors:
explicit
basic_istringstream(ios_base::openmode __mode = ios_base::in)
! : __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
! { this->init(&_M_stringbuf); }
explicit
basic_istringstream(const __string_type& __str,
ios_base::openmode __mode = ios_base::in)
! : __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
! { this->init(&_M_stringbuf); }
~basic_istringstream()
! { }
// Members:
__stringbuf_type*
rdbuf() const
! { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
__string_type
str() const
! { return _M_stringbuf.str(); }
void
str(const __string_type& __s)
! { _M_stringbuf.str(__s); }
};
*************** namespace std
*** 253,290 ****
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
! // Constructors/destructor:
explicit
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
! : __ostream_type(new __stringbuf_type(__mode | ios_base::out))
! { }
explicit
basic_ostringstream(const __string_type __str,
ios_base::openmode __mode = ios_base::out)
! : __ostream_type(new __stringbuf_type(__str, __mode | ios_base::out))
! { }
~basic_ostringstream()
! {
! delete _M_streambuf;
! _M_streambuf = NULL;
! }
// Members:
__stringbuf_type*
rdbuf() const
! { return static_cast<__stringbuf_type*>(_M_streambuf); }
__string_type
str() const
! { return this->rdbuf()->str(); }
void
str(const __string_type& __s)
! { rdbuf()->str(__s); }
!
};
--- 253,290 ----
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_ostream<char_type, traits_type> __ostream_type;
+
+ private:
+ __stringbuf_type _M_stringbuf;
! public:
! // Constructors/destructor:
explicit
basic_ostringstream(ios_base::openmode __mode = ios_base::out)
! : __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
! { this->init(&_M_stringbuf); }
explicit
basic_ostringstream(const __string_type __str,
ios_base::openmode __mode = ios_base::out)
! : __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
! { this->init(&_M_stringbuf); }
~basic_ostringstream()
! { }
// Members:
__stringbuf_type*
rdbuf() const
! { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
__string_type
str() const
! { return _M_stringbuf.str(); }
void
str(const __string_type& __s)
! { _M_stringbuf.str(__s); }
};
*************** namespace std
*** 304,344 ****
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
!
// Constructors/destructors
explicit
! basic_stringstream(ios_base::openmode __mode =
! ios_base::out | ios_base::in)
! : __iostream_type(new __stringbuf_type(__mode))
! { }
explicit
basic_stringstream(const __string_type& __str,
! ios_base::openmode __mode =
! ios_base::out | ios_base::in)
! : __iostream_type(new __stringbuf_type(__str, __mode))
! { }
~basic_stringstream()
! {
! delete _M_streambuf;
! _M_streambuf = NULL;
! }
// Members:
__stringbuf_type*
rdbuf() const
! { return static_cast<__stringbuf_type*>(_M_streambuf); }
__string_type
str() const
! { return rdbuf()->str(); }
void
str(const __string_type& __s)
! { rdbuf()->str(__s); }
};
-
} // namespace std
--- 304,342 ----
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
typedef basic_iostream<char_type, traits_type> __iostream_type;
!
! private:
! __stringbuf_type _M_stringbuf;
!
! public:
// Constructors/destructors
explicit
! basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
! : __iostream_type(NULL), _M_stringbuf(__m)
! { this->init(&_M_stringbuf); }
explicit
basic_stringstream(const __string_type& __str,
! ios_base::openmode __m = ios_base::out | ios_base::in)
! : __iostream_type(NULL), _M_stringbuf(__str, __m)
! { this->init(&_M_stringbuf); }
~basic_stringstream()
! { }
// Members:
__stringbuf_type*
rdbuf() const
! { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
__string_type
str() const
! { return _M_stringbuf.str(); }
void
str(const __string_type& __s)
! { _M_stringbuf.str(__s); }
};
} // namespace std
*************** namespace std
*** 350,354 ****
#endif
#endif
! #endif /* _CPP_SSTREAM */
--- 348,352 ----
#endif
#endif
! #endif // _CPP_SSTREAM
Index: testsuite/27_io/fstream_members.cc
===================================================================
RCS file: fstream_members.cc
diff -N fstream_members.cc
*** /dev/null Tue May 5 13:32:27 1998
--- fstream_members.cc Thu May 24 15:58:53 2001
***************
*** 0 ****
--- 1,70 ----
+ // 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
+
+ // Copyright (C) 2001 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library. This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ // GNU General Public License for more details.
+
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING. If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+
+ // 27.8.1.13 member functions (fstream_members)
+
+ #include <fstream>
+ #include <debug_assert.h>
+
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::filebuf fbuf;
+ std::streambuf* pbasebuf0 = &fbuf;
+
+ std::fstream sstrm1;
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::filebuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &fbuf);
+ std::filebuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
+ int main()
+ {
+ test02();
+ return 0;
+ }
+
+
+
Index: testsuite/27_io/ifstream_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ifstream_members.cc,v
retrieving revision 1.6
diff -c -p -r1.6 ifstream_members.cc
*** ifstream_members.cc 2001/05/12 16:51:42 1.6
--- ifstream_members.cc 2001/05/24 22:58:53
***************
*** 1,4 ****
! // Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,4 ----
! // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
*************** bool test01()
*** 73,82 ****
--- 73,123 ----
return test;
}
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::filebuf fbuf;
+ std::streambuf* pbasebuf0 = &fbuf;
+
+ std::ifstream sstrm1;
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::filebuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &fbuf);
+ std::filebuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
int main()
{
test00();
test01();
+
+ test02();
return 0;
}
+
+
+
Index: testsuite/27_io/istringstream_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/istringstream_members.cc,v
retrieving revision 1.3
diff -c -p -r1.3 istringstream_members.cc
*** istringstream_members.cc 2001/05/12 16:51:42 1.3
--- istringstream_members.cc 2001/05/24 22:58:53
***************
*** 1,6 ****
// 2000-01-10 bkoz
! // Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,6 ----
// 2000-01-10 bkoz
! // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
***************
*** 18,36 ****
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
- // 27.7.2 template class basic_istringstream
// 27.7.2.2 member functions (istringstream_members)
- // stringbuf* rdbuf() const
-
#include <sstream>
#include <debug_assert.h>
-
void test01()
{
bool test = true;
std::istringstream is01;
const std::string str01 = "123";
std::string str02;
const int i01 = 123;
--- 18,33 ----
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 27.7.2.2 member functions (istringstream_members)
#include <sstream>
#include <debug_assert.h>
void test01()
{
bool test = true;
std::istringstream is01;
+ const std::string str00;
const std::string str01 = "123";
std::string str02;
const int i01 = 123;
*************** void test01()
*** 39,47 ****
std::ios_base::iostate state1, state2, statefail, stateeof;
statefail = std::ios_base::failbit;
stateeof = std::ios_base::eofbit;
!
// void str(const basic_string&)
is01.str(str01);
state1 = is01.rdstate();
is01 >> a;
state2 = is01.rdstate();
--- 36,50 ----
std::ios_base::iostate state1, state2, statefail, stateeof;
statefail = std::ios_base::failbit;
stateeof = std::ios_base::eofbit;
!
! // string str() const
! str02 = is01.str();
! VERIFY( str00 == str02 );
!
// void str(const basic_string&)
is01.str(str01);
+ str02 = is01.str();
+ VERIFY( str01 == str02 );
state1 = is01.rdstate();
is01 >> a;
state2 = is01.rdstate();
*************** void test01()
*** 66,82 ****
VERIFY( state1 != state2 );
VERIFY( state2 == stateeof );
- // string str() const
- str02 = is01.str();
- VERIFY( str01 == str02 );
-
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
int main()
{
test01();
return 0;
}
--- 69,131 ----
VERIFY( state1 != state2 );
VERIFY( state2 == stateeof );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::stringbuf sbuf(str01);
+ std::streambuf* pbasebuf0 = &sbuf;
+
+ std::istringstream sstrm1;
+ VERIFY( sstrm1.str() == str00 );
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::stringbuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &sbuf);
+ std::stringbuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // derived rdbuf() returns the original buf, so str() doesn't change.
+ VERIFY( sstrm1.str() != str01 );
+ VERIFY( sstrm1.str() == str00 );
+ // however, casting the active streambuf to a stringbuf shows what's up:
+ std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
+ str02 = psbuf->str();
+ VERIFY( str02 == str01 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
int main()
{
test01();
+ test02();
return 0;
}
+
+
+
Index: testsuite/27_io/ofstream_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ofstream_members.cc,v
retrieving revision 1.6
diff -c -p -r1.6 ofstream_members.cc
*** ofstream_members.cc 2001/05/12 16:51:42 1.6
--- ofstream_members.cc 2001/05/24 22:58:54
***************
*** 1,4 ****
! // Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,4 ----
! // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
*************** bool test01()
*** 74,82 ****
--- 74,124 ----
return test;
}
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::filebuf fbuf;
+ std::streambuf* pbasebuf0 = &fbuf;
+
+ std::ofstream sstrm1;
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::filebuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &fbuf);
+ std::filebuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
int main()
{
test00();
test01();
+
+ test02();
return 0;
}
+
+
+
Index: testsuite/27_io/ostringstream_members.cc
===================================================================
RCS file: ostringstream_members.cc
diff -N ostringstream_members.cc
*** /dev/null Tue May 5 13:32:27 1998
--- ostringstream_members.cc Thu May 24 15:58:54 2001
***************
*** 0 ****
--- 1,105 ----
+ // 2001-05-23 Benjamin Kosnik <bkoz@redhat.com>
+
+ // Copyright (C) 2001 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library. This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ // GNU General Public License for more details.
+
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING. If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+
+ // 27.7.3.2 member functions (ostringstream_members)
+
+ #include <sstream>
+ #include <debug_assert.h>
+
+ void test01()
+ {
+ bool test = true;
+ std::ostringstream os01;
+ const std::string str00;
+ const std::string str01 = "123";
+ std::string str02;
+ const int i01 = 123;
+ int a,b;
+
+ std::ios_base::iostate state1, state2, statefail, stateeof;
+ statefail = std::ios_base::failbit;
+ stateeof = std::ios_base::eofbit;
+
+ // string str() const
+ str02 = os01.str();
+ VERIFY( str00 == str02 );
+
+ // void str(const basic_string&)
+ os01.str(str01);
+ str02 = os01.str();
+ VERIFY( str01 == str02 );
+
+ #ifdef DEBUG_ASSERT
+ assert(test);
+ #endif
+ }
+
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::stringbuf sbuf(str01);
+ std::streambuf* pbasebuf0 = &sbuf;
+
+ std::ostringstream sstrm1;
+ VERIFY( sstrm1.str() == str00 );
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::stringbuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &sbuf);
+ std::stringbuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // derived rdbuf() returns the original buf, so str() doesn't change.
+ VERIFY( sstrm1.str() != str01 );
+ VERIFY( sstrm1.str() == str00 );
+ // however, casting the active streambuf to a stringbuf shows what's up:
+ std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
+ str02 = psbuf->str();
+ VERIFY( str02 == str01 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
+ int main()
+ {
+ test01();
+ test02();
+ return 0;
+ }
Index: testsuite/27_io/stringstream_members.cc
===================================================================
RCS file: stringstream_members.cc
diff -N stringstream_members.cc
*** /dev/null Tue May 5 13:32:27 1998
--- stringstream_members.cc Thu May 24 15:58:54 2001
***************
*** 0 ****
--- 1,131 ----
+ // 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
+
+ // Copyright (C) 2001 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library. This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ // GNU General Public License for more details.
+
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING. If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+
+ // 27.7.6 member functions (stringstream_members)
+
+ #include <sstream>
+ #include <debug_assert.h>
+
+ void test01()
+ {
+ bool test = true;
+ std::stringstream is01;
+ const std::string str00;
+ const std::string str01 = "123";
+ std::string str02;
+ const int i01 = 123;
+ int a,b;
+
+ std::ios_base::iostate state1, state2, statefail, stateeof;
+ statefail = std::ios_base::failbit;
+ stateeof = std::ios_base::eofbit;
+
+ // string str() const
+ str02 = is01.str();
+ VERIFY( str00 == str02 );
+
+ // void str(const basic_string&)
+ is01.str(str01);
+ str02 = is01.str();
+ VERIFY( str01 == str02 );
+ state1 = is01.rdstate();
+ is01 >> a;
+ state2 = is01.rdstate();
+ VERIFY( a = i01 );
+ // 22.2.2.1.2 num_get virtual functions
+ // p 13
+ // in any case, if stage 2 processing was terminated by the test for
+ // in == end then err != ios_base::eofbit is performed.
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == stateeof );
+
+ is01.str(str01);
+ is01 >> b;
+ VERIFY( b != a );
+ // as is01.good() is false, istream::sentry blocks extraction.
+
+ is01.clear();
+ state1 = is01.rdstate();
+ is01 >> b;
+ state2 = is01.rdstate();
+ VERIFY( b == a );
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == stateeof );
+
+ #ifdef DEBUG_ASSERT
+ assert(test);
+ #endif
+ }
+
+ void
+ redirect_buffer(std::ios& stream, std::streambuf* new_buf)
+ { stream.rdbuf(new_buf); }
+
+ std::streambuf*
+ active_buffer(std::ios& stream)
+ { return stream.rdbuf(); }
+
+ // libstdc++/2832
+ void test02()
+ {
+ bool test = true;
+ const char* strlit01 = "fuck war";
+ const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
+ const std::string str00;
+ const std::string str01(strlit01);
+ std::string str02;
+ std::stringbuf sbuf(str01);
+ std::streambuf* pbasebuf0 = &sbuf;
+
+ std::stringstream sstrm1;
+ VERIFY( sstrm1.str() == str00 );
+ // derived rdbuf() always returns original streambuf, even though
+ // it's no longer associated with the stream.
+ std::stringbuf* const buf1 = sstrm1.rdbuf();
+ // base rdbuf() returns the currently associated streambuf
+ std::streambuf* pbasebuf1 = active_buffer(sstrm1);
+ redirect_buffer(sstrm1, &sbuf);
+ std::stringbuf* const buf2 = sstrm1.rdbuf();
+ std::streambuf* pbasebuf2 = active_buffer(sstrm1);
+ VERIFY( buf1 == buf2 );
+ VERIFY( pbasebuf1 != pbasebuf2 );
+ VERIFY( pbasebuf2 == pbasebuf0 );
+
+ // derived rdbuf() returns the original buf, so str() doesn't change.
+ VERIFY( sstrm1.str() != str01 );
+ VERIFY( sstrm1.str() == str00 );
+ // however, casting the active streambuf to a stringbuf shows what's up:
+ std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
+ str02 = psbuf->str();
+ VERIFY( str02 == str01 );
+
+ // How confusing and non-intuitive is this?
+ // These semantics are a joke, a serious defect, and incredibly lame.
+ }
+
+ int main()
+ {
+ test01();
+ test02();
+ return 0;
+ }
+
+
+
More information about the Gcc-patches
mailing list