From b1bd91584338e543ae7f6e7be707e6a2333f0c6d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 28 Mar 2017 08:35:04 +0100 Subject: [PATCH] PR libstdc++/80229 restore support for shared_ptr PR libstdc++/80229 * include/bits/shared_ptr_base.h (__shared_ptr::_M_enable_shared_from_this_with): Change parameters to non-const and then use remove_cv to get unqualified type. * testsuite/20_util/enable_shared_from_this/members/const.cc: Don't cast away constness on object created const. * testsuite/20_util/shared_ptr/cons/80229.cc: New test. From-SVN: r246520 --- libstdc++-v3/ChangeLog | 10 +++++++ libstdc++-v3/include/bits/shared_ptr_base.h | 14 +++++----- .../enable_shared_from_this/members/const.cc | 4 +-- .../20_util/shared_ptr/cons/80229.cc | 26 +++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d04a1f56fac..4a7869a1f6f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2017-03-28 Jonathan Wakely + + PR libstdc++/80229 + * include/bits/shared_ptr_base.h + (__shared_ptr::_M_enable_shared_from_this_with): Change parameters to + non-const and then use remove_cv to get unqualified type. + * testsuite/20_util/enable_shared_from_this/members/const.cc: Don't + cast away constness on object created const. + * testsuite/20_util/shared_ptr/cons/80229.cc: New test. + 2017-03-26 Markus Trippelsdorf PR libstdc++/80183 diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index a203f42c515..c8d7f20d5d7 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1363,17 +1363,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __has_esft_base<_Yp, __void_t<__esft_base_t<_Yp>>> : __not_> { }; // No enable shared_from_this for arrays - template - typename enable_if<__has_esft_base<_Yp>::value>::type - _M_enable_shared_from_this_with(const _Yp* __p) noexcept + template::type> + typename enable_if<__has_esft_base<_Yp2>::value>::type + _M_enable_shared_from_this_with(_Yp* __p) noexcept { if (auto __base = __enable_shared_from_this_base(_M_refcount, __p)) - __base->_M_weak_assign(const_cast<_Yp*>(__p), _M_refcount); + __base->_M_weak_assign(const_cast<_Yp2*>(__p), _M_refcount); } - template - typename enable_if::value>::type - _M_enable_shared_from_this_with(const _Yp*) noexcept + template::type> + typename enable_if::value>::type + _M_enable_shared_from_this_with(_Yp*) noexcept { } void* diff --git a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc index 0f7772661c1..3f8a6a536e6 100644 --- a/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc +++ b/libstdc++-v3/testsuite/20_util/enable_shared_from_this/members/const.cc @@ -32,9 +32,9 @@ test01() { struct X : public std::enable_shared_from_this { }; using CX = const X; - std::shared_ptr p(new X); + std::shared_ptr p(new CX); VERIFY( share_ownership(p->shared_from_this(), p) ); - p.reset(new CX); + p.reset(new X); VERIFY( share_ownership(p->shared_from_this(), p) ); auto p2 = std::const_pointer_cast(p)->shared_from_this(); VERIFY( share_ownership(p2, p) ); diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc new file mode 100644 index 00000000000..7b89066619d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/80229.cc @@ -0,0 +1,26 @@ +// 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 compile { target c++11 } } + +#include + +// PR libstdc++/80229 + +void del(void(*)()); +void the_func(); +std::shared_ptr ee(&the_func, &del); -- 2.30.2