File tree Expand file tree Collapse file tree 3 files changed +64
-15
lines changed Expand file tree Collapse file tree 3 files changed +64
-15
lines changed Original file line number Diff line number Diff line change @@ -222,21 +222,21 @@ if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
222
222
endif ()
223
223
224
224
# Optional dependency for some tests (boost::variant is only supported with version >= 1.56)
225
- find_package (Boost 1.56 )
226
-
227
- if (Boost_FOUND )
228
- if (NOT TARGET Boost::headers )
229
- if (TARGET Boost::boost )
230
- # Classic FindBoost
231
- add_library (Boost::headers ALIAS Boost::boost )
232
- else ()
233
- # Very old FindBoost, or newer Boost than CMake in older CMakes
234
- add_library (Boost::headers IMPORTED INTERFACE )
235
- set_property (TARGET Boost::headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
236
- ${Boost_INCLUDE_DIRS} )
237
- endif ()
238
- endif ()
239
- endif ()
225
+ # find_package(Boost 1.56)
226
+
227
+ # if(Boost_FOUND)
228
+ # if(NOT TARGET Boost::headers)
229
+ # if(TARGET Boost::boost)
230
+ # # Classic FindBoost
231
+ # add_library(Boost::headers ALIAS Boost::boost)
232
+ # else()
233
+ # # Very old FindBoost, or newer Boost than CMake in older CMakes
234
+ # add_library(Boost::headers IMPORTED INTERFACE)
235
+ # set_property(TARGET Boost::headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
236
+ # ${Boost_INCLUDE_DIRS})
237
+ # endif()
238
+ # endif()
239
+ # endif()
240
240
241
241
# Compile with compiler warnings turned on
242
242
function (pybind11_enable_warnings target_name )
Original file line number Diff line number Diff line change @@ -466,6 +466,24 @@ TEST_SUBMODULE(class_, m) {
466
466
py::class_<OtherDuplicateNested>(gt, " OtherDuplicateNested" );
467
467
py::class_<OtherDuplicateNested>(gt, " YetAnotherDuplicateNested" );
468
468
});
469
+
470
+ // Test drake#11424.
471
+ class ExampleVirt2 {
472
+ public:
473
+ virtual ~ExampleVirt2 () {}
474
+ virtual std::string get_name () const { return " ExampleVirt2" ; }
475
+ };
476
+ class PyExampleVirt2 : public ExampleVirt2 {
477
+ public:
478
+ std::string get_name () const override {
479
+ PYBIND11_OVERLOAD (std::string, ExampleVirt2, get_name, );
480
+ }
481
+ };
482
+ py::class_<ExampleVirt2, PyExampleVirt2>(m, " ExampleVirt2" )
483
+ .def (py::init ())
484
+ .def (" get_name" , &ExampleVirt2::get_name);
485
+ m.def (" example_virt2_get_name" ,
486
+ [](const ExampleVirt2& obj) { return obj.get_name (); });
469
487
}
470
488
471
489
template <int N> class BreaksBase { public:
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
import pytest
3
+ import weakref
3
4
4
5
import env # noqa: F401
5
6
@@ -465,3 +466,33 @@ class ClassScope:
465
466
m .register_duplicate_nested_class_type (ClassScope )
466
467
expected = 'generic_type: type "YetAnotherDuplicateNested" is already registered!'
467
468
assert str (exc_info .value ) == expected
469
+
470
+
471
+ def test_drake_11424 ():
472
+ # Define a derived class which *does not* overload the method.
473
+ # WARNING: The reproduction of this failure may be platform-specific, and
474
+ # seems to depend on the order of definition and/or the name of the classes
475
+ # defined. For example, trying to place this and the C++ code in
476
+ # `test_virtual_functions` makes `assert id_1 == id_2` below fail.
477
+ class Child1 (m .ExampleVirt2 ): pass
478
+
479
+ id_1 = id (Child1 )
480
+ assert m .example_virt2_get_name (m .ExampleVirt2 ()) == "ExampleVirt2"
481
+ assert m .example_virt2_get_name (Child1 ()) == "ExampleVirt2"
482
+
483
+ # Now delete everything (and ensure it's deleted).
484
+ wref = weakref .ref (Child1 )
485
+ del Child1
486
+ pytest .gc_collect ()
487
+ assert wref () == None
488
+
489
+ # Define a derived class which *does* define an overload.
490
+ class Child2 (m .ExampleVirt2 ):
491
+ def get_name (self ): return "Child2"
492
+
493
+ id_2 = id (Child2 )
494
+ assert id_1 == id_2 # This happens in CPython; not sure about PyPy.
495
+ assert m .example_virt2_get_name (m .ExampleVirt2 ()) == "ExampleVirt2"
496
+ # THIS WILL FAIL: This is using the cached `ExampleVirt2.get_name`, rather
497
+ # than re-inspect the Python dictionary.
498
+ assert m .example_virt2_get_name (Child2 ()) == "Child2"
You can’t perform that action at this time.
0 commit comments