File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -62,13 +62,23 @@ High-level aspects:
62
62
namespace pybindit {
63
63
namespace memory {
64
64
65
+ // Default fallback.
65
66
static constexpr bool type_has_shared_from_this (...) { return false ; }
66
67
68
+ // This overload (generated by ChatGPT) uses SFINAE to skip enable_shared_from_this checks when the
69
+ // base is inaccessible (e.g. private inheritance).
67
70
template <typename T>
68
- static constexpr bool type_has_shared_from_this (const std::enable_shared_from_this<T> *) {
71
+ static auto type_has_shared_from_this (const T *ptr)
72
+ -> decltype(static_cast <const std::enable_shared_from_this<T> *>(ptr), true) {
69
73
return true ;
70
74
}
71
75
76
+ // Inaccessible base → substitution failure → fallback overload selected
77
+ template <typename T>
78
+ static constexpr bool type_has_shared_from_this (const void *) {
79
+ return false ;
80
+ }
81
+
72
82
struct guarded_delete {
73
83
std::weak_ptr<void > released_ptr; // Trick to keep the smart_holder memory footprint small.
74
84
std::function<void (void *)> del_fun; // Rare case.
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ namespace pybindit {
10
10
namespace memory {
11
11
namespace smart_holder_poc { // Proof-of-Concept implementations.
12
12
13
+ struct PrivateESFT : private std ::enable_shared_from_this<PrivateESFT> {};
14
+ static_assert (!pybindit::memory::type_has_shared_from_this(static_cast <PrivateESFT *>(nullptr )),
15
+ " should detect inaccessible base" );
16
+
13
17
template <typename T>
14
18
T &as_lvalue_ref (const smart_holder &hld) {
15
19
static const char *context = " as_lvalue_ref" ;
You can’t perform that action at this time.
0 commit comments