From: Jonathan Wakely Date: Wed, 20 Jul 2016 18:21:53 +0000 (+0100) Subject: LWG 2328 Rvalue stream extraction should use perfect forwarding X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=07c772ed4e2bfd648c705575b0ff7f0c06f44c0c;p=gcc.git LWG 2328 Rvalue stream extraction should use perfect forwarding * include/std/istream (operator>>(basic_istream&&, _Tp&)): Adjust to use perfect forwarding (LWG 2328). * testsuite/27_io/rvalue_streams.cc: Test perfect forwarding. * doc/xml/manual/intro.xml: Document DR 2328 status. From-SVN: r238533 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 40caba12448..ad31fe6fdee 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2016-07-20 Jonathan Wakely + * include/std/istream (operator>>(basic_istream&&, _Tp&)): Adjust + to use perfect forwarding (LWG 2328). + * testsuite/27_io/rvalue_streams.cc: Test perfect forwarding. + * doc/xml/manual/intro.xml: Document DR 2328 status. + * libsupc++/pbase_type_info.cc (__pbase_type_info::__do_catch): Use static objects for catching nullptr as pointer to member types. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 7b836cddfbf..6335614efdb 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -948,6 +948,12 @@ requirements of the license of GCC. Update definitions of the partial specializations for const and volatile types. + 2328: + Rvalue stream extraction should use perfect forwarding + + Use perfect forwarding for right operand. + + 2329: regex_match()/regex_search() with match_results should forbid temporary strings diff --git a/libstdc++-v3/include/std/istream b/libstdc++-v3/include/std/istream index d4cf7bcbfd5..c8a2e08e9f9 100644 --- a/libstdc++-v3/include/std/istream +++ b/libstdc++-v3/include/std/istream @@ -909,6 +909,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L // [27.7.1.6] Rvalue stream extraction + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2328. Rvalue stream extraction should use perfect forwarding /** * @brief Generic extractor for rvalue stream * @param __is An input stream. @@ -921,9 +923,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template inline basic_istream<_CharT, _Traits>& - operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x) + operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x) { - __is >> __x; + __is >> std::forward<_Tp>(__x); return __is; } #endif // C++11 diff --git a/libstdc++-v3/testsuite/27_io/rvalue_streams.cc b/libstdc++-v3/testsuite/27_io/rvalue_streams.cc index eba5bc35961..5918595acbc 100644 --- a/libstdc++-v3/testsuite/27_io/rvalue_streams.cc +++ b/libstdc++-v3/testsuite/27_io/rvalue_streams.cc @@ -34,9 +34,33 @@ test01() VERIFY (i == i2); } +struct X { bool as_rvalue; }; + +void operator>>(std::istream&, X& x) { x.as_rvalue = false; } +void operator>>(std::istream&, X&& x) { x.as_rvalue = true; } + +// LWG 2328 Rvalue stream extraction should use perfect forwarding +void +test02() +{ + X x; + std::istringstream is; + auto& ref1 = (std::move(is) >> x); + VERIFY( &ref1 == &is ); + VERIFY( x.as_rvalue == false ); + auto& ref2 = (std::move(is) >> std::move(x)); + VERIFY( &ref2 == &is ); + VERIFY( x.as_rvalue == true ); + + char arr[2]; + std::istringstream("x") >> &arr[0]; + std::istringstream("x") >> arr; +} + int main() { test01(); + test02(); return 0; }