@@ -526,6 +526,8 @@ inline LoadType determine_load_type(handle src, const type_info* typeinfo,
526
526
// (This is essentially the same as case 2b, but because not using multiple inheritance
527
527
// is extremely common, we handle it specially to avoid the loop iterator and type
528
528
// pointer lookup overhead)
529
+ // TODO(eric.cousineau): This seems to also capture C++-registered classes as well, not just Python-derived
530
+ // classes.
529
531
if (bases.size () == 1 && (no_cpp_mi || bases.front ()->type == typeinfo->type )) {
530
532
return LoadType::DerivedCppSinglePySingle;
531
533
}
@@ -1552,11 +1554,17 @@ struct copyable_holder_caster : public type_caster_base<type> {
1552
1554
// Go ahead and release ownership to C++, if able.
1553
1555
auto * py_type = (PyTypeObject*)src.get_type ().ptr ();
1554
1556
lowest_type = detail::get_type_info (py_type);
1555
- if (lowest_type->release_info .can_derive_from_wrapper ) {
1556
- do_release_to_cpp = true ;
1557
- } else {
1558
- std::cerr << " WARNING! Python-derived C++ instance will soon lose Python portion. "
1559
- " Consider having your base class extend from pybind11::wrapper<>." << std::endl;
1557
+ // Double-check that we did not get along C++ inheritance.
1558
+ // TODO(eric.cousineau): Generalize this to unique_ptr<> case as well.
1559
+ const bool is_actually_pure_cpp = lowest_type->type == py_type;
1560
+ if (!is_actually_pure_cpp) {
1561
+ if (lowest_type->release_info .can_derive_from_wrapper ) {
1562
+ do_release_to_cpp = true ;
1563
+ } else {
1564
+ std::cerr << " WARNING! Casting to std::shared_ptr<> will cause Python subclass of pybind11 C++ instance to lose its Python portion. "
1565
+ " Make your base class extend from pybind11::wrapper<> to prevent aliasing."
1566
+ << std::endl;
1567
+ }
1560
1568
}
1561
1569
}
1562
1570
0 commit comments