Commit d90d97ff by Jonathan Wakely Committed by Jonathan Wakely

re PR libstdc++/24803 ([c++0x] reference_wrapper and pointers to member functions)

2010-01-12  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/24803
	PR libstdc++/35569
	PR libstdc++/42593
	* include/std/functional (bind): Forward rvalues and detect correct
	result type of bound function object.
	* include/std/mutex (call_once): Specify bind result type.
	* testsuite/20_util/reference_wrapper/invoke.cc: Remove invalid tests.
	* testsuite/20_util/reference_wrapper/24803.cc: Remove invalid tests
	and enable FIXME tests.
	* testsuite/20_util/bind/35569.cc: New.
	* testsuite/20_util/bind/ref2.cc: New.
	* testsuite/20_util/bind/38889.cc: New.
	* testsuite/20_util/bind/ref_neg.cc: New.
	* testsuite/20_util/bind/42593.cc: New.

From-SVN: r155826
parent 31380bc4
2010-01-12 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/24803
PR libstdc++/35569
PR libstdc++/42593
* include/std/functional (bind): Forward rvalues and detect correct
result type of bound function object.
* include/std/mutex (call_once): Specify bind result type.
* testsuite/20_util/reference_wrapper/invoke.cc: Remove invalid tests.
* testsuite/20_util/reference_wrapper/24803.cc: Remove invalid tests
and enable FIXME tests.
* testsuite/20_util/bind/35569.cc: New.
* testsuite/20_util/bind/ref2.cc: New.
* testsuite/20_util/bind/38889.cc: New.
* testsuite/20_util/bind/ref_neg.cc: New.
* testsuite/20_util/bind/42593.cc: New.
2010-01-11 Paolo Carlini <paolo.carlini@oracle.com> 2010-01-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/parallel/base.h (decode2): Rename to __decode2. * include/parallel/base.h (decode2): Rename to __decode2.
......
// <mutex> -*- C++ -*- // <mutex> -*- C++ -*-
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -722,12 +722,12 @@ namespace std ...@@ -722,12 +722,12 @@ namespace std
call_once(once_flag& __once, _Callable __f, _Args&&... __args) call_once(once_flag& __once, _Callable __f, _Args&&... __args)
{ {
#ifdef _GLIBCXX_HAVE_TLS #ifdef _GLIBCXX_HAVE_TLS
auto __bound_functor = std::bind(__f, __args...); auto __bound_functor = std::bind<void>(__f, __args...);
__once_callable = &__bound_functor; __once_callable = &__bound_functor;
__once_call = &__once_call_impl<decltype(__bound_functor)>; __once_call = &__once_call_impl<decltype(__bound_functor)>;
#else #else
unique_lock<mutex> __functor_lock(__get_once_mutex()); unique_lock<mutex> __functor_lock(__get_once_mutex());
__once_functor = std::bind(__f, __args...); __once_functor = std::bind<void>(__f, __args...);
__set_once_functor_lock_ptr(&__functor_lock); __set_once_functor_lock_ptr(&__functor_lock);
#endif #endif
......
// 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.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
using namespace std;
using namespace std::placeholders;
void test01()
{
bind(multiplies<int>(),4,_1)(5);
}
// 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.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
void goo(int);
void foo() {
std::bind (goo,1)();
std::bind (goo,std::placeholders::_1)(1);
}
// { dg-do compile }
// { 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.7.11 Function template bind
#include <functional>
void f( int ) {}
void test01()
{
std::function< void( int ) > pf = std::bind( &f, std::placeholders::_1 );
pf(1);
}
// 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.7.11 Function template bind
// { dg-options "-std=gnu++0x" }
#include <functional>
#include <testsuite_hooks.h>
using namespace std::placeholders;
int inc(int& i) { return ++i; }
void test01()
{
int counter = 0;
std::bind(&inc, _1)(counter);
VERIFY(counter == 1 );
std::bind(&inc, std::ref(counter))();
VERIFY(counter == 2 );
}
struct Inc
{
int operator()(int& i) const { return ++i; }
void operator()(int&&) const { }
int f(int& i) const { return ++i; }
};
void test02()
{
int counter = 0;
std::bind(Inc(), _1)(counter);
VERIFY(counter == 1 );
std::bind(&Inc::f, Inc(), std::ref(counter))();
VERIFY(counter == 2 );
}
int main()
{
test01();
test02();
}
// 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.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
using namespace std::placeholders;
int inc(int& i) { return ++i; }
void test01()
{
const int dummy = 0;
std::bind(&inc, _1)(0); // { dg-error ""}
std::bind(&inc, std::ref(dummy))(); // { dg-error ""}
std::bind(&inc, dummy)(); // { dg-error ""}
std::bind(&inc, 0)(); // { dg-error ""}
}
struct Inc
{
int operator()(int& i) const { return ++i; }
void operator()(int&&) const { }
int f(int&& i) const { return ++i; }
};
void test02()
{
const int dummy = 0;
std::bind(Inc(), _1)(dummy); // { dg-error ""}
std::bind(&Inc::f, Inc(), std::ref(dummy))(); // { dg-error ""}
}
int main()
{
test01();
test02();
}
// { dg-excess-errors "" }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-do compile } // { dg-do compile }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc. // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -54,27 +54,19 @@ void test01() ...@@ -54,27 +54,19 @@ void test01()
verify_return_type((*pr1)(0), double()); verify_return_type((*pr1)(0), double());
std::reference_wrapper<double (*)(int)>* pr2(0); std::reference_wrapper<double (*)(int)>* pr2(0);
verify_return_type((*pr2)(0), double()); verify_return_type((*pr2)(0), double());
std::reference_wrapper<int (test_type::*)()>* pr3(0);
verify_return_type((*pr3)(null_tt), int());
std::reference_wrapper<int (test_type::*)()const>* pr4(0);
verify_return_type((*pr4)(null_ttc), int());
std::reference_wrapper<functor1>* pr5(0); std::reference_wrapper<functor1>* pr5(0);
// libstdc++/24803 // libstdc++/24803
// FIXME: verify_return_type((*pr5)(0), double()); verify_return_type((*pr5)(0), double());
verify_return_type((*pr5)(zero), double()); verify_return_type((*pr5)(zero), double());
std::reference_wrapper<double (int, char)>* pr1b(0); std::reference_wrapper<double (int, char)>* pr1b(0);
verify_return_type((*pr1b)(0,0), double()); verify_return_type((*pr1b)(0,0), double());
std::reference_wrapper<double (*)(int, char)>* pr2b(0); std::reference_wrapper<double (*)(int, char)>* pr2b(0);
verify_return_type((*pr2b)(0,0), double()); verify_return_type((*pr2b)(0,0), double());
std::reference_wrapper<int (test_type::*)(char)>* pr3b(0);
verify_return_type((*pr3b)(null_tt,zero), int());
std::reference_wrapper<int (test_type::*)()const>* pr4b(0);
verify_return_type((*pr4b)(null_ttc), int());
std::reference_wrapper<functor2>* pr5b(0); std::reference_wrapper<functor2>* pr5b(0);
// libstdc++/24803 // libstdc++/24803
// FIXME: verify_return_type((*pr5b)(0,0), double()); verify_return_type((*pr5b)(0,0), double());
verify_return_type((*pr5b)(zero,zero), double()); verify_return_type((*pr5b)(zero,zero), double());
} }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc. // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -70,11 +70,6 @@ void test01() ...@@ -70,11 +70,6 @@ void test01()
::get_seventeen get_sev; ::get_seventeen get_sev;
::X x; ::X x;
::X* xp = &x; ::X* xp = &x;
int (::X::* p_foo)(float) = &::X::foo;
int (::X::* p_foo_c)(float) const = &::X::foo_c;
int (::X::* p_foo_v)(float) volatile = &::X::foo_v;
int (::X::* p_foo_cv)(float) const volatile = &::X::foo_cv;
int ::X::* p_bar = &::X::bar;
const float pi = 3.14; const float pi = 3.14;
...@@ -86,20 +81,6 @@ void test01() ...@@ -86,20 +81,6 @@ void test01()
VERIFY(cref(&truncate_float)(pi) == 3); VERIFY(cref(&truncate_float)(pi) == 3);
VERIFY(cref(&seventeen)() == 17); VERIFY(cref(&seventeen)() == 17);
// Member function pointers
VERIFY(ref(p_foo)(x, pi) == 3);
VERIFY(ref(p_foo)(xp, pi) == 3);
VERIFY(ref(p_foo_c)(x, pi) == 3);
VERIFY(ref(p_foo_c)(xp, pi) == 3);
VERIFY(ref(p_foo_v)(x, pi) == 3);
VERIFY(ref(p_foo_v)(xp, pi) == 3);
VERIFY(ref(p_foo_cv)(x, pi) == 3);
VERIFY(ref(p_foo_cv)(xp, pi) == 3);
// Member data pointers
VERIFY(ref(p_bar)(x) == 17);
VERIFY(ref(p_bar)(xp) == 17);
// Function objects // Function objects
VERIFY(ref(get_sev)() == 17); VERIFY(ref(get_sev)() == 17);
VERIFY(cref(get_sev)() == 17); VERIFY(cref(get_sev)() == 17);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment