From: Jonathan Wakely Date: Fri, 20 Jan 2017 00:07:14 +0000 (+0000) Subject: PR79156 fix std::__enable_shared_from_this extension X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=115ac9ff61a51bca1ad98dff8192c23e685249ea;p=gcc.git 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 31640d955c2..45a2c67aa7c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2017-01-19 Jonathan Wakely + 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 96c0d6b6dcc..3b8a5c7fad4 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 + 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 00000000000..2471314d582 --- /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 +// . + +// { dg-do run { target c++11 } } + +#include +#include + +struct A : std::__enable_shared_from_this { }; + +void +test01() +{ + std::__shared_ptr sp(new A); + auto sp2 = sp->shared_from_this(); + VERIFY( (bool)sp2 ); + static_assert( std::is_same::value, "" ); +} + +int +main() +{ + test01(); +}