Commit bcc6a03a by Benjamin Kosnik Committed by Benjamin Kosnik

re PR libstdc++/7216 (basic_iostream::traits_type is ambiguous issue)


2002-07-25  Benjamin Kosnik  <bkoz@redhat.com>

	PR libstdc++/7216
	* include/std/std_istream.h (basic_iostream): Add typedefs for
	char_type, int_type, pos_type, off_type, and traits_type.
	* testsuite/27_io/iostream.cc (test01): Add typedef tests.
	* testsuite/27_io/istream.cc: Same.
	* testsuite/27_io/ostream.cc: Same.
	* testsuite/27_io/filebuf.cc: Same.
	* testsuite/27_io/stringbuf.cc: Replace content, move to...
	* testsuite/27_io/stringbuf_members.cc: ...here.
	* testsuite/27_io/streambuf.cc: Replace content, move to...
	* testsuite/27_io/streambuf_members.cc: ...here.
	* testsuite/27_io/stringstream.cc: Replace content, move to...
	* testsuite/27_io/stringstream_members.cc: ...here.
	* testsuite/27_io/ios.cc: New file.
	* testsuite/27_io/fstream.cc: New file.
	* testsuite/27_io/ifstream.cc: New file.
	* testsuite/27_io/ofstream.cc: New file.
	* testsuite/27_io/istringstream.cc: New file.
	* testsuite/27_io/ostringstream.cc: New file.

