+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
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;
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();
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}