File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -323,7 +323,7 @@ TEST_SUBMODULE(smart_ptr, m) {
323
323
: value_(value) {
324
324
print_created (this , value);
325
325
}
326
- ~UniquePtrHeld () {
326
+ virtual ~UniquePtrHeld () {
327
327
print_destroyed (this );
328
328
}
329
329
int value () const { return value_; }
@@ -382,4 +382,22 @@ TEST_SUBMODULE(smart_ptr, m) {
382
382
m, " ContainerPlain" );
383
383
Container<UniquePtrHeld, KeepAliveType::KeepAlive>::def (
384
384
m, " ContainerKeepAlive" );
385
+
386
+ class UniquePtrDerived : public UniquePtrHeld {
387
+ public:
388
+ UniquePtrDerived (int value, std::string name)
389
+ : UniquePtrHeld(value), name_(name) {
390
+ print_created (this , name);
391
+ }
392
+ ~UniquePtrDerived () {
393
+ print_destroyed (this );
394
+ }
395
+ std::string name () const { return name_; }
396
+ private:
397
+ std::string name_{};
398
+ };
399
+
400
+ py::class_<UniquePtrDerived, UniquePtrHeld>(m, " UniquePtrDerived" )
401
+ .def (py::init<int , std::string>())
402
+ .def (" name" , &UniquePtrDerived::name);
385
403
}
Original file line number Diff line number Diff line change @@ -314,3 +314,14 @@ def test_unique_ptr_keep_alive():
314
314
del c_keep
315
315
pytest .gc_collect ()
316
316
assert c_keep_stats .alive () == 0
317
+
318
+
319
+ def test_unique_ptr_derived ():
320
+ obj = m .UniquePtrDerived (1 , "a" )
321
+ c_plain = m .ContainerPlain (obj )
322
+ del obj
323
+ pytest .gc_collect ()
324
+ obj = c_plain .release ()
325
+ assert obj .value () == 1
326
+ assert obj .name () == "a"
327
+ del obj
You can’t perform that action at this time.
0 commit comments