[libcxx] Fix PR 22468 - std::function<void()> does not accept non-void-returning functions
Summary:
The bug can be found here: http://llvm.org/bugs/show_bug.cgi?id=22468
`__invoke_void_return_wrapper` is needed to properly handle calling a function that returns a value but where the std::function return type is void. Without this '-Wsystem-headers' will cause `function::operator()(...)` to not compile.
Reviewers: eugenis, K-ballo, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D7444
llvm-svn: 228705
diff --git a/libcxx/include/__functional_base b/libcxx/include/__functional_base
index 6766793..e174e0c 100644
--- a/libcxx/include/__functional_base
+++ b/libcxx/include/__functional_base
@@ -419,6 +419,26 @@
typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
};
+template <class _Ret>
+struct __invoke_void_return_wrapper
+{
+ template <class ..._Args>
+ static _Ret __call(_Args&&... __args)
+ {
+ return __invoke(_VSTD::forward<_Args>(__args)...);
+ }
+};
+
+template <>
+struct __invoke_void_return_wrapper<void>
+{
+ template <class ..._Args>
+ static void __call(_Args&&... __args)
+ {
+ __invoke(_VSTD::forward<_Args>(__args)...);
+ }
+};
+
template <class _Tp>
class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
: public __weak_result_type<_Tp>