diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2001-06-12 02:30:37 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2001-06-12 02:30:37 +0000 |
commit | 3b0fd4bcdb019756a3f7902df689ee3568b866ba (patch) | |
tree | 1c224bfab1803de1debc3780ac8f957f19874588 | |
parent | 9dffe3b49e68cbab5ae18813b725eafd9c985ea5 (diff) | |
download | gcc-3b0fd4bcdb019756a3f7902df689ee3568b866ba.zip gcc-3b0fd4bcdb019756a3f7902df689ee3568b866ba.tar.gz gcc-3b0fd4bcdb019756a3f7902df689ee3568b866ba.tar.bz2 |
basic_string.h (string::compare): Adjust signatures as per DR 5.
2001-06-11 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/3126
* include/bits/basic_string.h (string::compare): Adjust signatures
as per DR 5.
* include/bits/basic_string.tcc: And here.
libstdc++/2346
* config/c_io_stdio.h: Remove whitespace.
* testsuite/27_io/istream_seeks.cc (test03): Add regression.
(test02): Add regression.
* testsuite/27_io/istream_seeks-3.tst: New file.
From-SVN: r43240
-rw-r--r-- | libstdc++-v3/ChangeLog | 13 | ||||
-rw-r--r-- | libstdc++-v3/config/c_io_stdio.h | 10 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 23 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/istream_seeks-3.tst | 10 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/istream_seeks.cc | 74 |
6 files changed, 122 insertions, 16 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c815979..ccf316f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2001-06-11 Benjamin Kosnik <bkoz@redhat.com> + + libstdc++/3126 + * include/bits/basic_string.h (string::compare): Adjust signatures + as per DR 5. + * include/bits/basic_string.tcc: And here. + + libstdc++/2346 + * config/c_io_stdio.h: Remove whitespace. + * testsuite/27_io/istream_seeks.cc (test03): Add regression. + (test02): Add regression. + * testsuite/27_io/istream_seeks-3.tst: New file. + 2001-06-11 Phil Edwards <pme@sources.redhat.com> * README: Update to reflect reality. diff --git a/libstdc++-v3/config/c_io_stdio.h b/libstdc++-v3/config/c_io_stdio.h index f24f6a8..1ea8b30 100644 --- a/libstdc++-v3/config/c_io_stdio.h +++ b/libstdc++-v3/config/c_io_stdio.h @@ -92,13 +92,3 @@ namespace std } #endif // _CPP_IO_STDIO_H - - - - - - - - - - diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 4067396..ef08da1 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -842,9 +842,15 @@ namespace std int compare(const _CharT* __s) const; +#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS +// 5. String::compare specification questionable + int + compare(size_type __pos, size_type __n1, const _CharT* __s) const; + int compare(size_type __pos, size_type __n1, const _CharT* __s, - size_type __n2 = npos) const; + size_type __n2) const; +#endif }; diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 7c74b67..9a05d2c 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -812,6 +812,24 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> int basic_string <_CharT,_Traits,_Alloc>:: + compare(size_type __pos, size_type __n1, const _CharT* __s) const + { + size_type __size = this->size(); + if (__pos > __size) + __throw_out_of_range("basic_string::compare"); + + size_type __osize = traits_type::length(__s); + size_type __rsize = min(__size - __pos, __n1); + size_type __len = min(__rsize, __osize); + int __r = traits_type::compare(_M_data() + __pos, __s, __len); + if (!__r) + __r = __rsize - __osize; + return __r; + } + + template<typename _CharT, typename _Traits, typename _Alloc> + int + basic_string <_CharT,_Traits,_Alloc>:: compare(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) const { @@ -839,7 +857,6 @@ namespace std _Traits::copy(__buf, __str.data(), __bytes); __buf[__bytes] = _CharT(); } +} // namespace std -} // std:: - -#endif /* _CPP_BITS_STRING_TCC */ +#endif diff --git a/libstdc++-v3/testsuite/27_io/istream_seeks-3.tst b/libstdc++-v3/testsuite/27_io/istream_seeks-3.tst new file mode 100644 index 0000000..dc45fc9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/istream_seeks-3.tst @@ -0,0 +1,10 @@ +0-0 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-1 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-2 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-3 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-4 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-5 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-6 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-7 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-8 lootpack, peanut butter wolf, rob swift, madlib, quasimoto +0-9 lootpack, peanut butter wolf, rob swift, madlib, quasimoto diff --git a/libstdc++-v3/testsuite/27_io/istream_seeks.cc b/libstdc++-v3/testsuite/27_io/istream_seeks.cc index 97ef01b..a8f138e 100644 --- a/libstdc++-v3/testsuite/27_io/istream_seeks.cc +++ b/libstdc++-v3/testsuite/27_io/istream_seeks.cc @@ -1,6 +1,6 @@ // 2000-06-29 bkoz -// Copyright (C) 2000 Free Software Foundation +// Copyright (C) 2000, 2001 Free Software Foundation // // 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 @@ -28,7 +28,6 @@ #include <fstream> #include <debug_assert.h> - bool test01() { using namespace std; @@ -64,6 +63,71 @@ bool test01() return test; } +const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::iostream& stream) +{ + for (int j = 0; j < times; j++) + { + bool test = true; + std::streampos begin = stream.tellg(); + + for (int i = 0; i < times; ++i) + stream << j << '-' << i << s << '\n'; + + stream.seekg(begin); + std::streampos end = stream.tellg(); + std::streampos badpos = std::streampos(std::streambuf::off_type(-1)); + } +} + +void check_contents(std::iostream& stream) +{ + bool test = true; + + stream.clear(); + stream.seekg(0, std::ios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, '\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// fstream +// libstdc++/2346 +void test02() +{ + std::fstream ofstrm; + ofstrm.open("istream_seeks-3.txt", std::ios::out); + if (!ofstrm) + abort(); + write_rewind(ofstrm); + ofstrm.close(); + + std::fstream ifstrm; + ifstrm.open("istream_seeks-3.txt", std::ios::in); + check_contents(ifstrm); + ifstrm.close(); +} + +// stringstream +// libstdc++/2346 +void test03() +{ + std::stringstream sstrm; + + write_rewind(sstrm); + check_contents(sstrm); +} + // fstreams void test04(void) { @@ -289,7 +353,13 @@ void test05(void) int main() { test01(); + + test02(); + test03(); + test04(); test05(); return 0; } + + |