pybind11/tests
Jason Rhinelander 2097826346 Fix template trampoline overload lookup failure
Problem
=======

The template trampoline pattern documented in PR #322 has a problem with
virtual method overloads in intermediate classes in the inheritance
chain between the trampoline class and the base class.

For example, consider the following inheritance structure, where `B` is
the actual class, `PyB<B>` is the trampoline class, and `PyA<B>` is an
intermediate class adding A's methods into the trampoline:

    PyB<B> -> PyA<B> -> B -> A

Suppose PyA<B> has a method `some_method()` with a PYBIND11_OVERLOAD in
it to overload the virtual `A::some_method()`.  If a Python class `C` is
defined that inherits from the pybind11-registered `B` and tries to
provide an overriding `some_method()`, the PYBIND11_OVERLOADs declared
in PyA<B> fails to find this overloaded method, and thus never invoke it
(or, if pure virtual and not overridden in PyB<B>, raises an exception).

This happens because the base (internal) `PYBIND11_OVERLOAD_INT` macro
simply calls `get_overload(this, name)`; `get_overload()` then uses the
inferred type of `this` to do a type lookup in `registered_types_cpp`.
This is where it fails: `this` will be a `PyA<B> *`, but `PyA<B>` is
neither the base type (`B`) nor the trampoline type (`PyB<B>`).  As a
result, the overload fails and we get a failed overload lookup.

The fix
=======

The fix is relatively simple: we can cast `this` passed to
`get_overload()` to a `const B *`, which lets get_overload look up the
correct class.  Since trampoline classes should be derived from `B`
classes anyway, this cast should be perfectly safe.

This does require adding the class name as an argument to the
PYBIND11_OVERLOAD_INT macro, but leaves the public macro signatures
unchanged.
2016-08-29 19:41:44 -04:00
..
CMakeLists.txt Don't install pytest from cmake, just fail instead 2016-08-26 17:22:48 -04:00
conftest.py Fix test suite failure without numpy and improve module init diagnostics 2016-08-25 17:08:09 +02:00
constructor_stats.h Port tests to pytest 2016-08-19 13:19:38 +02:00
object.h Replace tabs with spaces (to pass style check) 2016-08-28 14:11:38 -04:00
pybind11_tests.cpp Get pybind11 test suite to compile on the Intel compiler (more or less..) 2016-08-25 01:43:35 +02:00
pybind11_tests.h Port tests to pytest 2016-08-19 13:19:38 +02:00
test_buffers.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_buffers.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_callbacks.cpp Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_callbacks.py Move inheritance tests into the proper file 2016-08-19 13:19:38 +02:00
test_constants_and_functions.cpp Move enum tests into a new file 2016-08-19 13:19:38 +02:00
test_constants_and_functions.py Move enum tests into a new file 2016-08-19 13:19:38 +02:00
test_eigen.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_eigen.py Fix test suite failure without numpy and improve module init diagnostics 2016-08-25 17:08:09 +02:00
test_enum.cpp Move enum tests into a new file 2016-08-19 13:19:38 +02:00
test_enum.py Move enum tests into a new file 2016-08-19 13:19:38 +02:00
test_eval_call.py Rewrite eval tests to allow for simple asserts 2016-08-19 16:31:48 +02:00
test_eval.cpp Rewrite eval tests to allow for simple asserts 2016-08-19 16:31:48 +02:00
test_eval.py Rewrite eval tests to allow for simple asserts 2016-08-19 16:31:48 +02:00
test_exceptions.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_exceptions.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_inheritance.cpp Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_inheritance.py Move inheritance tests into the proper file 2016-08-19 13:19:38 +02:00
test_issues.cpp Simplify more tests by replacing capture with assert 2016-08-19 16:31:48 +02:00
test_issues.py Simplify more tests by replacing capture with assert 2016-08-19 16:31:48 +02:00
test_keep_alive.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_keep_alive.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_kwargs_and_defaults.cpp Simplify more tests by replacing capture with assert 2016-08-19 16:31:48 +02:00
test_kwargs_and_defaults.py Simplify more tests by replacing capture with assert 2016-08-19 16:31:48 +02:00
test_methods_and_attributes.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_methods_and_attributes.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_modules.cpp Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_modules.py Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_numpy_dtypes.cpp Fix test suite failure without numpy and improve module init diagnostics 2016-08-25 17:08:09 +02:00
test_numpy_dtypes.py Fix test suite failure without numpy and improve module init diagnostics 2016-08-25 17:08:09 +02:00
test_numpy_vectorize.cpp Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_numpy_vectorize.py Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_opaque_types.cpp Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_opaque_types.py Simplify tests by replacing output capture with asserts where possible 2016-08-19 13:19:38 +02:00
test_operator_overloading.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_operator_overloading.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_pickling.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_pickling.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_python_types.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_python_types.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_sequences_and_iterators.cpp Add tests for generalized iterators 2016-08-24 23:30:00 +01:00
test_sequences_and_iterators.py Add tests for generalized iterators 2016-08-24 23:30:00 +01:00
test_smart_ptr.cpp Port tests to pytest 2016-08-19 13:19:38 +02:00
test_smart_ptr.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_stl_binders.cpp Replace tabs with spaces (to pass style check) 2016-08-28 14:11:38 -04:00
test_stl_binders.py Port tests to pytest 2016-08-19 13:19:38 +02:00
test_virtual_functions.cpp Fix template trampoline overload lookup failure 2016-08-29 19:41:44 -04:00
test_virtual_functions.py Fix template trampoline overload lookup failure 2016-08-29 19:41:44 -04:00