Fixed compilation error when binding function accepting some forms of std::function (#689)

* Fixed compilation error when defining function accepting some forms of std::function.

The compilation error happens only when the functional.h header is
present, and the build is done in debug mode, with NDEBUG being
undefined.  In addition, the std::function must accept an abstract
base class by reference.

The compilation error occurred in cast.h, when trying to construct a
std::tuple<AbstractBase>, rather than a std::tuple<AbstractBase&>.
This was caused by functional.h using std::move rather than
std::forward, changing the signature of the function being used.

This commit contains the fix, along with a test that exhibits the
issue when compiled in debug mode without the fix applied.

* Moved new std::function tests into test_callbacks, added callback_with_movable test.
This commit is contained in:
Lunderberg
2017-02-22 14:00:59 -05:00
committed by Wenzel Jakob
parent c8e506961c
commit c7fcde7c76
3 changed files with 39 additions and 1 deletions

View File

@@ -96,3 +96,9 @@ def test_function_signatures(doc):
assert doc(test_callback3) == "test_callback3(arg0: Callable[[int], int]) -> str"
assert doc(test_callback4) == "test_callback4() -> Callable[[int], int]"
def test_movable_object():
from pybind11_tests import callback_with_movable
assert callback_with_movable(lambda _: None) is True