summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2002-04-18 23:47:50 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2002-04-18 23:47:50 +0000
commit86988432fce0c7ea15f9e0328296c71a25128825 (patch)
treeb620818e988b06e19978d5a14d76296e2d300e1a /libstdc++-v3
parentd4f13d242d5c9a58002cf467666488ea120e0803 (diff)
downloadgcc-86988432fce0c7ea15f9e0328296c71a25128825.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@52501 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog12
-rw-r--r--libstdc++-v3/include/bits/istream.tcc85
-rw-r--r--libstdc++-v3/include/bits/localefwd.h7
-rw-r--r--libstdc++-v3/src/locale.cc3
-rw-r--r--libstdc++-v3/testsuite/21_strings/capacity.cc23
-rw-r--r--libstdc++-v3/testsuite/21_strings/inserters_extractors.cc161
-rw-r--r--libstdc++-v3/testsuite/27_io/instantiations.cc7
7 files changed, 148 insertions, 150 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8b509cc627d..42ac41617ef 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,15 @@
+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>
* docs/doxygen/doxygroups.cc: New group on binary searching.
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index 9ee38a42fc7..6b2e4ca4acb 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -777,39 +777,28 @@ namespace std
sentry __cerb(*this, true);
if (__cerb)
{
- if (__n > 0)
+ try
{
- try
- {
- const int_type __eof = traits_type::eof();
- __streambuf_type* __sb = this->rdbuf();
- int_type __c = __sb->sbumpc();
- 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)
+ const int_type __eof = traits_type::eof();
+ __streambuf_type* __sb = this->rdbuf();
+ int_type __c = __sb->sgetc();
+
+ while (_M_gcount < __n && __c != __eof)
{
- // 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;
+ *__s++ = traits_type::to_char_type(__c);
+ ++_M_gcount;
+ __c = __sb->snextc();
}
+ 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
@@ -822,32 +811,30 @@ namespace std
basic_istream<_CharT, _Traits>::
readsome(char_type* __s, streamsize __n)
{
- const int_type __eof = traits_type::eof();
_M_gcount = 0;
sentry __cerb(*this, true);
if (__cerb)
{
- if (__n > 0)
+ try
{
- try
- {
- streamsize __num = this->rdbuf()->in_avail();
- 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)
+ const int_type __eof = traits_type::eof();
+ streamsize __num = this->rdbuf()->in_avail();
+ if (__num != static_cast<streamsize>(__eof))
{
- // 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;
+ __num = min(__num, __n);
+ if (__num)
+ _M_gcount = this->rdbuf()->sgetn(__s, __num);
}
+ 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
diff --git a/libstdc++-v3/include/bits/localefwd.h b/libstdc++-v3/include/bits/localefwd.h
index c6daeb69014..028c4126b85 100644
--- a/libstdc++-v3/include/bits/localefwd.h
+++ b/libstdc++-v3/include/bits/localefwd.h
@@ -455,14 +455,11 @@ namespace std
// counted on to be zero-initialized.
id();
- size_t
+ inline size_t
_M_id() const
{
if (!_M_index)
- {
- __exchange_and_add(&_S_highwater, 1);
- _M_index = _S_highwater;
- }
+ _M_index = 1 + __exchange_and_add(&_S_highwater, 1);
return _M_index - 1;
}
};
diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc
index 54693cb2059..26c2834eb7d 100644
--- a/libstdc++-v3/src/locale.cc
+++ b/libstdc++-v3/src/locale.cc
@@ -226,7 +226,8 @@ namespace std
locale::operator==(const locale& __rhs) const throw()
{
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&
diff --git a/libstdc++-v3/testsuite/21_strings/capacity.cc b/libstdc++-v3/testsuite/21_strings/capacity.cc
index 3bfb051e0a2..be209e07e0c 100644
--- a/libstdc++-v3/testsuite/21_strings/capacity.cc
+++ b/libstdc++-v3/testsuite/21_strings/capacity.cc
@@ -1,6 +1,6 @@
// 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
// software; you can redistribute it and/or modify it under the
@@ -21,7 +21,6 @@
// 21.3.3 string capacity
#include <string>
-#include <cstdio>
#include <testsuite_hooks.h>
template<typename T>
@@ -37,7 +36,7 @@ template<typename T>
struct B { };
-bool test01()
+void test01()
{
// 1 POD types : resize, capacity, reserve
bool test = true;
@@ -161,17 +160,11 @@ bool test01()
VERIFY( b01 == true );
sz04 = str02.size();
VERIFY( sz03 >= sz04 );
-
-#ifdef DEBUG_ASSERT
- assert(test);
-#endif
-
- return test;
}
// libstdc++/4548
// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html
-bool test02()
+void test02()
{
bool test = true;
@@ -180,12 +173,6 @@ bool test02()
std::string str02 = str01;
str01.reserve(1);
VERIFY( str01.capacity() == 12 );
-
-#ifdef DEBUG_ASSERT
- assert(test);
-#endif
-
- return test;
}
#if !__GXX_WEAK__
@@ -206,7 +193,3 @@ int main()
return 0;
}
-
-
-
-
diff --git a/libstdc++-v3/testsuite/21_strings/inserters_extractors.cc b/libstdc++-v3/testsuite/21_strings/inserters_extractors.cc
index 5d1d9f50b19..41a9a65f6ea 100644
--- a/libstdc++-v3/testsuite/21_strings/inserters_extractors.cc
+++ b/libstdc++-v3/testsuite/21_strings/inserters_extractors.cc
@@ -1,6 +1,6 @@
// 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
// software; you can redistribute it and/or modify it under the
@@ -53,16 +53,20 @@ bool test01(void)
std::istringstream istrs01(str01);
istrs01 >> str10;
VERIFY( str10 == str02 );
- try {
- 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
- }
+ try
+ {
+ 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
+ }
+ istrs01.clear();
istrs01 >> str10;
VERIFY( str10 == str03 );
+ istrs01.clear();
istrs01 >> str10;
VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
@@ -72,73 +76,86 @@ bool test01(void)
// istream& getline(istream&, string&, char)
// istream& getline(istream&, string&)
- try {
- getline(istrs01, str10);
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == " bay" );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10,'\t');
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == str05 );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10,'\t');
- VERIFY( !istrs01.fail() );
- VERIFY( !istrs01.eof() );
- VERIFY( istrs01.good() );
- VERIFY( str10 == str05 );
- }
- catch(std::exception& fail) {
- VERIFY( false ); // shouldn't throw
- }
-
- try {
- istrs01.clear();
- getline(istrs01, str10, '.');
- VERIFY( !istrs01.fail() );
- VERIFY( istrs01.eof() );
- VERIFY( !istrs01.good() );
- VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
- }
- catch(std::exception& fail) {
- 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
- }
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10);
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == " bay" );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10,'\t');
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == str05 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10,'\t');
+ VERIFY( !istrs01.fail() );
+ VERIFY( !istrs01.eof() );
+ VERIFY( istrs01.good() );
+ VERIFY( str10 == str05 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false ); // shouldn't throw
+ }
+
+ try
+ {
+ istrs01.clear();
+ getline(istrs01, str10, '.');
+ VERIFY( !istrs01.fail() );
+ VERIFY( istrs01.eof() );
+ VERIFY( !istrs01.good() );
+ VERIFY( str10 == "\t from Elk Rapids to the point reminds me of miles" );
+ }
+ catch(std::exception& fail)
+ {
+ 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&)
std::ostringstream ostrs01;
- try {
- ostrs01 << str01;
- VERIFY( ostrs01.str() == str01 );
- }
- catch(std::exception& fail) {
- VERIFY( false );
- }
-
+ try
+ {
+ ostrs01 << str01;
+ VERIFY( ostrs01.str() == str01 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false );
+ }
+
std::string hello_world;
std::cout << hello_world;
diff --git a/libstdc++-v3/testsuite/27_io/instantiations.cc b/libstdc++-v3/testsuite/27_io/instantiations.cc
index 6f87982c980..b7ee2b4b6f5 100644
--- a/libstdc++-v3/testsuite/27_io/instantiations.cc
+++ b/libstdc++-v3/testsuite/27_io/instantiations.cc
@@ -1,4 +1,4 @@
-// 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
// software; you can redistribute it and/or modify it under the
@@ -35,6 +35,7 @@ void
test01()
{
using namespace std;
+ bool test = true;
string x (" this is text");
istringstream sin (x);
ostringstream sout;
@@ -47,7 +48,7 @@ test01()
>> setprecision(5)
>> setw(20)
>> ws;
- VERIFY(sin);
+ VERIFY(sin.good());
sout << resetiosflags(ios_base::dec)
<< setiosflags(ios_base::dec)
@@ -56,7 +57,7 @@ test01()
<< setprecision(5)
<< setw(20)
<< ends << flush << endl;
- VERIFY(sout);
+ VERIFY(sout.good());
}