re PR libstdc++/43397 (std::function can't forward rvalue reference for pointer to member function)
2010-03-17 Jonathan Wakely <jwakely.gcc@gmail.com> PR libstdc++/43397 * include/std/functional (_Mem_fn): Use perfect forwarding. * testsuite/20_util/function/43397.cc: New. From-SVN: r157504
This commit is contained in:
parent
4b193f9456
commit
fbcedacca6
3 changed files with 116 additions and 20 deletions
|
@ -1,3 +1,9 @@
|
|||
2010-03-17 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
PR libstdc++/43397
|
||||
* include/std/functional (_Mem_fn): Use perfect forwarding.
|
||||
* testsuite/20_util/function/43397.cc: New.
|
||||
|
||||
2010-03-16 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
PR libstdc++/43394
|
||||
|
|
|
@ -500,12 +500,12 @@ namespace std
|
|||
_Res
|
||||
_M_call(_Tp& __object, const volatile _Class *,
|
||||
_ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
|
||||
{ return ((*__ptr).*__pmf)(__args...); }
|
||||
{ return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
public:
|
||||
typedef _Res result_type;
|
||||
|
@ -515,18 +515,21 @@ namespace std
|
|||
// Handle objects
|
||||
_Res
|
||||
operator()(_Class& __object, _ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle pointers
|
||||
_Res
|
||||
operator()(_Class* __object, _ArgTypes... __args) const
|
||||
{ return (__object->*__pmf)(__args...); }
|
||||
{ return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle smart pointers, references and pointers to derived
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
operator()(_Tp& __object, _ArgTypes... __args) const
|
||||
{ return _M_call(__object, &__object, __args...); }
|
||||
{
|
||||
return _M_call(__object, &__object,
|
||||
std::forward<_ArgTypes>(__args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
_Functor __pmf;
|
||||
|
@ -544,12 +547,12 @@ namespace std
|
|||
_Res
|
||||
_M_call(_Tp& __object, const volatile _Class *,
|
||||
_ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
|
||||
{ return ((*__ptr).*__pmf)(__args...); }
|
||||
{ return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
public:
|
||||
typedef _Res result_type;
|
||||
|
@ -559,17 +562,20 @@ namespace std
|
|||
// Handle objects
|
||||
_Res
|
||||
operator()(const _Class& __object, _ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle pointers
|
||||
_Res
|
||||
operator()(const _Class* __object, _ArgTypes... __args) const
|
||||
{ return (__object->*__pmf)(__args...); }
|
||||
{ return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle smart pointers, references and pointers to derived
|
||||
template<typename _Tp>
|
||||
_Res operator()(_Tp& __object, _ArgTypes... __args) const
|
||||
{ return _M_call(__object, &__object, __args...); }
|
||||
{
|
||||
return _M_call(__object, &__object,
|
||||
std::forward<_ArgTypes>(__args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
_Functor __pmf;
|
||||
|
@ -587,12 +593,12 @@ namespace std
|
|||
_Res
|
||||
_M_call(_Tp& __object, const volatile _Class *,
|
||||
_ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
|
||||
{ return ((*__ptr).*__pmf)(__args...); }
|
||||
{ return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
public:
|
||||
typedef _Res result_type;
|
||||
|
@ -602,18 +608,21 @@ namespace std
|
|||
// Handle objects
|
||||
_Res
|
||||
operator()(volatile _Class& __object, _ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle pointers
|
||||
_Res
|
||||
operator()(volatile _Class* __object, _ArgTypes... __args) const
|
||||
{ return (__object->*__pmf)(__args...); }
|
||||
{ return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle smart pointers, references and pointers to derived
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
operator()(_Tp& __object, _ArgTypes... __args) const
|
||||
{ return _M_call(__object, &__object, __args...); }
|
||||
{
|
||||
return _M_call(__object, &__object,
|
||||
std::forward<_ArgTypes>(__args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
_Functor __pmf;
|
||||
|
@ -631,12 +640,12 @@ namespace std
|
|||
_Res
|
||||
_M_call(_Tp& __object, const volatile _Class *,
|
||||
_ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
template<typename _Tp>
|
||||
_Res
|
||||
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
|
||||
{ return ((*__ptr).*__pmf)(__args...); }
|
||||
{ return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
public:
|
||||
typedef _Res result_type;
|
||||
|
@ -646,17 +655,20 @@ namespace std
|
|||
// Handle objects
|
||||
_Res
|
||||
operator()(const volatile _Class& __object, _ArgTypes... __args) const
|
||||
{ return (__object.*__pmf)(__args...); }
|
||||
{ return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle pointers
|
||||
_Res
|
||||
operator()(const volatile _Class* __object, _ArgTypes... __args) const
|
||||
{ return (__object->*__pmf)(__args...); }
|
||||
{ return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
|
||||
|
||||
// Handle smart pointers, references and pointers to derived
|
||||
template<typename _Tp>
|
||||
_Res operator()(_Tp& __object, _ArgTypes... __args) const
|
||||
{ return _M_call(__object, &__object, __args...); }
|
||||
{
|
||||
return _M_call(__object, &__object,
|
||||
std::forward<_ArgTypes>(__args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
_Functor __pmf;
|
||||
|
|
78
libstdc++-v3/testsuite/20_util/function/43397.cc
Normal file
78
libstdc++-v3/testsuite/20_util/function/43397.cc
Normal file
|
@ -0,0 +1,78 @@
|
|||
// { dg-options "-std=gnu++0x" }
|
||||
// Copyright (C) 2010 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/>.
|
||||
|
||||
// 20.8.15 polymorphic function object wrapper
|
||||
|
||||
#include <functional>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
struct Foo
|
||||
{
|
||||
Foo() { }
|
||||
short operator() ( int && ) { return 1; }
|
||||
short operator() ( int && ) const { return 2; }
|
||||
short operator() ( int && ) volatile { return 3; }
|
||||
short operator() ( int && ) const volatile { return 4; }
|
||||
short func( int && ) { return 5; }
|
||||
short func_c( int && ) const { return 6; }
|
||||
short func_v( int && ) volatile { return 7; }
|
||||
short func_cv( int && ) const volatile { return 8; }
|
||||
};
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
using std::function;
|
||||
using std::ref;
|
||||
|
||||
Foo foo;
|
||||
Foo const foo_c;
|
||||
Foo volatile foo_v;
|
||||
Foo const volatile foo_cv;
|
||||
|
||||
std::function< int ( int && ) > f1( ref(foo) );
|
||||
VERIFY( f1(0) == 1 );
|
||||
|
||||
std::function< int ( int && ) > f2( ref(foo_c) );
|
||||
VERIFY( f2(0) == 2 );
|
||||
|
||||
std::function< int ( int && ) > f3( ref(foo_v) );
|
||||
VERIFY( f3(0) == 3 );
|
||||
|
||||
std::function< int ( int && ) > f4( ref(foo_cv) );
|
||||
VERIFY( f4(0) == 4 );
|
||||
|
||||
std::function< int ( Foo &, int && ) > f5( &Foo::func ) ;
|
||||
VERIFY( f5(foo, 0) == 5 );
|
||||
|
||||
std::function< int ( Foo const &, int && ) > f6( &Foo::func_c ) ;
|
||||
VERIFY( f6(foo_c, 0) == 6 );
|
||||
|
||||
std::function< int ( Foo volatile &, int && ) > f7( &Foo::func_v ) ;
|
||||
VERIFY( f7(foo_v, 0) == 7 );
|
||||
|
||||
std::function< int ( Foo const volatile &, int && ) > f8( &Foo::func_cv ) ;
|
||||
VERIFY( f8(foo_cv, 0) == 8 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue