Bug 36949 - [C++0x] make_shared does not initialize enable_shared_from_this' internal shared_count
Summary: [C++0x] make_shared does not initialize enable_shared_from_this' internal sha...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: 4.4.0
Assignee: Paolo Carlini
URL:
Keywords:
: 36950 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-27 15:47 UTC by Daniel Frey
Modified: 2008-07-28 23:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-07-28 23:09:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Frey 2008-07-27 15:47:24 UTC
Here's a minimalistic example:

#include <memory>

struct A : std::enable_shared_from_this< A > {};

int main()
{
  std::make_shared< A >()->shared_from_this();
}

It throws a bad_weak_ptr exception, which is AFAICT wrong.
Comment 1 Daniel Frey 2008-07-27 16:19:21 UTC
*** Bug 36950 has been marked as a duplicate of this bug. ***
Comment 2 Paolo Carlini 2008-07-27 17:32:56 UTC
Jonathan, can you have a look? If you can confirm the issue, is it just matter of adding a call to __enable_shared_from_this_helper(_M_refcount, _M_ptr, _M_ptr) to __shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...) ??

PS: I'm going to adjust some arguments around from _Alloc to const _Alloc&...
Comment 3 Jonathan Wakely 2008-07-28 20:27:41 UTC
(In reply to comment #2)
> Jonathan, can you have a look? If you can confirm the issue, is it just matter
> of adding a call to __enable_shared_from_this_helper(_M_refcount, _M_ptr,
> _M_ptr) to __shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...) ??

Yes, that's the right fix.  

> PS: I'm going to adjust some arguments around from _Alloc to const _Alloc&...

Cool.

Thanks for catching this, Daniel.
Comment 4 Paolo Carlini 2008-07-28 23:09:43 UTC
Thanks, fix forthcoming.
Comment 5 paolo@gcc.gnu.org 2008-07-28 23:29:00 UTC
Subject: Bug 36949

Author: paolo
Date: Mon Jul 28 23:28:16 2008
New Revision: 138219

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138219
Log:
2008-07-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/36949
	* include/tr1_impl/boost_shared_ptr.h
	(__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...): Call
	__enable_shared_from_this_helper.
	* testsuite/20_util/shared_ptr/creation/36949.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/tr1_impl/boost_shared_ptr.h

Comment 6 Paolo Carlini 2008-07-28 23:30:52 UTC
Fixed.