diff options
4 files changed, 102 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 65134498fe7..1e1e522665a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index cd6037677df..6a54d0c20a9 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -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 index 00000000000..a0dda5f6390 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/12.cc @@ -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 index 00000000000..db20c0293c5 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/wchar_t/12.cc @@ -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(); +} |