[BUG]: Custom SharedPtr<T> usually should not be required to have a copy constructible T. #5417
Open
3 tasks done
Labels
triage
New bug, unverified
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
https://github.com/pybind/pybind11/archive/refs/tags/v2.13.5.tar.gz
Problem description
I have a custom
SharedPtr
that is basically anstd::shared_ptr
with some extra functionalities. It actually derives privately fromstd::shared_ptr
.My custom
SharedPtr<T>
is declared as a holder type.However, when
T
is not copy-constructible, I get compilation errors when using it: (error happens in "populate" binding)This happens because since
SceneRoot
is not copy-constructible (we do not want to inadvertently copy this huge structure!),type_caster<SharedPtr<T>>
inherits frommove_only_holder_caster
. Seepybind11/include/pybind11/cast.h
Lines 862 to 864 in f7e14e9
I do not really know much about use cases, but I do believe this is not correct. In pybind11 we have a custom
is_copy_constructible<>
trait because pre C++17 stl libraries sometimes report non-copy constructible as copy constructible but later give a compilation error. See commit 7937260. But in case of custom holders, using pybind's ownis_copy_constructible
is not correct IMO. I have discussed this (#5142) with myself and we both have agreed. :-)I have worked around the issue with this:
Notice that I also had to declare
is_holder_type<T, SharedPtr<T>>
.If I am not missing anything,
type_caster_holder
should usestd::is_copy_constructible
instead of the recursive pybind11 version.This would enable
std::shared_ptr
to not be treated as a special case herepybind11/include/pybind11/cast.h
Line 879 in f7e14e9
and here
pybind11/include/pybind11/cast.h
Line 840 in f7e14e9
Side Note
I do not understand how
std::shared_ptr
deals with the fact thatis_holder_type<>
is IMO supposed to fail (but of course it doesn't!) whenT
is not copy-constructible:pybind11/include/pybind11/cast.h
Lines 886 to 887 in f7e14e9
Reproducible example code
No response
Is this a regression? Put the last known working version here if it is.
Not a regression
The text was updated successfully, but these errors were encountered: