#1521: Piraha smart_ptr can't handle self assignment -----------------------+---------------------------------------------------- Reporter: eschnett | Owner: sbrandt Type: defect | Status: review Priority: major | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: -----------------------+---------------------------------------------------- Changes (by sbrandt):
* status: assigned => review
Comment:
The patch is simple, but actually getting a segfault to trigger was a bit harder than I expected. #include <iostream> #include "smart_ptr.hpp"
struct A { A() { std::cout << "Construct" << std::endl; } ~A() { std::cout << "Destruct" << std::endl; } // need virtual, otherwise no dereference occurs virtual void foo() { std::cout << "Foo" << std::endl; } };
int main() { cctki_piraha::smart_ptr<A> y(new A(),false); y = y; y->foo(); return 0; }