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
This commit is contained in:
Jonathan Wakely 2016-07-20 19:21:53 +01:00 committed by Jonathan Wakely
parent 18407bfb2c
commit 07c772ed4e
4 changed files with 39 additions and 2 deletions

View file

@ -1,5 +1,10 @@
2016-07-20 Jonathan Wakely <jwakely@redhat.com>
* 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.

View file

@ -948,6 +948,12 @@ requirements of the license of GCC.
<listitem><para>Update definitions of the partial specializations for const and volatile types.
</para></listitem></varlistentry>
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2328">2328</link>:
<emphasis>Rvalue stream extraction should use perfect forwarding</emphasis>
</term>
<listitem><para>Use perfect forwarding for right operand.
</para></listitem></varlistentry>
<varlistentry><term><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="../ext/lwg-defects.html#2329">2329</link>:
<emphasis><code>regex_match()/regex_search()</code> with <code>match_results</code> should forbid temporary strings</emphasis>
</term>

View file

@ -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<typename _CharT, typename _Traits, typename _Tp>
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

View file

@ -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;
}