aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2004-10-01 21:01:29 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2004-10-01 21:01:29 +0000
commitabccc4f66c34723d4f91654a3a52cc1b50effebc (patch)
tree7e0837c3812e17553fed0c08fcfae5ab1183eeee
parentb89dc911b33013c93da4a9441d5f39d59ba01d68 (diff)
downloadgcc-abccc4f66c34723d4f91654a3a52cc1b50effebc.zip
gcc-abccc4f66c34723d4f91654a3a52cc1b50effebc.tar.gz
gcc-abccc4f66c34723d4f91654a3a52cc1b50effebc.tar.bz2
sstream.tcc (pbackfail): Implement correctly 27.7.1.3/2, bullet 2...
2004-10-01 Paolo Carlini <pcarlini@suse.de> * include/bits/sstream.tcc (pbackfail): Implement correctly 27.7.1.3/2, bullet 2: if mode & ios_base::out is false do not write in the buffer. * testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc: New. * testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc: Likewise. * testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc: Likewise. * testsuite/27_io/basic_istream/putback/char/1.cc: Tweak consistently. From-SVN: r88407
-rw-r--r--libstdc++-v3/ChangeLog11
-rw-r--r--libstdc++-v3/include/bits/sstream.tcc29
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc4
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc76
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc64
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc76
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc64
7 files changed, 310 insertions, 14 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 88bd3a7..ff73a85c 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,16 @@
2004-10-01 Paolo Carlini <pcarlini@suse.de>
+ * include/bits/sstream.tcc (pbackfail): Implement correctly
+ 27.7.1.3/2, bullet 2: if mode & ios_base::out is false do not
+ write in the buffer.
+ * testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc: New.
+ * testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc: Likewise.
+ * testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc: Likewise.
+ * testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc: Likewise.
+ * testsuite/27_io/basic_istream/putback/char/1.cc: Tweak consistently.
+
+2004-10-01 Paolo Carlini <pcarlini@suse.de>
+
* include/bits/sstream.tcc (seekpos): Minor rearrangement of two
conditionals consistently with seekoff.
* include/std/std_sstream.h (setbuf): Avoid a string temporary.
diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc
index 19a24bf..76cda29 100644
--- a/libstdc++-v3/include/bits/sstream.tcc
+++ b/libstdc++-v3/include/bits/sstream.tcc
@@ -47,24 +47,29 @@ namespace std
pbackfail(int_type __c)
{
int_type __ret = traits_type::eof();
- const bool __testeof = traits_type::eq_int_type(__c, __ret);
-
if (this->eback() < this->gptr())
{
- const bool __testeq = traits_type::eq(traits_type::to_char_type(__c),
- this->gptr()[-1]);
- this->gbump(-1);
-
// Try to put back __c into input sequence in one of three ways.
// Order these tests done in is unspecified by the standard.
- if (!__testeof && __testeq)
- __ret = __c;
- else if (__testeof)
- __ret = traits_type::not_eof(__c);
+ const bool __testeof = traits_type::eq_int_type(__c, __ret);
+ if (!__testeof)
+ {
+ const bool __testeq = traits_type::eq(traits_type::
+ to_char_type(__c),
+ this->gptr()[-1]);
+ const bool __testout = this->_M_mode & ios_base::out;
+ if (__testeq || __testout)
+ {
+ this->gbump(-1);
+ if (!__testeq)
+ *this->gptr() = traits_type::to_char_type(__c);
+ __ret = __c;
+ }
+ }
else
{
- *this->gptr() = traits_type::to_char_type(__c);
- __ret = __c;
+ this->gbump(-1);
+ __ret = traits_type::not_eof(__c);
}
}
return __ret;
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc
index 870d57a..b3c64f6 100644
--- a/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc
@@ -49,11 +49,11 @@ test01()
is_04.ignore(30);
is_04.clear();
state1 = is_04.rdstate();
- is_04.putback('|');
+ is_04.putback('t');
VERIFY( is_04.gcount() == 0 ); // DR 60
state2 = is_04.rdstate();
VERIFY( state1 == state2 );
- VERIFY( is_04.peek() == '|' );
+ VERIFY( is_04.peek() == 't' );
// istream& unget()
is_04.clear();
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc
new file mode 100644
index 0000000..5e83299
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc
@@ -0,0 +1,76 @@
+// 2004-10-01 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class my_stringbuf : public std::stringbuf
+{
+public:
+ my_stringbuf(const std::string& str, std::ios_base::openmode mode)
+ : std::stringbuf(str, mode) { }
+
+ int_type
+ pub_pbackfail(int_type c)
+ { return this->pbackfail(c); }
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef my_stringbuf::int_type int_type;
+ typedef my_stringbuf::traits_type traits_type;
+
+ my_stringbuf sbuf("any", ios_base::in | ios_base::out);
+
+ int_type c = sbuf.sgetc();
+ VERIFY( c == 'a' );
+
+ c = sbuf.pub_pbackfail('z');
+ VERIFY( c == traits_type::eof() );
+ c = sbuf.sbumpc();
+ VERIFY( c == 'a' );
+
+ c = sbuf.pub_pbackfail('a');
+ VERIFY( c == 'a' );
+ c = sbuf.sbumpc();
+ VERIFY( c == 'a' );
+
+ c = sbuf.pub_pbackfail('x');
+ VERIFY( c == 'x' );
+ c = sbuf.sbumpc();
+ VERIFY( c == 'x' );
+
+ const int_type eof = traits_type::eof();
+ c = sbuf.pub_pbackfail(eof);
+ VERIFY( c == traits_type::not_eof(eof) );
+ c = sbuf.sgetc();
+ VERIFY( c == 'x' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc
new file mode 100644
index 0000000..832cee6
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc
@@ -0,0 +1,64 @@
+// 2004-10-01 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class my_stringbuf : public std::stringbuf
+{
+public:
+ my_stringbuf(const std::string& str, std::ios_base::openmode mode)
+ : std::stringbuf(str, mode) { }
+
+ int_type
+ pub_pbackfail(int_type __c)
+ { return this->pbackfail(__c); }
+};
+
+// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if
+// mode & ios_base::out is nonzero, ..."
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef my_stringbuf::int_type int_type;
+ typedef my_stringbuf::traits_type traits_type;
+
+ my_stringbuf sbuf("any", ios_base::in);
+
+ int_type c = sbuf.sbumpc();
+ VERIFY( c == 'a' );
+
+ c = sbuf.pub_pbackfail('x');
+ VERIFY( c == traits_type::eof() );
+ VERIFY( sbuf.str() == "any" );
+ c = sbuf.sgetc();
+ VERIFY( c == 'n' );
+}
+
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc
new file mode 100644
index 0000000..84ea872
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc
@@ -0,0 +1,76 @@
+// 2004-10-01 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class my_stringbuf : public std::wstringbuf
+{
+public:
+ my_stringbuf(const std::wstring& str, std::ios_base::openmode mode)
+ : std::wstringbuf(str, mode) { }
+
+ int_type
+ pub_pbackfail(int_type c)
+ { return this->pbackfail(c); }
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef my_stringbuf::int_type int_type;
+ typedef my_stringbuf::traits_type traits_type;
+
+ my_stringbuf sbuf(L"any", ios_base::in | ios_base::out);
+
+ int_type c = sbuf.sgetc();
+ VERIFY( c == L'a' );
+
+ c = sbuf.pub_pbackfail(L'z');
+ VERIFY( c == traits_type::eof() );
+ c = sbuf.sbumpc();
+ VERIFY( c == L'a' );
+
+ c = sbuf.pub_pbackfail(L'a');
+ VERIFY( c == L'a' );
+ c = sbuf.sbumpc();
+ VERIFY( c == L'a' );
+
+ c = sbuf.pub_pbackfail(L'x');
+ VERIFY( c == L'x' );
+ c = sbuf.sbumpc();
+ VERIFY( c == L'x' );
+
+ const int_type eof = traits_type::eof();
+ c = sbuf.pub_pbackfail(eof);
+ VERIFY( c == traits_type::not_eof(eof) );
+ c = sbuf.sgetc();
+ VERIFY( c == L'x' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc
new file mode 100644
index 0000000..eb5172f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc
@@ -0,0 +1,64 @@
+// 2004-10-01 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals]
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class my_stringbuf : public std::wstringbuf
+{
+public:
+ my_stringbuf(const std::wstring& str, std::ios_base::openmode mode)
+ : std::wstringbuf(str, mode) { }
+
+ int_type
+ pub_pbackfail(int_type __c)
+ { return this->pbackfail(__c); }
+};
+
+// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if
+// mode & ios_base::out is nonzero, ..."
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef my_stringbuf::int_type int_type;
+ typedef my_stringbuf::traits_type traits_type;
+
+ my_stringbuf sbuf(L"any", ios_base::in);
+
+ int_type c = sbuf.sbumpc();
+ VERIFY( c == L'a' );
+
+ c = sbuf.pub_pbackfail(L'x');
+ VERIFY( c == traits_type::eof() );
+ VERIFY( sbuf.str() == L"any" );
+ c = sbuf.sgetc();
+ VERIFY( c == L'n' );
+}
+
+
+int main()
+{
+ test01();
+ return 0;
+}