Skip to content

Commit

Permalink
Add operator= to shared_ptr for assignments to base classes (GH-4185)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuglede committed May 24, 2021
1 parent d53646f commit 0531b72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cython/Includes/libcpp/memory.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ cdef extern from "<memory>" namespace "std" nogil:
shared_ptr(shared_ptr[T]&, T*)
shared_ptr(unique_ptr[T]&)
#shared_ptr(weak_ptr[T]&) # Not Supported
shared_ptr[T]& operator=[Y](const shared_ptr[Y]& ptr)

# Modifiers
void reset()
Expand Down
9 changes: 9 additions & 0 deletions tests/run/cpp_smart_ptr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ cdef cppclass C(B):

cdef shared_ptr[A] holding_subclass = shared_ptr[A](new C())


def test_assignment_to_base_class():
"""
>>> test_assignment_to_base_class()
"""
cdef shared_ptr[C] derived = shared_ptr[C](new C())
cdef shared_ptr[A] base = derived


def test_dynamic_pointer_cast():
"""
>>> test_dynamic_pointer_cast()
Expand Down

0 comments on commit 0531b72

Please sign in to comment.