[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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@228705 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2015-02-10 16:48:45 +00:00
parent 31cb7fe75e
commit c3231d213a
8 changed files with 169 additions and 6 deletions

View File

@@ -81,4 +81,10 @@ int main()
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int (A::*)(int) const>() != 0);
}
{
std::function<void(int)> f(&g);
assert(f);
assert(f.target<int(*)(int)>() != 0);
f(1);
}
}

View File

@@ -88,4 +88,11 @@ int main()
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(f.target<int (A::*)(int) const>() != 0);
}
{
std::function<void(int)> f;
f = &g;
assert(f);
assert(f.target<int(*)(int)>() != 0);
f(1);
}
}

View File

@@ -89,4 +89,12 @@ int main()
fun(10);
}
#endif
{
std::function<void(int)> fun(std::allocator_arg,
test_allocator<int(*)(int)>(),
&g);
assert(fun);
assert(fun.target<int(*)(int)>() != 0);
fun(10);
}
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <functional>
// class function<R()>
// Test that we properly return both values and void for all non-variadic
// overloads of function::operator()(...)
#define _LIBCPP_HAS_NO_VARIADICS
#include <functional>
#include <cassert>
int foo0() { return 42; }
int foo1(int) { return 42; }
int foo2(int, int) { return 42; }
int foo3(int, int, int) { return 42; }
int main()
{
{
std::function<int()> f(&foo0);
assert(f() == 42);
}
{
std::function<int(int)> f(&foo1);
assert(f(1) == 42);
}
{
std::function<int(int, int)> f(&foo2);
assert(f(1, 1) == 42);
}
{
std::function<int(int, int, int)> f(&foo3);
assert(f(1, 1, 1) == 42);
}
{
std::function<void()> f(&foo0);
f();
}
{
std::function<void(int)> f(&foo1);
f(1);
}
{
std::function<void(int, int)> f(&foo2);
f(1, 1);
}
{
std::function<void(int, int, int)> f(&foo3);
f(1, 1, 1);
}
}