* include/std/functional (function::function): Move construct target.
(function::operator=): Use perfect forwarding for argument.
(function::operator()): Use new __throw_bad_function_call.
* include/bits/functexcept.h (__throw_bad_function_call): Declare.
* src/functexcept.cc (__throw_bad_function_call): Define.
* config/abi/pre/gnu.ver: Add new symbol.
* testsuite/20_util/function/cons/move_target.cc: New.
* testsuite/20_util/function/assign/move_target.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155261
138bc75d-0d04-0410-961f-
82ee72b054a4
+2009-12-15 Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ * include/std/functional (function::function): Move construct target.
+ (function::operator=): Use perfect forwarding for argument.
+ (function::operator()): Use new __throw_bad_function_call.
+ * include/bits/functexcept.h (__throw_bad_function_call): Declare.
+ * src/functexcept.cc (__throw_bad_function_call): Define.
+ * config/abi/pre/gnu.ver: Add new symbol.
+ * testsuite/20_util/function/cons/move_target.cc: New.
+ * testsuite/20_util/function/assign/move_target.cc: New.
+
2009-12-15 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42379
_ZNSs18_S_construct_aux_2*;
_ZNSbIwSt11char_traitsIwESaIwEE18_S_construct_aux_2*;
+ _ZSt25__throw_bad_function_callv;
+
} GLIBCXX_3.4.13;
# Symbols in the support library (libsupc++) have their own tag.
void
__throw_future_error(int) __attribute__((__noreturn__));
+ // Helpers for exception objects in <functional>
+ void
+ __throw_bad_function_call() __attribute__((__noreturn__));
+
_GLIBCXX_END_NAMESPACE
#endif
}
static void
- _M_init_functor(_Any_data& __functor, const _Functor& __f)
- { _M_init_functor(__functor, __f, _Local_storage()); }
+ _M_init_functor(_Any_data& __functor, _Functor&& __f)
+ { _M_init_functor(__functor, std::move(__f), _Local_storage()); }
template<typename _Signature>
static bool
{ return true; }
private:
- static void
- _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type)
- { new (__functor._M_access()) _Functor(__f); }
+ static void
+ _M_init_functor(_Any_data& __functor, _Functor&& __f, true_type)
+ { new (__functor._M_access()) _Functor(std::move(__f)); }
static void
- _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type)
- { __functor._M_access<_Functor*>() = new _Functor(__f); }
+ _M_init_functor(_Any_data& __functor, _Functor&& __f, false_type)
+ { __functor._M_access<_Functor*>() = new _Functor(std::move(__f)); }
};
template<typename _Functor>
template<typename _Functor>
typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value,
function&>::__type
- operator=(_Functor __f)
+ operator=(_Functor&& __f)
{
- function(__f).swap(*this);
+ function(std::forward<_Functor>(__f)).swap(*this);
return *this;
}
/*
template<typename _Functor, typename _Alloc>
void
- assign(_Functor __f, const _Alloc& __a)
+ assign(_Functor&& __f, const _Alloc& __a)
{
- function(__f, __a).swap(*this);
+ function(allocator_arg, __a,
+ std::forward<_Functor>(__f)).swap(*this);
}
*/
{
_M_invoker = &_My_handler::_M_invoke;
_M_manager = &_My_handler::_M_manager;
- _My_handler::_M_init_functor(_M_functor, __f);
+ _My_handler::_M_init_functor(_M_functor, std::move(__f));
}
}
operator()(_ArgTypes... __args) const
{
if (_M_empty())
- {
-#if __EXCEPTIONS
- throw bad_function_call();
-#else
- __builtin_abort();
-#endif
- }
+ __throw_bad_function_call();
return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
}
#include <ios>
#include <system_error>
#include <future>
+#include <functional>
#ifdef _GLIBCXX_USE_NLS
# include <libintl.h>
__throw_future_error(int __i)
{ throw future_error(future_errc(__i)); }
+ void
+ __throw_bad_function_call()
+ { throw bad_function_call(); }
#else
void
__throw_bad_exception(void)
__throw_future_error(int)
{ std::abort(); }
+ void
+ __throw_bad_function_call()
+ { std::abort(); }
+
#endif //__EXCEPTIONS
_GLIBCXX_END_NAMESPACE
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <functional>
+
+struct moveable
+{
+ moveable() = default;
+ ~moveable() = default;
+ // target object must be CopyConstructible,
+ // but should not be copied during this test
+ moveable(const moveable& c) { throw "copied"; }
+ moveable& operator=(const moveable&) = delete;
+ moveable(moveable&&) { }
+
+ void operator()() const { }
+};
+
+void test01()
+{
+ std::function<void ()> f;
+ f = moveable();
+ f();
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 <functional>
+
+struct moveable
+{
+ moveable() = default;
+ ~moveable() = default;
+ // target object must be CopyConstructible,
+ // but should not be copied during this test
+ moveable(const moveable& c) { throw "copied"; }
+ moveable& operator=(const moveable&) = delete;
+ moveable(moveable&&) { }
+
+ void operator()() const { }
+};
+
+void test01()
+{
+ std::function<void ()> f = moveable();
+ f();
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}