A couple of silly bugs in the non-standard __enable_shared_from_this
extension.
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.
Tested powerpc64le-linux, committed to trunk.
commit cbd8c405a54659a828467c3d9edefaba35d33a0d
Author: Jonathan Wakely <[email protected]>
Date: Thu Jan 19 23:40:17 2017 +0000
PR79156 fix std::__enable_shared_from_this extension
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.
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h
b/libstdc++-v3/include/bits/shared_ptr_base.h
index 96c0d6b..3b8a5c7 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -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
index 0000000..2471314
--- /dev/null
+++ b/libstdc++-v3/testsuite/ext/shared_ptr/1.cc
@@ -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();
+}