diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2017-01-20 00:07:14 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2017-01-20 00:07:14 +0000 |
commit | 115ac9ff61a51bca1ad98dff8192c23e685249ea (patch) | |
tree | db28cb937eb52ed6ae3d5ad02debde519bd856cf | |
parent | 27169e45d4c16032c2fdee7b89883a1ca62b2b93 (diff) | |
download | gcc-115ac9ff61a51bca1ad98dff8192c23e685249ea.zip gcc-115ac9ff61a51bca1ad98dff8192c23e685249ea.tar.gz gcc-115ac9ff61a51bca1ad98dff8192c23e685249ea.tar.bz2 |
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.
From-SVN: r244668
-rw-r--r-- | libstdc++-v3/ChangeLog | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr_base.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/shared_ptr/1.cc | 38 |
3 files changed, 48 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 31640d9..45a2c67 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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. 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(); +} |