From-SVN: r55767
parent 325fceb3
2002-07-25 Benjamin Kosnik <bkoz@redhat.com> 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/7216
* include/std/std_istream.h (basic_iostream): Add typedefs for
char_type, int_type, pos_type, off_type, and traits_type.
* testsuite/27_io/iostream.cc (test01): Add typedef tests.
* testsuite/27_io/istream.cc: Same.
* testsuite/27_io/ostream.cc: Same.
* testsuite/27_io/filebuf.cc: Same.
* testsuite/27_io/stringbuf.cc: Replace content, move to...
* testsuite/27_io/stringbuf_members.cc: ...here.
* testsuite/27_io/streambuf.cc: Replace content, move to...
* testsuite/27_io/streambuf_members.cc: ...here.
* testsuite/27_io/stringstream.cc: Replace content, move to...
* testsuite/27_io/stringstream_members.cc: ...here.
* testsuite/27_io/ios.cc: New file.
* testsuite/27_io/fstream.cc: New file.
* testsuite/27_io/ifstream.cc: New file.
* testsuite/27_io/ofstream.cc: New file.
* testsuite/27_io/istringstream.cc: New file.
* testsuite/27_io/ostringstream.cc: New file.
2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/7220 PR libstdc++/7220
* include/bits/istream.tcc (istream::ignore): Don't extract on * include/bits/istream.tcc (istream::ignore): Don't extract on
zero. zero.
......
...@@ -261,6 +261,16 @@ namespace std ...@@ -261,6 +261,16 @@ namespace std
public basic_ostream<_CharT, _Traits> public basic_ostream<_CharT, _Traits>
{ {
public: public:
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
// 271. basic_iostream missing typedefs
// Types (inherited):
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
#endif
// Non-standard Types: // Non-standard Types:
typedef basic_istream<_CharT, _Traits> __istream_type; typedef basic_istream<_CharT, _Traits> __istream_type;
typedef basic_ostream<_CharT, _Traits> __ostream_type; typedef basic_ostream<_CharT, _Traits> __ostream_type;
......
...@@ -19,15 +19,26 @@ ...@@ -19,15 +19,26 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA. // USA.
// NB: this test assumes that _M_buf_size == 40, and not the usual // 27.8.1.1 - Template class basic_filebuf
// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be // NB: This file is for testing basic_filebuf with NO OTHER INCLUDES.
// simulated a bit more readily.
#include <fstream> #include <fstream>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
// { dg-do compile } // { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::filebuf test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
// test05 // test05
// libstdc++/1886 // libstdc++/1886
// should be able to instantiate basic_filebuf for non-standard types. // should be able to instantiate basic_filebuf for non-standard types.
...@@ -35,6 +46,7 @@ template class std::basic_filebuf<short, std::char_traits<short> >; ...@@ -35,6 +46,7 @@ template class std::basic_filebuf<short, std::char_traits<short> >;
int main() int main()
{ {
test01();
return 0; return 0;
} }
......
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.8.1.11 - Template class basic_fstream
// NB: This file is for testing basic_fstream with NO OTHER INCLUDES.
#include <fstream>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::fstream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_fstream<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.8.1.5 - Template class basic_ifstream
// NB: This file is for testing basic_ifstream with NO OTHER INCLUDES.
#include <fstream>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::ifstream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_ifstream<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.4.4 - Template class basic_ios
// NB: This file is for testing basic_ios with NO OTHER INCLUDES.
#include <ios>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::ios test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_ios<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
...@@ -34,6 +34,18 @@ ...@@ -34,6 +34,18 @@
#include <istream> #include <istream>
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::iostream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test namespace test
{ {
using namespace std; using namespace std;
...@@ -43,5 +55,6 @@ namespace test ...@@ -43,5 +55,6 @@ namespace test
int main() int main()
{ {
test01();
return 0; return 0;
} }
...@@ -34,6 +34,18 @@ ...@@ -34,6 +34,18 @@
// { dg-do compile } // { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::istream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test namespace test
{ {
using namespace std; using namespace std;
...@@ -43,5 +55,6 @@ namespace test ...@@ -43,5 +55,6 @@ namespace test
int main() int main()
{ {
test01();
return 0; return 0;
} }
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.7.2 - Template class basic_istringstream
// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES.
#include <sstream>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::istringstream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_istringstream<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.8.1.8 - Template class basic_ofstream
// NB: This file is for testing basic_ofstream with NO OTHER INCLUDES.
#include <fstream>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::ifstream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_ifstream<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
...@@ -34,6 +34,18 @@ ...@@ -34,6 +34,18 @@
// { dg-do compile } // { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::ostream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test namespace test
{ {
using namespace std; using namespace std;
...@@ -43,5 +55,6 @@ namespace test ...@@ -43,5 +55,6 @@ namespace test
int main() int main()
{ {
test01();
return 0; return 0;
} }
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.7.3 - Class basic_ostringstream
// NB: This file is for testing basic_ostringstream with NO OTHER INCLUDES.
#include <sstream>
// { dg-do compile }
// libstdc++/7216
void test01()
{
// Check for required typedefs
typedef std::ostringstream test_type;
typedef test_type::char_type char_type;
typedef test_type::traits_type traits_type;
typedef test_type::int_type int_type;
typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
}
namespace test
{
using namespace std;
typedef short type_t;
template class basic_ostringstream<type_t, char_traits<type_t> >;
} // test
int main()
{
test01();
return 0;
}
// 2001-05-23 Benjamin Kosnik <bkoz@redhat.com> // 2001-05-23 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -97,9 +97,61 @@ void test02() ...@@ -97,9 +97,61 @@ void test02()
// These semantics are a joke, a serious defect, and incredibly lame. // These semantics are a joke, a serious defect, and incredibly lame.
} }
// 03: sanity checks for strings, stringbufs
void
test03()
{
bool test = false;
// Empty string sanity check.
std::string str01;
std::string::iterator __i_start = str01.begin();
std::string::iterator __i_end = str01.end();
std::string::size_type len = str01.size();
test = __i_start == __i_end;
VERIFY( len == 0 );
// Full string sanity check.
std::string str02("these golden days, i spend waiting for you:\n"
"Betty Carter on Verve with I'm Yours and You're Mine.");
__i_start = str02.begin();
__i_end = str02.end();
len = str02.size();
VERIFY( __i_start != __i_end );
VERIFY( len != 0 );
// Test an empty ostringstream for sanity.
std::ostringstream ostrstream0;
std::string str03 = ostrstream0.str();
__i_start = str03.begin();
__i_end = str03.end();
len = str03.size();
VERIFY( __i_start == __i_end );
VERIFY( len == 0 );
VERIFY( str01 == str03 );
}
// user-reported error
class derived_oss: public std::ostringstream
{
public:
derived_oss() : std::ostringstream() { }
};
void
test04()
{
bool test = true;
derived_oss yy;
yy << "buena vista social club\n";
VERIFY( yy.str() == std::string("buena vista social club\n") );
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
test04();
return 0; return 0;
} }
// 1999-10-11 bkoz // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -27,352 +27,34 @@ ...@@ -27,352 +27,34 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
// 27.5.2 template class basic_streambuf // 27.5.2 - Template class basic_streambuf
// NB: This file is for testing basic_streambuf with NO OTHER INCLUDES.
#include <cstring> // for memset, memcmp
#include <streambuf> #include <streambuf>
#include <string>
#include <ostream>
#include <testsuite_hooks.h>
class testbuf : public std::streambuf // { dg-do compile }
{
public:
// Typedefs:
typedef std::streambuf::traits_type traits_type;
typedef std::streambuf::char_type char_type;
testbuf(): std::streambuf()
{ _M_mode = (std::ios_base::in | std::ios_base::out); }
bool
check_pointers()
{
bool test = true;
VERIFY( this->eback() == NULL );
VERIFY( this->gptr() == NULL );
VERIFY( this->egptr() == NULL );
VERIFY( this->pbase() == NULL );
VERIFY( this->pptr() == NULL );
VERIFY( this->epptr() == NULL );
return test;
}
int_type
pub_uflow()
{ return (this->uflow()); }
int_type
pub_overflow(int_type __c = traits_type::eof())
{ return (this->overflow(__c)); }
int_type
pub_pbackfail(int_type __c)
{ return (this->pbackfail(__c)); }
void
pub_setg(char* beg, char* cur, char *end)
{ this->setg(beg, cur, end); }
void
pub_setp(char* beg, char* end)
{ this->setp(beg, end); }
protected:
int_type
underflow()
{
int_type __retval = traits_type::eof();
if (this->gptr() < this->egptr())
__retval = traits_type::not_eof(0);
return __retval;
}
};
// libstdc++/7216
void test01() void test01()
{ {
typedef testbuf::traits_type traits_type; // Check for required typedefs
typedef testbuf::int_type int_type; typedef std::streambuf test_type;
typedef test_type::char_type char_type;
bool test = true; typedef test_type::traits_type traits_type;
char* lit01 = "chicago underground trio/possible cube on delmark"; typedef test_type::int_type int_type;
testbuf buf01; typedef test_type::pos_type pos_type;
typedef test_type::off_type off_type;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
// - all pointer members to null pointers
// - locale to current global locale
VERIFY( buf01.check_pointers() );
VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.3.1 get area
// 27.5.2.2.3 get area
// 27.5.2.4.3 get area
int i01 = 3;
buf01.pub_setg(lit01, lit01, (lit01 + i01));
VERIFY( i01 == buf01.in_avail() );
VERIFY( buf01.pub_uflow() == lit01[0] );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) );
VERIFY( buf01.pub_uflow() == lit01[1] );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) );
VERIFY( buf01.pub_uflow() == lit01[2] );
VERIFY( buf01.sgetc() == traits_type::eof() );
// pbackfail
buf01.pub_setg(lit01, lit01, (lit01 + i01));
VERIFY( i01 == buf01.in_avail() );
int_type intt01 = traits_type::to_int_type('b');
VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) );
// overflow
VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) );
VERIFY( traits_type::eof() == buf01.pub_overflow() );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) );
// sputn/xsputn
char* lit02 = "isotope 217: the unstable molecule on thrill jockey";
int i02 = std::strlen(lit02);
char carray[i02 + 1];
std::memset(carray, 0, i02 + 1);
buf01.pub_setp(carray, (carray + i02));
buf01.sputn(lit02, 0);
VERIFY( carray[0] == 0 );
VERIFY( lit02[0] == 'i' );
buf01.sputn(lit02, 1);
VERIFY( lit02[0] == carray[0] );
VERIFY( lit02[1] == 's' );
VERIFY( carray[1] == 0 );
buf01.sputn(lit02 + 1, 10);
VERIFY( std::memcmp(lit02, carray, 10) == 0 );
buf01.sputn(lit02 + 11, 20);
VERIFY( std::memcmp(lit02, carray, 30) == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
void test02()
{
typedef testbuf::traits_type traits_type;
typedef testbuf::int_type int_type;
bool test = true;
char* lit01 = "chicago underground trio/possible cube on delmark";
testbuf buf01;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
// - all pointer members to null pointers
// - locale to current global locale
VERIFY( buf01.check_pointers() );
VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.2.5 Put area
size_t i01 = traits_type::length(lit01);
char carray01[i01];
std::memset(carray01, 0, i01);
buf01.pub_setg(lit01, lit01, lit01 + i01);
buf01.sgetn(carray01, 0);
VERIFY( carray01[0] == 0 );
buf01.sgetn(carray01, 1);
VERIFY( carray01[0] == 'c' );
buf01.sgetn(carray01 + 1, i01 - 1);
VERIFY( carray01[0] == 'c' );
VERIFY( carray01[1] == 'h' );
VERIFY( carray01[i01 - 1] == 'k' );
#ifdef DEBUG_ASSERT
assert(test);
#endif
} }
// test03
// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html
template<typename charT, typename traits = std::char_traits<charT> >
class basic_nullbuf : public std::basic_streambuf<charT, traits>
{
protected:
typedef typename
std::basic_streambuf<charT, traits>::int_type int_type;
virtual int_type
overflow(int_type c)
{ return traits::not_eof(c); }
};
typedef basic_nullbuf<char> nullbuf;
typedef basic_nullbuf<wchar_t> wnullbuf;
template<typename T>
char
print(const T& x)
{
nullbuf ob;
std::ostream out(&ob);
out << x << std::endl;
return (!out ? '0' : '1');
}
void test03() namespace test
{ {
bool test = true; using namespace std;
const std::string control01("11111"); typedef short type_t;
std::string test01; template class basic_streambuf<type_t, char_traits<type_t> >;
} // test
test01 += print(true);
test01 += print(3.14159);
test01 += print(10);
test01 += print('x');
test01 += print("pipo");
VERIFY( test01 == control01 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
class setpbuf : public std::streambuf
{
char buffer[4];
std::string result;
public:
std::string&
get_result()
{ return result; }
setpbuf()
{
char foo [32];
setp(foo, foo + 32);
setp(buffer, buffer + 4);
}
~setpbuf()
{ sync(); }
virtual int_type
overflow(int_type n)
{
if (sync() != 0)
return traits_type::eof();
result += traits_type::to_char_type(n);
return n;
}
virtual int
sync()
{
result.append(pbase(), pptr());
setp(buffer, buffer + 4);
return 0;
}
};
// libstdc++/1057
void test04()
{
bool test = true;
std::string text = "abcdefghijklmn";
// 01
setpbuf sp1;
// Here xsputn writes over sp1.result
sp1.sputn(text.c_str(), text.length());
// This crashes when result is accessed
sp1.pubsync();
VERIFY( sp1.get_result() == text );
// 02
setpbuf sp2;
for (std::string::size_type i = 0; i < text.length(); ++i)
{
// sputc also writes over result
sp2.sputc(text[i]);
}
// Crash here
sp2.pubsync();
VERIFY( sp2.get_result() == text );
}
class nullsetpbuf : public std::streambuf
{
char foo[64];
public:
nullsetpbuf()
{
setp(foo, foo + 64);
setp(NULL, NULL);
}
};
// libstdc++/1057
void test05()
{
std::string text1 = "abcdefghijklmn";
nullsetpbuf nsp;
// Immediate crash as xsputn writes to null pointer
nsp.sputn(text1.c_str(), text1.length());
// ditto
nsp.sputc('a');
}
// test06
namespace gnu
{
class something_derived;
}
class gnu::something_derived : std::streambuf { };
// libstdc++/3599
class testbuf2 : public std::streambuf
{
public:
typedef std::streambuf::traits_type traits_type;
testbuf2() : std::streambuf() { }
protected:
int_type
overflow(int_type c = traits_type::eof())
{ return traits_type::not_eof(0); }
};
void
test07()
{
bool test = true;
testbuf2 ob;
std::ostream out(&ob);
out << "gasp";
VERIFY(out.good());
out << std::endl;
VERIFY(out.good());
}
int main() int main()
{ {
test01(); test01();
test02();
test03();
test04();
test05();
test07();
return 0; return 0;
} }
// 1999-10-11 bkoz
// Copyright (C) 1999, 2000, 2001, 2002 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.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.5.2 template class basic_streambuf
#include <cstring> // for memset, memcmp
#include <streambuf>
#include <string>
#include <ostream>
#include <testsuite_hooks.h>
class testbuf : public std::streambuf
{
public:
// Typedefs:
typedef std::streambuf::traits_type traits_type;
typedef std::streambuf::char_type char_type;
testbuf(): std::streambuf()
{ _M_mode = (std::ios_base::in | std::ios_base::out); }
bool
check_pointers()
{
bool test = true;
VERIFY( this->eback() == NULL );
VERIFY( this->gptr() == NULL );
VERIFY( this->egptr() == NULL );
VERIFY( this->pbase() == NULL );
VERIFY( this->pptr() == NULL );
VERIFY( this->epptr() == NULL );
return test;
}
int_type
pub_uflow()
{ return (this->uflow()); }
int_type
pub_overflow(int_type __c = traits_type::eof())
{ return (this->overflow(__c)); }
int_type
pub_pbackfail(int_type __c)
{ return (this->pbackfail(__c)); }
void
pub_setg(char* beg, char* cur, char *end)
{ this->setg(beg, cur, end); }
void
pub_setp(char* beg, char* end)
{ this->setp(beg, end); }
protected:
int_type
underflow()
{
int_type __retval = traits_type::eof();
if (this->gptr() < this->egptr())
__retval = traits_type::not_eof(0);
return __retval;
}
};
void test01()
{
typedef testbuf::traits_type traits_type;
typedef testbuf::int_type int_type;
bool test = true;
char* lit01 = "chicago underground trio/possible cube on delmark";
testbuf buf01;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
// - all pointer members to null pointers
// - locale to current global locale
VERIFY( buf01.check_pointers() );
VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.3.1 get area
// 27.5.2.2.3 get area
// 27.5.2.4.3 get area
int i01 = 3;
buf01.pub_setg(lit01, lit01, (lit01 + i01));
VERIFY( i01 == buf01.in_avail() );
VERIFY( buf01.pub_uflow() == lit01[0] );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) );
VERIFY( buf01.pub_uflow() == lit01[1] );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) );
VERIFY( buf01.pub_uflow() == lit01[2] );
VERIFY( buf01.sgetc() == traits_type::eof() );
// pbackfail
buf01.pub_setg(lit01, lit01, (lit01 + i01));
VERIFY( i01 == buf01.in_avail() );
int_type intt01 = traits_type::to_int_type('b');
VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) );
// overflow
VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) );
VERIFY( traits_type::eof() == buf01.pub_overflow() );
VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) );
// sputn/xsputn
char* lit02 = "isotope 217: the unstable molecule on thrill jockey";
int i02 = std::strlen(lit02);
char carray[i02 + 1];
std::memset(carray, 0, i02 + 1);
buf01.pub_setp(carray, (carray + i02));
buf01.sputn(lit02, 0);
VERIFY( carray[0] == 0 );
VERIFY( lit02[0] == 'i' );
buf01.sputn(lit02, 1);
VERIFY( lit02[0] == carray[0] );
VERIFY( lit02[1] == 's' );
VERIFY( carray[1] == 0 );
buf01.sputn(lit02 + 1, 10);
VERIFY( std::memcmp(lit02, carray, 10) == 0 );
buf01.sputn(lit02 + 11, 20);
VERIFY( std::memcmp(lit02, carray, 30) == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
void test02()
{
typedef testbuf::traits_type traits_type;
typedef testbuf::int_type int_type;
bool test = true;
char* lit01 = "chicago underground trio/possible cube on delmark";
testbuf buf01;
// 27.5.2.1 basic_streambuf ctors
// default ctor initializes
// - all pointer members to null pointers
// - locale to current global locale
VERIFY( buf01.check_pointers() );
VERIFY( buf01.getloc() == std::locale() );
// 27.5.2.2.5 Put area
size_t i01 = traits_type::length(lit01);
char carray01[i01];
std::memset(carray01, 0, i01);
buf01.pub_setg(lit01, lit01, lit01 + i01);
buf01.sgetn(carray01, 0);
VERIFY( carray01[0] == 0 );
buf01.sgetn(carray01, 1);
VERIFY( carray01[0] == 'c' );
buf01.sgetn(carray01 + 1, i01 - 1);
VERIFY( carray01[0] == 'c' );
VERIFY( carray01[1] == 'h' );
VERIFY( carray01[i01 - 1] == 'k' );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
// test03
// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html
template<typename charT, typename traits = std::char_traits<charT> >
class basic_nullbuf : public std::basic_streambuf<charT, traits>
{
protected:
typedef typename
std::basic_streambuf<charT, traits>::int_type int_type;
virtual int_type
overflow(int_type c)
{ return traits::not_eof(c); }
};
typedef basic_nullbuf<char> nullbuf;
typedef basic_nullbuf<wchar_t> wnullbuf;
template<typename T>
char
print(const T& x)
{
nullbuf ob;
std::ostream out(&ob);
out << x << std::endl;
return (!out ? '0' : '1');
}
void test03()
{
bool test = true;
const std::string control01("11111");
std::string test01;
test01 += print(true);
test01 += print(3.14159);
test01 += print(10);
test01 += print('x');
test01 += print("pipo");
VERIFY( test01 == control01 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
}
class setpbuf : public std::streambuf
{
char buffer[4];
std::string result;
public:
std::string&
get_result()
{ return result; }
setpbuf()
{
char foo [32];
setp(foo, foo + 32);
setp(buffer, buffer + 4);
}
~setpbuf()
{ sync(); }
virtual int_type
overflow(int_type n)
{
if (sync() != 0)
return traits_type::eof();
result += traits_type::to_char_type(n);
return n;
}
virtual int
sync()
{
result.append(pbase(), pptr());
setp(buffer, buffer + 4);
return 0;
}
};
// libstdc++/1057
void test04()
{
bool test = true;
std::string text = "abcdefghijklmn";
// 01
setpbuf sp1;
// Here xsputn writes over sp1.result
sp1.sputn(text.c_str(), text.length());
// This crashes when result is accessed
sp1.pubsync();
VERIFY( sp1.get_result() == text );
// 02
setpbuf sp2;
for (std::string::size_type i = 0; i < text.length(); ++i)
{
// sputc also writes over result
sp2.sputc(text[i]);
}
// Crash here
sp2.pubsync();
VERIFY( sp2.get_result() == text );
}
class nullsetpbuf : public std::streambuf
{
char foo[64];
public:
nullsetpbuf()
{
setp(foo, foo + 64);
setp(NULL, NULL);
}
};
// libstdc++/1057
void test05()
{
std::string text1 = "abcdefghijklmn";
nullsetpbuf nsp;
// Immediate crash as xsputn writes to null pointer
nsp.sputn(text1.c_str(), text1.length());
// ditto
nsp.sputc('a');
}
// test06
namespace gnu
{
class something_derived;
}
class gnu::something_derived : std::streambuf { };
// libstdc++/3599
class testbuf2 : public std::streambuf
{
public:
typedef std::streambuf::traits_type traits_type;
testbuf2() : std::streambuf() { }
protected:
int_type
overflow(int_type c = traits_type::eof())
{ return traits_type::not_eof(0); }
};
void
test07()
{
bool test = true;
testbuf2 ob;
std::ostream out(&ob);
out << "gasp";
VERIFY(out.good());
out << std::endl;
VERIFY(out.good());
}
int main()
{
test01();
test02();
test03();
test04();
test05();
test07();
return 0;
}
// 981015 bkoz // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// i,o,stringstream usage
// Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. // Copyright (C) 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -28,133 +27,34 @@ ...@@ -28,133 +27,34 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
#include <vector> // 27.7.4 - Template class basic_stringstream
#include <string> // NB: This file is for testing basic_stringstream with NO OTHER INCLUDES.
#include <sstream>
#include <testsuite_hooks.h>
// 01: sanity checks for strings, stringbufs
std::string
test01()
{
bool test = false;
// Empty string sanity check.
std::string str01;
std::string::iterator __i_start = str01.begin();
std::string::iterator __i_end = str01.end();
std::string::size_type len = str01.size();
test = __i_start == __i_end;
VERIFY( len == 0 );
// Full string sanity check.
std::string str02("these golden days, i spend waiting for you:\n"
"Betty Carter on Verve with I'm Yours and You're Mine.");
__i_start = str02.begin();
__i_end = str02.end();
len = str02.size();
VERIFY( __i_start != __i_end );
VERIFY( len != 0 );
// Test an empty ostring stream for sanity.
std::ostringstream ostrstream0;
std::string str03 = ostrstream0.str();
__i_start = str03.begin();
__i_end = str03.end();
len = str03.size();
VERIFY( __i_start == __i_end );
VERIFY( len == 0 );
VERIFY( str01 == str03 );
return str02; #include <sstream>
}
// { dg-do compile }
int // libstdc++/7216
test02() void test01()
{ {
bool test = true; // Check for required typedefs
typedef std::stringstream test_type;
// typedef test_type::char_type char_type;
// 1: Automatic formatting of a compound string typedef test_type::traits_type traits_type;
// typedef test_type::int_type int_type;
int i = 1024; typedef test_type::pos_type pos_type;
int *pi = &i; typedef test_type::off_type off_type;
double d = 3.14159;
double *pd = &d;
std::string blank;
std::ostringstream ostrst01;
std::ostringstream ostrst02(blank);
// No buffer,so should be created.
ostrst01 << "i: " << i << " i's address: " << pi << "\n"
<< "d: " << d << " d's address: " << pd << std::endl;
// Buffer, so existing buffer should be overwritten.
ostrst02 << "i: " << i << " i's address: " << pi << "\n"
<< "d: " << d << " d's address: " << pd << std::endl;
std::string msg01 = ostrst01.str();
std::string msg02 = ostrst02.str();
VERIFY( msg01 == msg02 );
VERIFY( msg02 != blank );
//
// 2: istringstream
//
// extracts the stored ascii values, placing them in turn in the four vars
#if 0
int i2 = 0;
int *pi2 = &i2;
double d2 = 0.0;
double *pd2 = &d2;
std::istringstream istrst01(ostrst02.str());
istrst01 >> i2 >> pi2 >> d2 >> pd2;
//istrst01 >> i2;
//istrst01 >> pi2;
VERIFY( i2 == i );
VERIFY( d2 == d );
VERIFY( pd2 == pd );
VERIFY( pi2 == pi );
#endif
// stringstream
std::string str1("");
std::string str3("this is a somewhat string");
std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out);
std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out);
return 0;
} }
// user-reported error namespace test
class derived_oss: public std::ostringstream
{
public:
derived_oss() : std::ostringstream() {}
};
int
test03()
{ {
bool test = true; using namespace std;
derived_oss yy; typedef short type_t;
yy << "buena vista social club\n"; template class basic_stringstream<type_t, char_traits<type_t> >;
VERIFY( yy.str() == std::string("buena vista social club\n") ); } // test
#ifdef DEBUG_ASSERT
assert(test);
#endif
return 0;
}
int int main()
main()
{ {
test01(); test01();
test02();
test03();
return 0; return 0;
} }
// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com> // 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -120,12 +120,67 @@ void test02() ...@@ -120,12 +120,67 @@ void test02()
// These semantics are a joke, a serious defect, and incredibly lame. // These semantics are a joke, a serious defect, and incredibly lame.
} }
void
test03()
{
bool test = true;
//
// 1: Automatic formatting of a compound string
//
int i = 1024;
int *pi = &i;
double d = 3.14159;
double *pd = &d;
std::string blank;
std::ostringstream ostrst01;
std::ostringstream ostrst02(blank);
// No buffer, so should be created.
ostrst01 << "i: " << i << " i's address: " << pi << "\n"
<< "d: " << d << " d's address: " << pd << std::endl;
// Buffer, so existing buffer should be overwritten.
ostrst02 << "i: " << i << " i's address: " << pi << "\n"
<< "d: " << d << " d's address: " << pd << std::endl;
std::string msg01 = ostrst01.str();
std::string msg02 = ostrst02.str();
VERIFY( msg01 == msg02 );
VERIFY( msg02 != blank );
//
// 2: istringstream
//
// extracts the stored ascii values, placing them in turn in the four vars
#if 0
int i2 = 0;
//int* pi2 = &i2;
void* pi2 = &i2;
double d2 = 0.0;
// double* pd2 = &d2;
void* pd2 = &d2;
std::istringstream istrst01(ostrst02.str());
istrst01 >> i2 >> pi2 >> d2 >> pd2;
//istrst01 >> i2;
//istrst01 >> pi2;
VERIFY( i2 == i );
VERIFY( d2 == d );
VERIFY( pd2 == pd );
VERIFY( pi2 == pi );
#endif
// stringstream
std::string str1("");
std::string str3("this is a somewhat string");
std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out);
std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out);
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment