Commit 36ce7daa by Benjamin Kosnik Committed by Benjamin Kosnik

localefwd.h (locale::id::_M_id): Do this correctly, as type safety is important,…

localefwd.h (locale::id::_M_id): Do this correctly, as type safety is important, especially on solaris.


2002-04-18  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/localefwd.h (locale::id::_M_id): Do this correctly,
	as type safety is important, especially on solaris.
	* include/bits/istream.tcc (istream::read): Clean.
	(istream::readsome): Same.
	* locale.cc: Wrap lines.

	* testsuite/21_strings/inserters_extractors.cc: Tweaks.
	* testsuite/27_io/instantiations.cc (test): Add bool variable...
	* testsuite/21_strings/capacity.cc: Clean.

From-SVN: r52501
parent 2f82dbf8
2002-04-18 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/localefwd.h (locale::id::_M_id): Do this correctly,
as type safety is important, especially on solaris.
* include/bits/istream.tcc (istream::read): Clean.
(istream::readsome): Same.
* locale.cc: Wrap lines.
* testsuite/21_strings/inserters_extractors.cc: Tweaks.
* testsuite/27_io/instantiations.cc (test): Add bool variable...
* testsuite/21_strings/capacity.cc: Clean.
2002-04-17 Phil Edwards <pme@gcc.gnu.org> 2002-04-17 Phil Edwards <pme@gcc.gnu.org>
* docs/doxygen/doxygroups.cc: New group on binary searching. * docs/doxygen/doxygroups.cc: New group on binary searching.
......
...@@ -777,39 +777,28 @@ namespace std ...@@ -777,39 +777,28 @@ namespace std
sentry __cerb(*this, true); sentry __cerb(*this, true);
if (__cerb) if (__cerb)
{ {
if (__n > 0) try
{ {
try const int_type __eof = traits_type::eof();
{ __streambuf_type* __sb = this->rdbuf();
const int_type __eof = traits_type::eof(); int_type __c = __sb->sgetc();
__streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sbumpc(); while (_M_gcount < __n && __c != __eof)
bool __testeof = __c == __eof;
while (_M_gcount < __n - 1 && !__testeof)
{
*__s++ = traits_type::to_char_type(__c);
++_M_gcount;
__c = __sb->sbumpc();
__testeof = __c == __eof;
}
if (__testeof)
this->setstate(ios_base::eofbit | ios_base::failbit);
else
{
// _M_gcount == __n - 1
*__s++ = traits_type::to_char_type(__c);
++_M_gcount;
}
}
catch(exception& __fail)
{ {
// 27.6.1.3 paragraph 1 *__s++ = traits_type::to_char_type(__c);
// Turn this on without causing an ios::failure to be thrown. ++_M_gcount;
this->setstate(ios_base::badbit); __c = __sb->snextc();
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
} }
if (__c == __eof)
this->setstate(ios_base::eofbit | ios_base::failbit);
}
catch(exception& __fail)
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
this->setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
} }
} }
else else
...@@ -822,32 +811,30 @@ namespace std ...@@ -822,32 +811,30 @@ namespace std
basic_istream<_CharT, _Traits>:: basic_istream<_CharT, _Traits>::
readsome(char_type* __s, streamsize __n) readsome(char_type* __s, streamsize __n)
{ {
const int_type __eof = traits_type::eof();
_M_gcount = 0; _M_gcount = 0;
sentry __cerb(*this, true); sentry __cerb(*this, true);
if (__cerb) if (__cerb)
{ {
if (__n > 0) try
{ {
try const int_type __eof = traits_type::eof();
{ streamsize __num = this->rdbuf()->in_avail();
streamsize __num = this->rdbuf()->in_avail(); if (__num != static_cast<streamsize>(__eof))
if (__num != static_cast<streamsize>(__eof))
{
__num = min(__num, __n);
_M_gcount = this->rdbuf()->sgetn(__s, __num);
}
else
this->setstate(ios_base::eofbit);
}
catch(exception& __fail)
{ {
// 27.6.1.3 paragraph 1 __num = min(__num, __n);
// Turn this on without causing an ios::failure to be thrown. if (__num)
this->setstate(ios_base::badbit); _M_gcount = this->rdbuf()->sgetn(__s, __num);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
} }
else
this->setstate(ios_base::eofbit);
}
catch(exception& __fail)
{
// 27.6.1.3 paragraph 1
// Turn this on without causing an ios::failure to be thrown.
this->setstate(ios_base::badbit);
if ((this->exceptions() & ios_base::badbit) != 0)
__throw_exception_again;
} }
} }
else else
......
...@@ -455,14 +455,11 @@ namespace std ...@@ -455,14 +455,11 @@ namespace std
// counted on to be zero-initialized. // counted on to be zero-initialized.
id(); id();
size_t inline size_t
_M_id() const _M_id() const
{ {
if (!_M_index) if (!_M_index)
{ _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
__exchange_and_add(&_S_highwater, 1);
_M_index = _S_highwater;
}
return _M_index - 1; return _M_index - 1;
} }
}; };
......
...@@ -226,7 +226,8 @@ namespace std ...@@ -226,7 +226,8 @@ namespace std
locale::operator==(const locale& __rhs) const throw() locale::operator==(const locale& __rhs) const throw()
{ {
string __name = this->name(); string __name = this->name();
return (_M_impl == __rhs._M_impl || (__name != "*" && __name == __rhs.name())); return (_M_impl == __rhs._M_impl
|| (__name != "*" && __name == __rhs.name()));
} }
const locale& const locale&
......
// 1999-05-11 bkoz // 1999-05-11 bkoz
// Copyright (C) 1999 Free Software Foundation, Inc. // Copyright (C) 1999, 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
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
// 21.3.3 string capacity // 21.3.3 string capacity
#include <string> #include <string>
#include <cstdio>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
template<typename T> template<typename T>
...@@ -37,7 +36,7 @@ template<typename T> ...@@ -37,7 +36,7 @@ template<typename T>
struct B { }; struct B { };
bool test01() void test01()
{ {
// 1 POD types : resize, capacity, reserve // 1 POD types : resize, capacity, reserve
bool test = true; bool test = true;
...@@ -161,17 +160,11 @@ bool test01() ...@@ -161,17 +160,11 @@ bool test01()
VERIFY( b01 == true ); VERIFY( b01 == true );
sz04 = str02.size(); sz04 = str02.size();
VERIFY( sz03 >= sz04 ); VERIFY( sz03 >= sz04 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
} }
// libstdc++/4548 // libstdc++/4548
// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html // http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html
bool test02() void test02()
{ {
bool test = true; bool test = true;
...@@ -180,12 +173,6 @@ bool test02() ...@@ -180,12 +173,6 @@ bool test02()
std::string str02 = str01; std::string str02 = str01;
str01.reserve(1); str01.reserve(1);
VERIFY( str01.capacity() == 12 ); VERIFY( str01.capacity() == 12 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
} }
#if !__GXX_WEAK__ #if !__GXX_WEAK__
...@@ -206,7 +193,3 @@ int main() ...@@ -206,7 +193,3 @@ int main()
return 0; return 0;
} }
// 1999-07-01 bkoz // 1999-07-01 bkoz
// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 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
...@@ -53,16 +53,20 @@ bool test01(void) ...@@ -53,16 +53,20 @@ bool test01(void)
std::istringstream istrs01(str01); std::istringstream istrs01(str01);
istrs01 >> str10; istrs01 >> str10;
VERIFY( str10 == str02 ); VERIFY( str10 == str02 );
try { try
std::istringstream::int_type i01 = istrs01.peek(); //a-boo {
VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' ); std::istringstream::int_type i01 = istrs01.peek(); //a-boo
} VERIFY( std::istringstream::traits_type::to_char_type(i01) == ' ' );
catch(std::exception& fail) { }
VERIFY( false ); // shouldn't throw catch(std::exception& fail)
} {
VERIFY( false ); // shouldn't throw
}
istrs01.clear();
istrs01 >> str10; istrs01 >> str10;
VERIFY( str10 == str03 ); VERIFY( str10 == str03 );
istrs01.clear();
istrs01 >> str10; istrs01 >> str10;
VERIFY( str10 == str04 ); // sentry picks out the white spaces. . VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
...@@ -72,73 +76,86 @@ bool test01(void) ...@@ -72,73 +76,86 @@ bool test01(void)
// istream& getline(istream&, string&, char) // istream& getline(istream&, string&, char)
// istream& getline(istream&, string&) // istream& getline(istream&, string&)
try { try
getline(istrs01, str10); {
VERIFY( !istrs01.fail() ); istrs01.clear();
VERIFY( !istrs01.eof() ); getline(istrs01, str10);
VERIFY( istrs01.good() ); VERIFY( !istrs01.fail() );
VERIFY( str10 == " bay" ); VERIFY( !istrs01.eof() );
} VERIFY( istrs01.good() );
catch(std::exception& fail) { VERIFY( str10 == " bay" );
VERIFY( false ); // shouldn't throw }
} catch(std::exception& fail)
{
try { VERIFY( false ); // shouldn't throw
istrs01.clear(); }
getline(istrs01, str10,'\t');
VERIFY( !istrs01.fail() ); try
VERIFY( !istrs01.eof() ); {
VERIFY( istrs01.good() ); istrs01.clear();
VERIFY( str10 == str05 ); getline(istrs01, str10,'\t');
} VERIFY( !istrs01.fail() );
catch(std::exception& fail) { VERIFY( !istrs01.eof() );
VERIFY( false ); // shouldn't throw VERIFY( istrs01.good() );
} VERIFY( str10 == str05 );
}
try { catch(std::exception& fail)
istrs01.clear(); {
getline(istrs01, str10,'\t'); VERIFY( false ); // shouldn't throw
VERIFY( !istrs01.fail() ); }
VERIFY( !istrs01.eof() );
VERIFY( istrs01.good() ); try
VERIFY( str10 == str05 ); {
} istrs01.clear();
catch(std::exception& fail) { getline(istrs01, str10,'\t');
VERIFY( false ); // shouldn't throw VERIFY( !istrs01.fail() );
} VERIFY( !istrs01.eof() );
VERIFY( istrs01.good() );
try { VERIFY( str10 == str05 );
istrs01.clear(); }
getline(istrs01, str10, '.'); catch(std::exception& fail)
VERIFY( !istrs01.fail() ); {
VERIFY( istrs01.eof() ); VERIFY( false ); // shouldn't throw
VERIFY( !istrs01.good() ); }
VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
} try
catch(std::exception& fail) { {
VERIFY( false ); // shouldn't throw istrs01.clear();
} getline(istrs01, str10, '.');
VERIFY( !istrs01.fail() );
try { VERIFY( istrs01.eof() );
getline(istrs02, str10); VERIFY( !istrs01.good() );
VERIFY( istrs02.fail() ); VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
VERIFY( istrs02.eof() ); }
VERIFY( str10 =="\t from Elk Rapids to the point reminds me of miles" ); catch(std::exception& fail)
} {
catch(std::exception& fail) { VERIFY( false ); // shouldn't throw
VERIFY( false ); // shouldn't throw }
}
try
{
getline(istrs02, str10);
VERIFY( istrs02.fail() );
VERIFY( istrs02.eof() );
VERIFY( str10 =="\t from Elk Rapids to the point reminds me of miles" );
}
catch(std::exception& fail)
{
VERIFY( false ); // shouldn't throw
}
// ostream& operator<<(ostream&, const basic_string&) // ostream& operator<<(ostream&, const basic_string&)
std::ostringstream ostrs01; std::ostringstream ostrs01;
try { try
ostrs01 << str01; {
VERIFY( ostrs01.str() == str01 ); ostrs01 << str01;
} VERIFY( ostrs01.str() == str01 );
catch(std::exception& fail) { }
VERIFY( false ); catch(std::exception& fail)
} {
VERIFY( false );
}
std::string hello_world; std::string hello_world;
std::cout << hello_world; std::cout << hello_world;
......
// 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
...@@ -35,6 +35,7 @@ void ...@@ -35,6 +35,7 @@ void
test01() test01()
{ {
using namespace std; using namespace std;
bool test = true;
string x (" this is text"); string x (" this is text");
istringstream sin (x); istringstream sin (x);
ostringstream sout; ostringstream sout;
...@@ -47,7 +48,7 @@ test01() ...@@ -47,7 +48,7 @@ test01()
>> setprecision(5) >> setprecision(5)
>> setw(20) >> setw(20)
>> ws; >> ws;
VERIFY(sin); VERIFY(sin.good());
sout << resetiosflags(ios_base::dec) sout << resetiosflags(ios_base::dec)
<< setiosflags(ios_base::dec) << setiosflags(ios_base::dec)
...@@ -56,7 +57,7 @@ test01() ...@@ -56,7 +57,7 @@ test01()
<< setprecision(5) << setprecision(5)
<< setw(20) << setw(20)
<< ends << flush << endl; << ends << flush << endl;
VERIFY(sout); VERIFY(sout.good());
} }
......
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