11
11
#include " pybind11_tests.h"
12
12
#include " constructor_stats.h"
13
13
14
+ namespace {
15
+
14
16
// Many bases for testing that multiple inheritance from many classes (i.e. requiring extra
15
17
// space for holder constructed flags) works.
16
18
template <int N> struct BaseN {
@@ -43,7 +45,34 @@ int WithStatic2::static_value2 = 2;
43
45
int VanillaStaticMix1::static_value = 12 ;
44
46
int VanillaStaticMix2::static_value = 12 ;
45
47
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
+
46
72
TEST_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.
47
76
48
77
// test_multiple_inheritance_mix1
49
78
// test_multiple_inheritance_mix2
@@ -99,27 +128,14 @@ TEST_SUBMODULE(multiple_inheritance, m) {
99
128
// test_multiple_inheritance_virtbase
100
129
// Test the case where not all base classes are specified, and where pybind11 requires the
101
130
// 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
- };
107
131
py::class_<Base1a, std::shared_ptr<Base1a>>(m, " Base1a" )
108
132
.def (py::init<int >())
109
133
.def (" foo" , &Base1a::foo);
110
134
111
- struct Base2a {
112
- Base2a (int i) : i(i) { }
113
- int bar () { return i; }
114
- int i;
115
- };
116
135
py::class_<Base2a, std::shared_ptr<Base2a>>(m, " Base2a" )
117
136
.def (py::init<int >())
118
137
.def (" bar" , &Base2a::bar);
119
138
120
- struct Base12a : Base1a, Base2a {
121
- Base12a (int i, int j) : Base1a(i), Base2a(j) { }
122
- };
123
139
py::class_<Base12a, /* Base1 missing */ Base2a,
124
140
std::shared_ptr<Base12a>>(m, " Base12a" , py::multiple_inheritance ())
125
141
.def (py::init<int , int >());
@@ -130,10 +146,6 @@ TEST_SUBMODULE(multiple_inheritance, m) {
130
146
// test_mi_unaligned_base
131
147
// test_mi_base_return
132
148
// 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
137
149
// Unregistered classes:
138
150
struct I801B3 { int c = 3 ; virtual ~I801B3 () = default ; };
139
151
struct I801E : I801B3, I801D {};
0 commit comments