@@ -1491,6 +1491,27 @@ struct holder_helper {
1491
1491
static auto get (const T &p) -> decltype(p.get()) { return p.get (); }
1492
1492
};
1493
1493
1494
+ template <typename holder>
1495
+ void check_for_holder_mismatch_impl () {
1496
+ using iholder = intrinsic_t <holder>;
1497
+ using base_type = decltype (*holder_helper<iholder>::get (std::declval<iholder>()));
1498
+ auto &holder_typeinfo = typeid (iholder);
1499
+ auto ins = get_internals ().holders_seen .emplace (typeid (base_type), &holder_typeinfo);
1500
+
1501
+ auto debug = type_id<base_type>();
1502
+ if (!ins.second && !same_type (*ins.first ->second , holder_typeinfo)) {
1503
+ #ifdef NDEBUG
1504
+ pybind11_fail (" Mismatched holders detected (compile in debug mode for details)" );
1505
+ #else
1506
+ std::string seen_holder_name (ins.first ->second ->name ());
1507
+ detail::clean_type_id (seen_holder_name);
1508
+ pybind11_fail (" Mismatched holders detected: "
1509
+ " attempting to use holder type " + type_id<iholder>() + " , but " + type_id<base_type>() +
1510
+ " was already seen using holder type " + seen_holder_name);
1511
+ #endif
1512
+ }
1513
+ }
1514
+
1494
1515
// / Type caster for holder types like std::shared_ptr, etc.
1495
1516
template <typename type, typename holder_type>
1496
1517
struct copyable_holder_caster : public type_caster_base <type> {
@@ -1524,6 +1545,7 @@ struct copyable_holder_caster : public type_caster_base<type> {
1524
1545
void check_holder_compat () {
1525
1546
if (typeinfo->default_holder )
1526
1547
throw cast_error (" Unable to load a custom holder type from a default-holder instance" );
1548
+ check_for_holder_mismatch_impl<holder_type>();
1527
1549
}
1528
1550
1529
1551
bool load_value (value_and_holder &&v_h) {
@@ -1615,23 +1637,7 @@ template <typename holder>
1615
1637
void check_for_holder_mismatch (enable_if_t <!is_holder<holder>::value, int > = 0 ) {}
1616
1638
template <typename holder>
1617
1639
void check_for_holder_mismatch (enable_if_t <is_holder<holder>::value, int > = 0 ) {
1618
- using iholder = intrinsic_t <holder>;
1619
- using base_type = decltype (*holder_helper<iholder>::get (std::declval<iholder>()));
1620
- auto &holder_typeinfo = typeid (iholder);
1621
- auto ins = get_internals ().holders_seen .emplace (typeid (base_type), &holder_typeinfo);
1622
-
1623
- auto debug = type_id<base_type>();
1624
- if (!ins.second && !same_type (*ins.first ->second , holder_typeinfo)) {
1625
- #ifdef NDEBUG
1626
- pybind11_fail (" Mismatched holders detected (compile in debug mode for details)" );
1627
- #else
1628
- std::string seen_holder_name (ins.first ->second ->name ());
1629
- detail::clean_type_id (seen_holder_name);
1630
- pybind11_fail (" Mismatched holders detected: "
1631
- " attempting to use holder type " + type_id<iholder>() + " , but " + type_id<base_type>() +
1632
- " was already seen using holder type " + seen_holder_name);
1633
- #endif
1634
- }
1640
+ check_for_holder_mismatch_impl<holder>();
1635
1641
}
1636
1642
1637
1643
template <typename T> struct handle_type_name { static constexpr auto name = _<T>(); };
0 commit comments