1111#include " pybind11_tests.h"
1212#include " constructor_stats.h"
1313
14+ namespace {
15+
1416// Many bases for testing that multiple inheritance from many classes (i.e. requiring extra
1517// space for holder constructed flags) works.
1618template <int N> struct BaseN {
@@ -43,7 +45,34 @@ int WithStatic2::static_value2 = 2;
4345int VanillaStaticMix1::static_value = 12 ;
4446int VanillaStaticMix2::static_value = 12 ;
4547
48+ // test_multiple_inheritance_virtbase
49+ struct Base1a {
50+ Base1a (int i) : i(i) { }
51+ int foo () { return i; }
52+ int i;
53+ };
54+ struct Base2a {
55+ Base2a (int i) : i(i) { }
56+ int bar () { return i; }
57+ int i;
58+ };
59+ struct Base12a : Base1a, Base2a {
60+ Base12a (int i, int j) : Base1a(i), Base2a(j) { }
61+ };
62+
63+ // test_mi_unaligned_base
64+ // test_mi_base_return
65+ struct I801B1 { int a = 1 ; I801B1() = default ; I801B1(const I801B1 &) = default ; virtual ~I801B1 () = default ; };
66+ struct I801B2 { int b = 2 ; I801B2() = default ; I801B2(const I801B2 &) = default ; virtual ~I801B2 () = default ; };
67+ struct I801C : I801B1, I801B2 {};
68+ struct I801D : I801C {}; // Indirect MI
69+
70+ } // namespace
71+
4672TEST_SUBMODULE (multiple_inheritance, m) {
73+ // Please do not interleave `struct` and `class` definitions with bindings code,
74+ // but implement `struct`s and `class`es in the anonymous namespace above.
75+ // This helps keeping the smart_holder branch in sync with master.
4776
4877 // test_multiple_inheritance_mix1
4978 // test_multiple_inheritance_mix2
@@ -99,27 +128,14 @@ TEST_SUBMODULE(multiple_inheritance, m) {
99128 // test_multiple_inheritance_virtbase
100129 // Test the case where not all base classes are specified, and where pybind11 requires the
101130 // py::multiple_inheritance flag to perform proper casting between types.
102- struct Base1a {
103- Base1a (int i) : i(i) { }
104- int foo () { return i; }
105- int i;
106- };
107131 py::class_<Base1a, std::shared_ptr<Base1a>>(m, " Base1a" )
108132 .def (py::init<int >())
109133 .def (" foo" , &Base1a::foo);
110134
111- struct Base2a {
112- Base2a (int i) : i(i) { }
113- int bar () { return i; }
114- int i;
115- };
116135 py::class_<Base2a, std::shared_ptr<Base2a>>(m, " Base2a" )
117136 .def (py::init<int >())
118137 .def (" bar" , &Base2a::bar);
119138
120- struct Base12a : Base1a, Base2a {
121- Base12a (int i, int j) : Base1a(i), Base2a(j) { }
122- };
123139 py::class_<Base12a, /* Base1 missing */ Base2a,
124140 std::shared_ptr<Base12a>>(m, " Base12a" , py::multiple_inheritance ())
125141 .def (py::init<int , int >());
@@ -130,10 +146,6 @@ TEST_SUBMODULE(multiple_inheritance, m) {
130146 // test_mi_unaligned_base
131147 // test_mi_base_return
132148 // Issue #801: invalid casting to derived type with MI bases
133- struct I801B1 { int a = 1 ; I801B1() = default ; I801B1(const I801B1 &) = default ; virtual ~I801B1 () = default ; };
134- struct I801B2 { int b = 2 ; I801B2() = default ; I801B2(const I801B2 &) = default ; virtual ~I801B2 () = default ; };
135- struct I801C : I801B1, I801B2 {};
136- struct I801D : I801C {}; // Indirect MI
137149 // Unregistered classes:
138150 struct I801B3 { int c = 3 ; virtual ~I801B3 () = default ; };
139151 struct I801E : I801B3, I801D {};
0 commit comments