1
1
#define PYBIND11_DETAIL_TYPE_CASTER_ODR_GUARD_IMPL_THROW_DISABLED true
2
2
#include " pybind11_tests.h"
3
3
4
+ // For test of real-world issue.
5
+ #include " pybind11/stl_bind.h"
6
+
7
+ #include < vector>
8
+
4
9
namespace mrc_ns { // minimal real caster
5
10
6
11
struct type_mrc {
@@ -36,8 +41,14 @@ struct minimal_real_caster {
36
41
}
37
42
};
38
43
44
+ // Intentionally not called from Python: this test is to exercise the ODR guard,
45
+ // not stl.h or stl_bind.h.
46
+ inline void pass_vector_type_mrc (const std::vector<type_mrc> &) {}
47
+
39
48
} // namespace mrc_ns
40
49
50
+ PYBIND11_MAKE_OPAQUE (std::vector<mrc_ns::type_mrc>);
51
+
41
52
namespace pybind11 {
42
53
namespace detail {
43
54
template <>
@@ -48,4 +59,11 @@ struct type_caster<mrc_ns::type_mrc> : mrc_ns::minimal_real_caster {};
48
59
TEST_SUBMODULE (type_caster_odr_guard_2, m) {
49
60
m.def (" type_mrc_to_python" , []() { return mrc_ns::type_mrc (202 ); });
50
61
m.def (" type_mrc_from_python" , [](const mrc_ns::type_mrc &obj) { return obj.value + 200 ; });
62
+
63
+ // Uncomment and run test_type_caster_odr_guard_1.py to verify that the
64
+ // test_type_caster_odr_violation_detected_counter subtest fails
65
+ // (num_violations 2 instead of 1).
66
+ // Unlike the "controlled ODR violation" for the minimal_real_caster, this ODR violation is
67
+ // completely unsafe, therefore it cannot portably be exercised with predictable results.
68
+ // m.def("pass_vector_type_mrc", mrc_ns::pass_vector_type_mrc);
51
69
}
0 commit comments