re PR libstdc++/36949 ([C++0x] make_shared does not initialize enable_shared_from_thi...
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 28 Jul 2008 23:28:16 +0000 (23:28 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 28 Jul 2008 23:28:16 +0000 (23:28 +0000)
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.

From-SVN: r138219

libstdc++-v3/ChangeLog
libstdc++-v3/include/tr1_impl/boost_shared_ptr.h
libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc [new file with mode: 0644]

index ab9183c4115b078298ea41d0094a7d936fc101a7..25f0d56f8644819dc5c7a38c543a1d8be4350c85 100644 (file)
@@ -1,3 +1,11 @@
+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.
+
 2008-07-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR libstdc++/36924
index a3fd80e85512f5bacacc05b01bf9402fb05dd100..5da40516bd6d9282a354dfbe857b24924cfa456b 100644 (file)
@@ -1,6 +1,6 @@
 // <tr1_impl/boost_shared_ptr.h> -*- C++ -*-
 
-// Copyright (C) 2007 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -505,13 +505,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1
       // This constructor is non-standard, it is used by allocate_shared.
       template<typename _Alloc, typename... _Args>
         __shared_ptr(_Sp_make_shared_tag __tag, _Alloc __a, _Args&&... __args)
-        : _M_ptr()
-        , _M_refcount(__tag, (_Tp*)0, __a, std::forward<_Args>(__args)...)
+        : _M_ptr(), _M_refcount(__tag, (_Tp*)0, __a,
+                               std::forward<_Args>(__args)...)
         {
           // _M_ptr needs to point to the newly constructed object.
           // This relies on _Sp_counted_ptr_inplace::_M_get_deleter.
-          void * __p = _M_refcount._M_get_deleter(typeid(__tag));
+          void* __p = _M_refcount._M_get_deleter(typeid(__tag));
           _M_ptr = static_cast<_Tp*>(__p);
+         __enable_shared_from_this_helper(_M_refcount, _M_ptr, _M_ptr);
         }
 
       template<typename _Tp1, _Lock_policy _Lp1, typename _Alloc,
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/creation/36949.cc
new file mode 100644 (file)
index 0000000..4fc7db3
--- /dev/null
@@ -0,0 +1,35 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2008 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <memory>
+
+struct A : std::enable_shared_from_this<A> { };
+
+// libstdc++/36949
+void test01()
+{
+  std::make_shared<A>()->shared_from_this();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}