PR79156 fix std::__enable_shared_from_this extension
authorJonathan Wakely <jwakely@redhat.com>
Fri, 20 Jan 2017 00:07:14 +0000 (00:07 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 20 Jan 2017 00:07:14 +0000 (00:07 +0000)
PR libstdc++/79156
* include/bits/shared_ptr_base.h (__enable_shared_from_this_base):
Fix return type.
(__enable_shared_from_this): Declare __shared_ptr as a friend.
* testsuite/ext/shared_ptr/1.cc: New test.

From-SVN: r244668

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/testsuite/ext/shared_ptr/1.cc [new file with mode: 0644]

index 31640d955c2aef6c4bdac59ea95e5075278efd34..45a2c67aa7c4eda326bc57037f27734f809d5c0f 100644 (file)
@@ -1,5 +1,11 @@
 2017-01-19  Jonathan Wakely  <jwakely@redhat.com>
 
+       PR libstdc++/79156
+       * include/bits/shared_ptr_base.h (__enable_shared_from_this_base):
+       Fix return type.
+       (__enable_shared_from_this): Declare __shared_ptr as a friend.
+       * testsuite/ext/shared_ptr/1.cc: New test.
+
        PR libstdc++/64903
        * include/bits/stl_algo.h (is_partioned): Don't retest the partition
        point.
index 96c0d6b6dccd416eb532248f714f9fdaa90dc4b7..3b8a5c7fad4100bb2216b3f6ee00c6f6e79e86d9 100644 (file)
@@ -1817,11 +1817,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const noexcept
        { _M_weak_this._M_assign(__p, __n); }
 
-      friend void
+      friend const __enable_shared_from_this*
       __enable_shared_from_this_base(const __shared_count<_Lp>&,
                                     const __enable_shared_from_this* __p)
       { return __p; }
 
+      template<typename, _Lock_policy>
+       friend class __shared_ptr;
+
       mutable __weak_ptr<_Tp, _Lp>  _M_weak_this;
     };
 
diff --git a/libstdc++-v3/testsuite/ext/shared_ptr/1.cc b/libstdc++-v3/testsuite/ext/shared_ptr/1.cc
new file mode 100644 (file)
index 0000000..2471314
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct A : std::__enable_shared_from_this<A> { };
+
+void
+test01()
+{
+  std::__shared_ptr<A> sp(new A);
+  auto sp2 = sp->shared_from_this();
+  VERIFY( (bool)sp2 );
+  static_assert( std::is_same<decltype(sp), decltype(sp2)>::value, "" );
+}
+
+int
+main()
+{
+  test01();
+}