aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kosnik <bkoz@redhat.com>2001-05-02 05:50:20 +0000
committerBenjamin Kosnik <bkoz@gcc.gnu.org>2001-05-02 05:50:20 +0000
commita85afd69a3321ef87f6dc1bec4fabb0301176afd (patch)
tree8d0c04e05b848b07f2a4a90dc2096813f1c4b410
parent0a5fee3256ec62528a5aba473854929be72a4c3a (diff)
downloadgcc-a85afd69a3321ef87f6dc1bec4fabb0301176afd.zip
gcc-a85afd69a3321ef87f6dc1bec4fabb0301176afd.tar.gz
gcc-a85afd69a3321ef87f6dc1bec4fabb0301176afd.tar.bz2
sbuf_iter.h (istreambuf_iterator): Correct.
2001-05-01 Benjamin Kosnik <bkoz@redhat.com> * include/bits/sbuf_iter.h (istreambuf_iterator): Correct. * testsuite/24_iterators/istreambuf_iterator.cc (test02): Add test. * include/bits/std_sstream.h (stringbuf): Leak copied string. * testsuite/24_iterators/ostreambuf_iterator.cc: Correct. From-SVN: r41755
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/sbuf_iter.h16
-rw-r--r--libstdc++-v3/include/bits/std_sstream.h10
-rw-r--r--libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc41
-rw-r--r--libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc22
5 files changed, 75 insertions, 23 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c682576..49a8cf8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2001-05-01 Benjamin Kosnik <bkoz@redhat.com>
+
+ * include/bits/sbuf_iter.h (istreambuf_iterator): Correct.
+ * testsuite/24_iterators/istreambuf_iterator.cc (test02): Add test.
+
+ * include/bits/std_sstream.h (stringbuf): Leak
+ copied string.
+ * testsuite/24_iterators/ostreambuf_iterator.cc: Correct.
+
2001-05-01 Tom Browder <tbrowder@home.com>
* docs/html/ext/howto.html: Fix typo.
diff --git a/libstdc++-v3/include/bits/sbuf_iter.h b/libstdc++-v3/include/bits/sbuf_iter.h
index 6bec6d2..4935c11 100644
--- a/libstdc++-v3/include/bits/sbuf_iter.h
+++ b/libstdc++-v3/include/bits/sbuf_iter.h
@@ -141,18 +141,15 @@ namespace std
return *this;
}
-#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
- // 14882 says return a proxy object. It should be a const
- // proxy object, but since this class is not mandated, it
- // should allow this signature:
- const __istreambufiter_type
+ __istreambufiter_type
operator++(int)
{
+ __istreambufiter_type __old = *this;
if (_M_sbuf)
- _M_c = _M_sbuf->sbumpc();
- return *this;
+ __old._M_c = _M_sbuf->sbumpc();
+ _M_c = -2;
+ return __old;
}
-#endif
bool
equal(const __istreambufiter_type& __b)
@@ -205,3 +202,6 @@ namespace std
} // namespace std
#endif
+
+
+
diff --git a/libstdc++-v3/include/bits/std_sstream.h b/libstdc++-v3/include/bits/std_sstream.h
index 9a1e75a..0da71e4 100644
--- a/libstdc++-v3/include/bits/std_sstream.h
+++ b/libstdc++-v3/include/bits/std_sstream.h
@@ -71,16 +71,14 @@ namespace std
explicit
basic_stringbuf(const __string_type& __str,
ios_base::openmode __mode = ios_base::in | ios_base::out)
- : __streambuf_type(), _M_string(__str)
+ : __streambuf_type(), _M_string(__str.c_str())
{ _M_stringbuf_init(__mode); }
// Get and set:
__string_type
str() const
{
- if (_M_mode & ios_base::in && !(_M_mode & ios_base::out))
- return _M_string;
- else
+ if (_M_mode & ios_base::out)
{
// This is the deal: _M_string.size() is value that
// represents the size of the intial string that makes
@@ -91,6 +89,8 @@ namespace std
__len = max(__size_type(_M_out_end - _M_out_beg), __len);
return __string_type(_M_out_beg, _M_out_beg + __len);
}
+ else
+ return _M_string;
}
void
@@ -121,7 +121,7 @@ namespace std
if (_M_mode & ios_base::ate)
_M_really_sync(0, _M_buf_size);
else
- _M_really_sync(0, 0);
+ _M_really_sync(0, 0);
}
// Overridden virtual functions:
diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc
index 78d3633..8325c97 100644
--- a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc
+++ b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc
@@ -1,6 +1,6 @@
// 1999-06-28 bkoz
-// Copyright (C) 1999 Free Software Foundation, Inc.
+// Copyright (C) 1999, 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
@@ -102,7 +102,7 @@ bool test01(void)
std::istringstream istrs02(str01);
cistreambuf_iter istrb_it28(istrs02);
- for (int i = 0; i < sizeof(slit01) - 3;)
+ for (int i = 0; i < sizeof(slit01) - 2;)
{
c = *++istrb_it28;
VERIFY( c == slit01[++i] );
@@ -115,9 +115,46 @@ bool test01(void)
return test;
}
+// libstdc++/2627
+void test02()
+{
+ bool test = true;
+ const std::string s("free the vieques");
+
+ // 1
+ std::string res_postfix;
+ std::istringstream iss01(s);
+ std::istreambuf_iterator<char> isbufit01(iss01);
+ for (int j = 0; j < s.size(); ++j, isbufit01++)
+ res_postfix += *isbufit01;
+
+ // 2
+ std::string res_prefix;
+ std::istringstream iss02(s);
+ std::istreambuf_iterator<char> isbufit02(iss02);
+ for (int j = 0; j < s.size(); ++j, ++isbufit02)
+ res_prefix += *isbufit02;
+
+ // 3 mixed
+ std::string res_mixed;
+ std::istringstream iss03(s);
+ std::istreambuf_iterator<char> isbufit03(iss03);
+ for (int j = 0; j < int(s.size() / 2); ++j)
+ {
+ res_mixed += *isbufit03;
+ ++isbufit03;
+ res_mixed += *isbufit03;
+ isbufit03++;
+ }
+
+ VERIFY ( res_postfix == res_prefix );
+ VERIFY ( res_mixed == res_prefix );
+}
+
int main()
{
test01();
+ test02();
return 0;
}
diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
index 9f1544f..eec7f98 100644
--- a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
+++ b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
@@ -30,7 +30,9 @@ bool test01(void)
typedef costreambuf_iter::streambuf_type cstreambuf_type;
bool test = true;
const char slit01[] = "playa hermosa, liberia, guanacaste";
+ const char slit02[] = "bodega bay, lost coast, california";
std::string str01(slit01);
+ std::string str02(slit02);
std::string tmp;
std::stringbuf strbuf01;
std::stringbuf strbuf02(str01);
@@ -61,21 +63,25 @@ bool test01(void)
// charT operator*() const
// ostreambuf_iterator& operator++();
// ostreambuf_iterator& operator++(int);
- costreambuf_iter ostrb_it27(ostrs00);
+ costreambuf_iter ostrb_it27(ostrs01);
VERIFY( !ostrb_it27.failed() );
- for (int i = 0; i < strlen(slit01) - 2; ++i)
- ostrb_it27 = 'a';
+ int j = str02.size();
+ for (int i = 0; i < j; ++i)
+ ostrb_it27 = str02[i];
VERIFY( !ostrb_it27.failed() );
- tmp = ostrs00.str();
- VERIFY ( tmp == str01 );
+ tmp = ostrs01.str();
+ VERIFY ( tmp != str01 );
+ VERIFY ( tmp == str02 );
- costreambuf_iter ostrb_it28(ostrs01);
+ costreambuf_iter ostrb_it28(ostrs00);
VERIFY( !ostrb_it28.failed() );
- for (int i = 0; i < strlen(slit01) + 1; ++i)
+ j = ostrs00.str().size();
+ for (int i = 0; i < j + 2; ++i)
ostrb_it28 = 'b';
VERIFY( !ostrb_it28.failed() );
- tmp = ostrs01.str();
+ tmp = ostrs00.str();
VERIFY ( tmp != str01 );
+ VERIFY ( tmp != str02 );
#ifdef DEBUG_ASSERT
assert(test);