On 04/11/20 12:43 -0800, Thomas Rodgers wrote:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97719
On Nov 4, 2020, at 11:54 AM, Stephan Bergmann <sberg...@redhat.com> wrote:
On 07/10/2020 18:55, Thomas Rodgers wrote:
From: Thomas Rodgers <trodg...@redhat.com>
New ctors and ::view() accessor for -
* basic_stingbuf
* basic_istringstream
* basic_ostringstream
* basic_stringstreamm
New ::get_allocator() accessor for basic_stringbuf.
I found that this
<https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a0e4d7b44c544c84cffc7ff9c64b6f1af14fb08d>
"libstdc++: Implement C++20 features for <sstream>" changed the behavior of
$ cat test.cc
#include <iostream>
#include <iterator>
#include <sstream>
int main() {
std::stringstream s("a");
std::istreambuf_iterator<char> i(s);
if (i != std::istreambuf_iterator<char>()) std::cout << *i << '\n';
}
$ g++ -std=c++20 test.cc
$ ./a.out
from printing "a" to printing nothing. (The `i != ...` comparison appears to change i
from pointing at "a" to pointing to null, and returns false.)
I ran into this when building LibreOffice, and I hope test.cc is a faithfully
minimized reproducer. However, I know little about std::istreambuf_iterator,
so it may well be that the code isn't even valid.
I'm testing this patch.
commit 1ca2fe0fc85403c6ea4e0775b5da051ff0eebc96
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Wed Nov 4 21:44:05 2020
libstdc++: Fix default mode of new basic_stringstream constructor [PR 97719]
libstdc++-v3/ChangeLog:
PR libstdc++/97719
* include/std/sstream (basic_stringstream(string_type&&, openmode)):
Fix default argument.
* testsuite/27_io/basic_stringstream/cons/char/97719.cc: New test.
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 33a00486606c..8acf1eb259ab 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -976,7 +976,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
explicit
basic_stringstream(__string_type&& __str,
- ios_base::openmode __mode = ios_base::out
+ ios_base::openmode __mode = ios_base::in
| ios_base::out)
: __iostream_type(), _M_stringbuf(std::move(__str), __mode)
{ this->init(std::__addressof(_M_stringbuf)); }
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc
new file mode 100644
index 000000000000..fa523a803b6d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/97719.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 2020 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ // PR libstdc++/97719
+ std::string str = "a";
+ std::stringstream s(std::move(str));
+ std::istreambuf_iterator<char> i(s);
+ VERIFY( i != std::istreambuf_iterator<char>() );
+ VERIFY( *i == 'a' );
+}
+
+int
+main()
+{
+ test01();
+}