http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57228
Bug ID: 57228 Summary: [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: f.heckenb...@fh-soft.de Created attachment 30076 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30076&action=edit Test case http://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr says: "When constructing a shared_ptr from a raw pointer to an object of a type derived from std::enable_shared_from_this, the constructors of shared_ptr detect other owners of the object through the weak reference stored in that base class. This allows ownership of the object to be shared with existing shared_ptrs. Otherwise, it is undefined behavior to construct a shared_ptr for an object that is already managed by another shared_ptr." Therefore, I gather the attached program should share ownership, but it doesn't: It says "gp2.use_count() = 1;" and aborts due to double deletion. Using shared_from_this() works, though, so it's probably not a serious problem.