commit 58c7f84d733fcaeb5280ba1766817fc70bfda15b Author: Jonathan Wakely Date: Tue Oct 29 21:40:57 2013 +0000 PR libstdc++/58839 * include/bits/shared_ptr_base.h (__shared_ptr::__shared_ptr(unique_ptr&&)): 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 +// . + +#include + +// libstdc++/58839 + +void test01() +{ + std::unique_ptr y; + std::shared_ptr x = std::move(y); +}