]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
basic_string.h (getline): Qualify call to prevent ADL and add overloads for rvalue...
authorJonathan Wakely <jwakely@redhat.com>
Tue, 12 Aug 2014 15:19:53 +0000 (16:19 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 12 Aug 2014 15:19:53 +0000 (16:19 +0100)
* include/bits/basic_string.h (getline): Qualify call to prevent ADL
and add overloads for rvalue streams.
* testsuite/21_strings/basic_string/inserters_extractors/char/12.cc:
New.
* testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc:
New.

From-SVN: r213869

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc [new file with mode: 0644]

index 65134498fe7f83be1ef2b79eee8a5a6163d3b6e8..1e1e522665a79fde9f5d8317ba91624e38719ab1 100644 (file)
@@ -1,3 +1,12 @@
+2014-08-12  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/bits/basic_string.h (getline): Qualify call to prevent ADL
+       and add overloads for rvalue streams.
+       * testsuite/21_strings/basic_string/inserters_extractors/char/12.cc:
+       New.
+       * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc:
+       New.
+
 2014-08-09  Ulrich Drepper  <drepper@gmail.com>
 
        * include/ext/random.tcc (uniform_on_sphere_helper): Define.
index cd6037677df24be77be43c111d61a993eb46d401..6a54d0c20a946d50c94d5fa0b27560a202765088 100644 (file)
@@ -2811,7 +2811,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline basic_istream<_CharT, _Traits>&
     getline(basic_istream<_CharT, _Traits>& __is,
            basic_string<_CharT, _Traits, _Alloc>& __str)
-    { return getline(__is, __str, __is.widen('\n')); }
+    { return std::getline(__is, __str, __is.widen('\n')); }
+
+#if __cplusplus >= 201103L
+  /// Read a line from an rvalue stream into a string.
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    basic_istream<_CharT, _Traits>&
+    getline(basic_istream<_CharT, _Traits>&& __is,
+           basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
+    { return std::getline(__is, __str, __delim); }
+
+  /// Read a line from an rvalue stream into a string.
+  template<typename _CharT, typename _Traits, typename _Alloc>
+    inline basic_istream<_CharT, _Traits>&
+    getline(basic_istream<_CharT, _Traits>&& __is,
+           basic_string<_CharT, _Traits, _Alloc>& __str)
+    { return std::getline(__is, __str); }
+#endif
 
   template<>
     basic_istream<char>&
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc
new file mode 100644 (file)
index 0000000..a0dda5f
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2014 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/>.
+
+#include <string>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::string s;
+  getline(std::istringstream("First line\nSecond line\n"), s);
+  VERIFY( s == "First line" );
+  getline(std::istringstream("Third line\nFourth line\n"), s, 'r');
+  VERIFY( s == "Thi" );
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc
new file mode 100644 (file)
index 0000000..db20c02
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2014 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/>.
+
+#include <string>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  std::wstring s;
+  getline(std::wistringstream(L"First line\nSecond line\n"), s);
+  VERIFY( s == L"First line" );
+  getline(std::wistringstream(L"Third line\nFourth line\n"), s, L'r');
+  VERIFY( s == L"Thi" );
+}
+
+int
+main()
+{
+  test01();
+}