public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/57228] New: [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers
@ 2013-05-09 14:02 f.heckenbach@fh-soft.de
2013-05-09 14:11 ` [Bug libstdc++/57228] " redi at gcc dot gnu.org
2013-05-09 14:16 ` redi at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-05-09 14:02 UTC (permalink / raw)
To: gcc-bugs
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.heckenbach@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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/57228] [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers
2013-05-09 14:02 [Bug libstdc++/57228] New: [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers f.heckenbach@fh-soft.de
@ 2013-05-09 14:11 ` redi at gcc dot gnu.org
2013-05-09 14:16 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-09 14:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57228
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
cppreference is wrong.
This exact case has been discussed on the LWG reflector and everyone agreed
it's invalid. The shared_ptr(Y*) constructor use_count() == 1 as a
postcondition, which is not compatible with the claim that you can share
ownership with existing shared_ptr objects.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/57228] [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers
2013-05-09 14:02 [Bug libstdc++/57228] New: [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers f.heckenbach@fh-soft.de
2013-05-09 14:11 ` [Bug libstdc++/57228] " redi at gcc dot gnu.org
@ 2013-05-09 14:16 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2013-05-09 14:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57228
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is http://cplusplus.github.io/LWG/lwg-active.html#2179 but if the
behaviour changes I'll eat my hat.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-09 14:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-09 14:02 [Bug libstdc++/57228] New: [c++11] constructing shared_ptr to enable_shared_from_this-derived class from raw pointers f.heckenbach@fh-soft.de
2013-05-09 14:11 ` [Bug libstdc++/57228] " redi at gcc dot gnu.org
2013-05-09 14:16 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).