On 29 October 2013 21:33, Jonathan Wakely wrote: > This change fixes the unique_ptr<void> testcase in the PR while > preserving the extension that we allow initializing a shared_ptr from > a unique_ptr that uses a custom pointer. > > I've added a test for that extension, and for assignment of > enable_shared_from this. > > 2013-10-29 Jonathan Wakely <jwakely....@gmail.com> > > PR libstdc++/58839 > * include/bits/shared_ptr_base.h > (__shared_ptr<T>::__shared_ptr(unique_ptr<U,D>&&)): Only use addressof > when unique_ptr<U,D>::pointer is not a built-in pointer type. > * testsuite/20_util/shared_ptr/cons/58839.cc: New. > * testsuite/20_util/enable_shared_from_this/members/assign.cc: New. > * testsuite/20_util/enable_shared_from_this/members/unique_ptr.cc: > New. > > Tested x86_64-linux, committed to trunk.
For the 4.8 branch I'm committing this simpler form, which just disables the extension: PR libstdc++/58839 * include/bits/shared_ptr_base.h (__shared_ptr<T>::__shared_ptr(unique_ptr<U,D>&&)): Do not dereference pointer. * testsuite/20_util/shared_ptr/cons/58839.cc: New.
commit 58c7f84d733fcaeb5280ba1766817fc70bfda15b Author: Jonathan Wakely <jwakely....@gmail.com> Date: Tue Oct 29 21:40:57 2013 +0000 PR libstdc++/58839 * include/bits/shared_ptr_base.h (__shared_ptr<T>::__shared_ptr(unique_ptr<U,D>&&)): Do not dereference pointer. * testsuite/20_util/shared_ptr/cons/58839.cc: New. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 5b0be41..c4845dd 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -819,7 +819,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_ptr(__r.get()), _M_refcount() { __glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>) - auto __tmp = std::__addressof(*__r.get()); + auto __tmp = __r.get(); _M_refcount = __shared_count<_Lp>(std::move(__r)); __enable_shared_from_this_helper(_M_refcount, __tmp, __tmp); } diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58839.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58839.cc new file mode 100644 index 0000000..6ad2564 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/58839.cc @@ -0,0 +1,29 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2013 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/>. + +#include <memory> + +// libstdc++/58839 + +void test01() +{ + std::unique_ptr<void> y; + std::shared_ptr<void> x = std::move(y); +}