2009-11-06 23:15:17 +01:00
|
|
|
// shared_ptr and weak_ptr implementation details -*- C++ -*-
|
|
|
|
|
2019-01-01 13:31:55 +01:00
|
|
|
// Copyright (C) 2007-2019 Free Software Foundation, Inc.
|
2009-11-06 23:15:17 +01:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// GCC Note: Based on files from version 1.32.0 of the Boost library.
|
|
|
|
|
|
|
|
// shared_count.hpp
|
|
|
|
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
|
|
|
|
|
|
|
|
// shared_ptr.hpp
|
|
|
|
// Copyright (C) 1998, 1999 Greg Colvin and Beman Dawes.
|
|
|
|
// Copyright (C) 2001, 2002, 2003 Peter Dimov
|
|
|
|
|
|
|
|
// weak_ptr.hpp
|
|
|
|
// Copyright (C) 2001, 2002, 2003 Peter Dimov
|
|
|
|
|
|
|
|
// enable_shared_from_this.hpp
|
|
|
|
// Copyright (C) 2002 Peter Dimov
|
|
|
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See
|
|
|
|
// accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
/** @file bits/shared_ptr_base.h
|
|
|
|
* This is an internal header file, included by other library headers.
|
2010-12-19 10:21:16 +01:00
|
|
|
* Do not attempt to use it directly. @headername{memory}
|
2009-11-06 23:15:17 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SHARED_PTR_BASE_H
|
|
|
|
#define _SHARED_PTR_BASE_H 1
|
|
|
|
|
2018-06-04 23:38:42 +02:00
|
|
|
#include <typeinfo>
|
2014-06-25 22:54:46 +02:00
|
|
|
#include <bits/allocated_ptr.h>
|
Split <functional> into smaller pieces
* include/Makefile.am: Add <bits/refwrap.h> and <bits/std_function.h>.
Order alphabetically.
* include/Makefile.in: Regenerate.
* include/bits/refwrap.h: New header.
(_Maybe_get_result_type,_Weak_result_type_impl, _Weak_result_type)
(_Reference_wrapper_base_impl, _Reference_wrapper_base)
(reference_wrapper, ref, cref): Move here from <functional>.
* include/bits/shared_ptr_base.h: Include <bits/refwrap.h> and
<bits/stl_function.h> instead of <functional>.
* include/bits/std_function.h: New header.
(_Maybe_unary_or_binary_function, bad_function_call)
(__is_location_invariant, _Nocopy_types, _Any_data)
(_Simple_type_wrapper, _Function_base, _Function_handler, function):
Move here from <functional>.
* include/bits/unique_ptr.h: Include <bits/stl_function.h>.
* include/std/functional: Include new headers and move components to
them.
* include/std/future: Include <bits/std_function.h> instead of
<functional>.
* include/std/mutex: Likewise.
* include/std/regex: Likewise.
* src/c++11/compatibility-thread-c++0x.cc: Include <functional>.
* testsuite/20_util/default_delete/48631_neg.cc: Adjust dg-error line.
* testsuite/20_util/default_delete/void_neg.cc: Likewise.
* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error
lines.
* testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Likewise.
* testsuite/30_threads/packaged_task/49668.cc: Include <functional>.
From-SVN: r241410
2016-10-21 17:32:25 +02:00
|
|
|
#include <bits/refwrap.h>
|
|
|
|
#include <bits/stl_function.h>
|
2013-04-07 18:44:40 +02:00
|
|
|
#include <ext/aligned_buffer.h>
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
|
|
{
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2012-08-03 02:27:48 +02:00
|
|
|
#if _GLIBCXX_USE_DEPRECATED
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2012-08-03 02:27:48 +02:00
|
|
|
template<typename> class auto_ptr;
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2012-08-03 02:27:48 +02:00
|
|
|
#endif
|
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
/**
|
|
|
|
* @brief Exception possibly thrown by @c shared_ptr.
|
|
|
|
* @ingroup exceptions
|
|
|
|
*/
|
|
|
|
class bad_weak_ptr : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2015-09-03 22:40:03 +02:00
|
|
|
virtual char const* what() const noexcept;
|
2011-03-15 01:24:08 +01:00
|
|
|
|
2016-08-24 10:03:01 +02:00
|
|
|
virtual ~bad_weak_ptr() noexcept;
|
2010-11-02 19:51:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Substitute for bad_weak_ptr object in the case of -fno-exceptions.
|
|
|
|
inline void
|
|
|
|
__throw_bad_weak_ptr()
|
2012-11-07 14:20:33 +01:00
|
|
|
{ _GLIBCXX_THROW_OR_ABORT(bad_weak_ptr()); }
|
2010-11-02 19:51:23 +01:00
|
|
|
|
|
|
|
using __gnu_cxx::_Lock_policy;
|
|
|
|
using __gnu_cxx::__default_lock_policy;
|
|
|
|
using __gnu_cxx::_S_single;
|
|
|
|
using __gnu_cxx::_S_mutex;
|
|
|
|
using __gnu_cxx::_S_atomic;
|
|
|
|
|
|
|
|
// Empty helper class except when the template argument is _S_mutex.
|
|
|
|
template<_Lock_policy _Lp>
|
|
|
|
class _Mutex_base
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// The atomic policy uses fully-fenced builtins, single doesn't care.
|
|
|
|
enum { _S_need_barriers = 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class _Mutex_base<_S_mutex>
|
|
|
|
: public __gnu_cxx::__mutex
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
// This policy is used when atomic builtins are not available.
|
|
|
|
// The replacement atomic operations might not have the necessary
|
|
|
|
// memory barriers.
|
|
|
|
enum { _S_need_barriers = 1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<_Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class _Sp_counted_base
|
|
|
|
: public _Mutex_base<_Lp>
|
|
|
|
{
|
2016-08-24 10:03:01 +02:00
|
|
|
public:
|
2011-05-19 00:59:17 +02:00
|
|
|
_Sp_counted_base() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
: _M_use_count(1), _M_weak_count(1) { }
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
virtual
|
2011-05-19 00:59:17 +02:00
|
|
|
~_Sp_counted_base() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{ }
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
// Called when _M_use_count drops to zero, to release the resources
|
|
|
|
// managed by *this.
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_dispose() noexcept = 0;
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
// Called when _M_weak_count drops to zero.
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_destroy() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{ delete this; }
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
virtual void*
|
2013-04-28 13:38:21 +02:00
|
|
|
_M_get_deleter(const std::type_info&) noexcept = 0;
|
2010-11-02 19:51:23 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
_M_add_ref_copy()
|
|
|
|
{ __gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1); }
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
void
|
|
|
|
_M_add_ref_lock();
|
2014-01-28 11:23:27 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
_M_add_ref_lock_nothrow();
|
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_release() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{
|
|
|
|
// Be race-detector-friendly. For more info see bits/c++config.
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count);
|
|
|
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
|
|
|
|
{
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count);
|
|
|
|
_M_dispose();
|
|
|
|
// There must be a memory barrier between dispose() and destroy()
|
|
|
|
// to ensure that the effects of dispose() are observed in the
|
|
|
|
// thread that runs destroy().
|
|
|
|
// See http://gcc.gnu.org/ml/libstdc++/2005-11/msg00136.html
|
|
|
|
if (_Mutex_base<_Lp>::_S_need_barriers)
|
|
|
|
{
|
2015-06-12 11:49:41 +02:00
|
|
|
__atomic_thread_fence (__ATOMIC_ACQ_REL);
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Be race-detector-friendly. For more info see bits/c++config.
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
|
|
|
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count,
|
|
|
|
-1) == 1)
|
|
|
|
{
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count);
|
|
|
|
_M_destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_weak_add_ref() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{ __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); }
|
|
|
|
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_weak_release() noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{
|
|
|
|
// Be race-detector-friendly. For more info see bits/c++config.
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
|
|
|
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
|
|
|
|
{
|
|
|
|
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count);
|
|
|
|
if (_Mutex_base<_Lp>::_S_need_barriers)
|
|
|
|
{
|
|
|
|
// See _M_release(),
|
|
|
|
// destroy() must observe results of dispose()
|
2015-06-12 11:49:41 +02:00
|
|
|
__atomic_thread_fence (__ATOMIC_ACQ_REL);
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
|
|
|
_M_destroy();
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 10:03:01 +02:00
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
long
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_get_use_count() const noexcept
|
2010-11-02 19:51:23 +01:00
|
|
|
{
|
|
|
|
// No memory barrier is used here so there is no synchronization
|
|
|
|
// with other threads.
|
2012-02-10 19:20:43 +01:00
|
|
|
return __atomic_load_n(&_M_use_count, __ATOMIC_RELAXED);
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
|
|
|
|
2016-08-24 10:03:01 +02:00
|
|
|
private:
|
2011-05-19 00:59:17 +02:00
|
|
|
_Sp_counted_base(_Sp_counted_base const&) = delete;
|
|
|
|
_Sp_counted_base& operator=(_Sp_counted_base const&) = delete;
|
2010-11-02 19:51:23 +01:00
|
|
|
|
|
|
|
_Atomic_word _M_use_count; // #shared
|
|
|
|
_Atomic_word _M_weak_count; // #weak + (#shared != 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_single>::
|
|
|
|
_M_add_ref_lock()
|
|
|
|
{
|
2013-11-18 14:52:39 +01:00
|
|
|
if (_M_use_count == 0)
|
|
|
|
__throw_bad_weak_ptr();
|
|
|
|
++_M_use_count;
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_mutex>::
|
|
|
|
_M_add_ref_lock()
|
|
|
|
{
|
|
|
|
__gnu_cxx::__scoped_lock sentry(*this);
|
|
|
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
|
|
|
|
{
|
|
|
|
_M_use_count = 0;
|
|
|
|
__throw_bad_weak_ptr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 10:03:01 +02:00
|
|
|
template<>
|
2010-11-02 19:51:23 +01:00
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_atomic>::
|
|
|
|
_M_add_ref_lock()
|
|
|
|
{
|
|
|
|
// Perform lock-free add-if-not-zero operation.
|
2014-01-27 18:56:40 +01:00
|
|
|
_Atomic_word __count = _M_get_use_count();
|
2010-11-02 19:51:23 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (__count == 0)
|
|
|
|
__throw_bad_weak_ptr();
|
|
|
|
// Replace the current counter value with the old value + 1, as
|
2016-08-24 10:03:01 +02:00
|
|
|
// long as it's not changed meanwhile.
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
2012-02-10 19:20:43 +01:00
|
|
|
while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
|
2016-08-24 10:03:01 +02:00
|
|
|
true, __ATOMIC_ACQ_REL,
|
2012-02-10 19:20:43 +01:00
|
|
|
__ATOMIC_RELAXED));
|
2010-11-02 19:51:23 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 11:23:27 +01:00
|
|
|
template<>
|
|
|
|
inline bool
|
|
|
|
_Sp_counted_base<_S_single>::
|
|
|
|
_M_add_ref_lock_nothrow()
|
|
|
|
{
|
|
|
|
if (_M_use_count == 0)
|
|
|
|
return false;
|
|
|
|
++_M_use_count;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool
|
|
|
|
_Sp_counted_base<_S_mutex>::
|
|
|
|
_M_add_ref_lock_nothrow()
|
|
|
|
{
|
|
|
|
__gnu_cxx::__scoped_lock sentry(*this);
|
|
|
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
|
|
|
|
{
|
|
|
|
_M_use_count = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline bool
|
|
|
|
_Sp_counted_base<_S_atomic>::
|
|
|
|
_M_add_ref_lock_nothrow()
|
|
|
|
{
|
|
|
|
// Perform lock-free add-if-not-zero operation.
|
|
|
|
_Atomic_word __count = _M_get_use_count();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (__count == 0)
|
|
|
|
return false;
|
|
|
|
// Replace the current counter value with the old value + 1, as
|
|
|
|
// long as it's not changed meanwhile.
|
|
|
|
}
|
|
|
|
while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
|
|
|
|
true, __ATOMIC_ACQ_REL,
|
|
|
|
__ATOMIC_RELAXED));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-18 14:52:39 +01:00
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_single>::_M_add_ref_copy()
|
|
|
|
{ ++_M_use_count; }
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_single>::_M_release() noexcept
|
|
|
|
{
|
|
|
|
if (--_M_use_count == 0)
|
|
|
|
{
|
|
|
|
_M_dispose();
|
|
|
|
if (--_M_weak_count == 0)
|
|
|
|
_M_destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_single>::_M_weak_add_ref() noexcept
|
|
|
|
{ ++_M_weak_count; }
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline void
|
|
|
|
_Sp_counted_base<_S_single>::_M_weak_release() noexcept
|
|
|
|
{
|
|
|
|
if (--_M_weak_count == 0)
|
|
|
|
_M_destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
inline long
|
|
|
|
_Sp_counted_base<_S_single>::_M_get_use_count() const noexcept
|
|
|
|
{ return _M_use_count; }
|
|
|
|
|
2010-11-02 19:51:23 +01:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
// Forward declarations.
|
|
|
|
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class __shared_ptr;
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class __weak_ptr;
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class __enable_shared_from_this;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
class shared_ptr;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
class weak_ptr;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
struct owner_less;
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
class enable_shared_from_this;
|
|
|
|
|
|
|
|
template<_Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class __weak_count;
|
|
|
|
|
|
|
|
template<_Lock_policy _Lp = __default_lock_policy>
|
|
|
|
class __shared_count;
|
|
|
|
|
|
|
|
|
|
|
|
// Counted ptr with no deleter or allocator support
|
|
|
|
template<typename _Ptr, _Lock_policy _Lp>
|
2011-11-08 17:45:54 +01:00
|
|
|
class _Sp_counted_ptr final : public _Sp_counted_base<_Lp>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-06-05 19:43:29 +02:00
|
|
|
explicit
|
2013-04-28 13:38:21 +02:00
|
|
|
_Sp_counted_ptr(_Ptr __p) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
: _M_ptr(__p) { }
|
|
|
|
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_dispose() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ delete _M_ptr; }
|
|
|
|
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_destroy() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ delete this; }
|
|
|
|
|
|
|
|
virtual void*
|
2013-04-28 13:38:21 +02:00
|
|
|
_M_get_deleter(const std::type_info&) noexcept
|
|
|
|
{ return nullptr; }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
_Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
|
|
|
|
_Sp_counted_ptr& operator=(const _Sp_counted_ptr&) = delete;
|
|
|
|
|
2013-04-28 13:38:21 +02:00
|
|
|
private:
|
|
|
|
_Ptr _M_ptr;
|
2009-11-06 23:15:17 +01:00
|
|
|
};
|
|
|
|
|
2010-06-05 19:43:29 +02:00
|
|
|
template<>
|
2010-06-05 20:35:53 +02:00
|
|
|
inline void
|
2011-05-19 00:59:17 +02:00
|
|
|
_Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() noexcept { }
|
2010-06-05 19:43:29 +02:00
|
|
|
|
|
|
|
template<>
|
2010-06-05 20:35:53 +02:00
|
|
|
inline void
|
2011-05-19 00:59:17 +02:00
|
|
|
_Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() noexcept { }
|
2010-06-05 19:43:29 +02:00
|
|
|
|
|
|
|
template<>
|
2010-06-05 20:35:53 +02:00
|
|
|
inline void
|
2011-05-19 00:59:17 +02:00
|
|
|
_Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() noexcept { }
|
2010-06-05 19:43:29 +02:00
|
|
|
|
2013-04-28 13:38:21 +02:00
|
|
|
template<int _Nm, typename _Tp,
|
|
|
|
bool __use_ebo = !__is_final(_Tp) && __is_empty(_Tp)>
|
|
|
|
struct _Sp_ebo_helper;
|
|
|
|
|
|
|
|
/// Specialization using EBO.
|
|
|
|
template<int _Nm, typename _Tp>
|
|
|
|
struct _Sp_ebo_helper<_Nm, _Tp, true> : private _Tp
|
|
|
|
{
|
|
|
|
explicit _Sp_ebo_helper(const _Tp& __tp) : _Tp(__tp) { }
|
2017-06-09 15:20:37 +02:00
|
|
|
explicit _Sp_ebo_helper(_Tp&& __tp) : _Tp(std::move(__tp)) { }
|
2013-04-28 13:38:21 +02:00
|
|
|
|
|
|
|
static _Tp&
|
|
|
|
_S_get(_Sp_ebo_helper& __eboh) { return static_cast<_Tp&>(__eboh); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Specialization not using EBO.
|
|
|
|
template<int _Nm, typename _Tp>
|
|
|
|
struct _Sp_ebo_helper<_Nm, _Tp, false>
|
|
|
|
{
|
|
|
|
explicit _Sp_ebo_helper(const _Tp& __tp) : _M_tp(__tp) { }
|
2017-06-09 15:20:37 +02:00
|
|
|
explicit _Sp_ebo_helper(_Tp&& __tp) : _M_tp(std::move(__tp)) { }
|
2013-04-28 13:38:21 +02:00
|
|
|
|
|
|
|
static _Tp&
|
|
|
|
_S_get(_Sp_ebo_helper& __eboh)
|
|
|
|
{ return __eboh._M_tp; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
_Tp _M_tp;
|
|
|
|
};
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
// Support for custom deleter and/or allocator
|
|
|
|
template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>
|
2011-11-08 17:45:54 +01:00
|
|
|
class _Sp_counted_deleter final : public _Sp_counted_base<_Lp>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2013-04-28 13:38:21 +02:00
|
|
|
class _Impl : _Sp_ebo_helper<0, _Deleter>, _Sp_ebo_helper<1, _Alloc>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2013-04-28 13:38:21 +02:00
|
|
|
typedef _Sp_ebo_helper<0, _Deleter> _Del_base;
|
|
|
|
typedef _Sp_ebo_helper<1, _Alloc> _Alloc_base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
_Impl(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_ptr(__p), _Del_base(std::move(__d)), _Alloc_base(__a)
|
2013-04-28 13:38:21 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
_Deleter& _M_del() noexcept { return _Del_base::_S_get(*this); }
|
|
|
|
_Alloc& _M_alloc() noexcept { return _Alloc_base::_S_get(*this); }
|
|
|
|
|
|
|
|
_Ptr _M_ptr;
|
2009-11-06 23:15:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2014-06-25 22:54:46 +02:00
|
|
|
using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_deleter>;
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
// __d(__p) must not throw.
|
2013-04-28 13:38:21 +02:00
|
|
|
_Sp_counted_deleter(_Ptr __p, _Deleter __d) noexcept
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_impl(__p, std::move(__d), _Alloc()) { }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// __d(__p) must not throw.
|
2013-04-28 13:38:21 +02:00
|
|
|
_Sp_counted_deleter(_Ptr __p, _Deleter __d, const _Alloc& __a) noexcept
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_impl(__p, std::move(__d), __a) { }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2012-04-12 00:54:53 +02:00
|
|
|
~_Sp_counted_deleter() noexcept { }
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_dispose() noexcept
|
2013-04-28 13:38:21 +02:00
|
|
|
{ _M_impl._M_del()(_M_impl._M_ptr); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_destroy() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2014-06-25 22:54:46 +02:00
|
|
|
__allocator_type __a(_M_impl._M_alloc());
|
|
|
|
__allocated_ptr<__allocator_type> __guard_ptr{ __a, this };
|
|
|
|
this->~_Sp_counted_deleter();
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void*
|
2013-04-28 13:38:21 +02:00
|
|
|
_M_get_deleter(const std::type_info& __ti) noexcept
|
2009-11-20 22:23:02 +01:00
|
|
|
{
|
2014-12-12 16:58:49 +01:00
|
|
|
#if __cpp_rtti
|
2014-11-12 20:41:36 +01:00
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 2400. shared_ptr's get_deleter() should use addressof()
|
|
|
|
return __ti == typeid(_Deleter)
|
|
|
|
? std::__addressof(_M_impl._M_del())
|
|
|
|
: nullptr;
|
2009-11-20 22:23:02 +01:00
|
|
|
#else
|
2013-04-28 13:38:21 +02:00
|
|
|
return nullptr;
|
2009-11-20 22:23:02 +01:00
|
|
|
#endif
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2013-04-28 13:38:21 +02:00
|
|
|
private:
|
|
|
|
_Impl _M_impl;
|
2009-11-06 23:15:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// helpers for make_shared / allocate_shared
|
|
|
|
|
2017-05-11 15:21:07 +02:00
|
|
|
struct _Sp_make_shared_tag
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
|
|
|
|
friend class _Sp_counted_ptr_inplace;
|
|
|
|
|
|
|
|
static const type_info&
|
2018-07-20 13:24:55 +02:00
|
|
|
_S_ti() noexcept _GLIBCXX_VISIBILITY(default)
|
2017-05-11 15:21:07 +02:00
|
|
|
{
|
PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.
This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.
This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).
If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.
PR libstdc++/85930
PR libstdc++/87520
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
[__cpp_rtti]: Define even when RTTI is enabled. Use array of
sizeof(type_info) so that type-punned reference binds to an object
of the correct size as well as correct alignment.
(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
_S_ti() reference even when RTTI is enabled.
(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).
From-SVN: r266376
2018-11-22 14:42:39 +01:00
|
|
|
alignas(type_info) static constexpr char __tag[sizeof(type_info)] = { };
|
2017-05-11 15:21:07 +02:00
|
|
|
return reinterpret_cast<const type_info&>(__tag);
|
|
|
|
}
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
|
|
|
|
static bool _S_eq(const type_info&) noexcept;
|
2017-05-11 15:21:07 +02:00
|
|
|
};
|
2009-11-06 23:15:17 +01:00
|
|
|
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
template<typename _Alloc>
|
|
|
|
struct _Sp_alloc_shared_tag
|
|
|
|
{
|
|
|
|
const _Alloc& _M_a;
|
|
|
|
};
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
|
2011-11-08 17:45:54 +01:00
|
|
|
class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2013-04-28 13:38:21 +02:00
|
|
|
class _Impl : _Sp_ebo_helper<0, _Alloc>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2013-04-28 13:38:21 +02:00
|
|
|
typedef _Sp_ebo_helper<0, _Alloc> _A_base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit _Impl(_Alloc __a) noexcept : _A_base(__a) { }
|
|
|
|
|
|
|
|
_Alloc& _M_alloc() noexcept { return _A_base::_S_get(*this); }
|
|
|
|
|
|
|
|
__gnu_cxx::__aligned_buffer<_Tp> _M_storage;
|
2011-11-08 17:45:54 +01:00
|
|
|
};
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2011-11-08 17:45:54 +01:00
|
|
|
public:
|
2014-06-25 22:54:46 +02:00
|
|
|
using __allocator_type = __alloc_rebind<_Alloc, _Sp_counted_ptr_inplace>;
|
|
|
|
|
2018-06-06 21:39:27 +02:00
|
|
|
// Alloc parameter is not a reference so doesn't alias anything in __args
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename... _Args>
|
|
|
|
_Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
|
2013-04-28 13:38:21 +02:00
|
|
|
: _M_impl(__a)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2011-11-08 17:45:54 +01:00
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 2070. allocate_shared should use allocator_traits<A>::construct
|
2013-04-28 13:38:21 +02:00
|
|
|
allocator_traits<_Alloc>::construct(__a, _M_ptr(),
|
2011-11-08 17:45:54 +01:00
|
|
|
std::forward<_Args>(__args)...); // might throw
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2012-04-12 00:54:53 +02:00
|
|
|
~_Sp_counted_ptr_inplace() noexcept { }
|
|
|
|
|
2011-11-08 17:45:54 +01:00
|
|
|
virtual void
|
|
|
|
_M_dispose() noexcept
|
2013-04-28 13:38:21 +02:00
|
|
|
{
|
|
|
|
allocator_traits<_Alloc>::destroy(_M_impl._M_alloc(), _M_ptr());
|
|
|
|
}
|
2011-11-08 17:45:54 +01:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
// Override because the allocator needs to know the dynamic type
|
|
|
|
virtual void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_destroy() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2014-06-25 22:54:46 +02:00
|
|
|
__allocator_type __a(_M_impl._M_alloc());
|
|
|
|
__allocated_ptr<__allocator_type> __guard_ptr{ __a, this };
|
|
|
|
this->~_Sp_counted_ptr_inplace();
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
private:
|
|
|
|
friend class __shared_count<_Lp>; // To be able to call _M_ptr().
|
|
|
|
|
|
|
|
// No longer used, but code compiled against old libstdc++ headers
|
|
|
|
// might still call it from __shared_ptr ctor to get the pointer out.
|
2009-11-06 23:15:17 +01:00
|
|
|
virtual void*
|
PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.
This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.
This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).
If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.
PR libstdc++/85930
PR libstdc++/87520
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
[__cpp_rtti]: Define even when RTTI is enabled. Use array of
sizeof(type_info) so that type-punned reference binds to an object
of the correct size as well as correct alignment.
(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
_S_ti() reference even when RTTI is enabled.
(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).
From-SVN: r266376
2018-11-22 14:42:39 +01:00
|
|
|
_M_get_deleter(const std::type_info& __ti) noexcept override
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
auto __ptr = const_cast<typename remove_cv<_Tp>::type*>(_M_ptr());
|
PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.
This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.
This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).
If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.
PR libstdc++/85930
PR libstdc++/87520
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
[__cpp_rtti]: Define even when RTTI is enabled. Use array of
sizeof(type_info) so that type-punned reference binds to an object
of the correct size as well as correct alignment.
(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
_S_ti() reference even when RTTI is enabled.
(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).
From-SVN: r266376
2018-11-22 14:42:39 +01:00
|
|
|
// Check for the fake type_info first, so we don't try to access it
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
// as a real type_info object. Otherwise, check if it's the real
|
|
|
|
// type_info for this class. With RTTI enabled we can check directly,
|
|
|
|
// or call a library function to do it.
|
|
|
|
if (&__ti == &_Sp_make_shared_tag::_S_ti()
|
|
|
|
||
|
PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.
This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.
This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).
If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.
PR libstdc++/85930
PR libstdc++/87520
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
[__cpp_rtti]: Define even when RTTI is enabled. Use array of
sizeof(type_info) so that type-punned reference binds to an object
of the correct size as well as correct alignment.
(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
_S_ti() reference even when RTTI is enabled.
(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).
From-SVN: r266376
2018-11-22 14:42:39 +01:00
|
|
|
#if __cpp_rtti
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
__ti == typeid(_Sp_make_shared_tag)
|
|
|
|
#else
|
|
|
|
_Sp_make_shared_tag::_S_eq(__ti)
|
PR libstdc++/87520 Always pass type-punned type_info reference
The implementations of std::make_shared for -frtti and -fno-rtti are not
compatible, because they pass different arguments to
_Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate.
Either the argument doesn't match the expected value, and so the
shared_ptr::_M_ptr member is never set, or the type-punned reference is
treated as a real std::type_info object and gets dereferenced.
This patch removes the differences between -frtti and -fno-rtti, so that
typeid is never used, and the type-punned reference is used in both
cases. For backwards compatibility with existing code that passes
typeid(_Sp_make_shared_tag) that still needs to be handled, but only
after checking that the argument is not the type-punned reference (so
it's safe to treat as a real std::type_info object). The reference is
bound to an object of literal type, so that it doesn't need a guard
variable to make its initialization thread-safe.
This patch also fixes 87520 by ensuring that the type-punned reference
is bound to "a region of storage of suitable size and alignment to
contain an object of the reference's type" (as per the proposed
resolution of Core DR 453).
If all objects are built with the fixed version of GCC then -frtti and
-fno-rtti can be mixed freely and std::make_shared will work correctly.
If some objects are built with unfixed GCC versions then problems can
still arise, depending on which template instantiations are kept by the
linker.
PR libstdc++/85930
PR libstdc++/87520
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti)
[__cpp_rtti]: Define even when RTTI is enabled. Use array of
sizeof(type_info) so that type-punned reference binds to an object
of the correct size as well as correct alignment.
(_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for
_S_ti() reference even when RTTI is enabled.
(__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...))
[__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag).
From-SVN: r266376
2018-11-22 14:42:39 +01:00
|
|
|
#endif
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
)
|
|
|
|
return __ptr;
|
2013-10-02 21:55:14 +02:00
|
|
|
return nullptr;
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2013-04-28 13:38:21 +02:00
|
|
|
_Tp* _M_ptr() noexcept { return _M_impl._M_storage._M_ptr(); }
|
|
|
|
|
2011-11-08 17:45:54 +01:00
|
|
|
_Impl _M_impl;
|
2009-11-06 23:15:17 +01:00
|
|
|
};
|
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
// The default deleter for shared_ptr<T[]> and shared_ptr<T[N]>.
|
|
|
|
struct __sp_array_delete
|
|
|
|
{
|
|
|
|
template<typename _Yp>
|
|
|
|
void operator()(_Yp* __p) const { delete[] __p; }
|
|
|
|
};
|
2013-04-28 13:38:21 +02:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
template<_Lock_policy _Lp>
|
|
|
|
class __shared_count
|
|
|
|
{
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
template<typename _Tp>
|
|
|
|
struct __not_alloc_shared_tag { using type = void; };
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
struct __not_alloc_shared_tag<_Sp_alloc_shared_tag<_Tp>> { };
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
public:
|
2011-05-19 00:59:17 +02:00
|
|
|
constexpr __shared_count() noexcept : _M_pi(0)
|
2009-11-06 23:15:17 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _Ptr>
|
2010-06-05 19:43:29 +02:00
|
|
|
explicit
|
2009-11-06 23:15:17 +01:00
|
|
|
__shared_count(_Ptr __p) : _M_pi(0)
|
|
|
|
{
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_M_pi = new _Sp_counted_ptr<_Ptr, _Lp>(__p);
|
|
|
|
}
|
|
|
|
__catch(...)
|
|
|
|
{
|
|
|
|
delete __p;
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
template<typename _Ptr>
|
|
|
|
__shared_count(_Ptr __p, /* is_array = */ false_type)
|
|
|
|
: __shared_count(__p)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _Ptr>
|
|
|
|
__shared_count(_Ptr __p, /* is_array = */ true_type)
|
|
|
|
: __shared_count(__p, __sp_array_delete{}, allocator<void>())
|
|
|
|
{ }
|
|
|
|
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
template<typename _Ptr, typename _Deleter,
|
|
|
|
typename = typename __not_alloc_shared_tag<_Deleter>::type>
|
2013-10-08 14:33:37 +02:00
|
|
|
__shared_count(_Ptr __p, _Deleter __d)
|
|
|
|
: __shared_count(__p, std::move(__d), allocator<void>())
|
|
|
|
{ }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
template<typename _Ptr, typename _Deleter, typename _Alloc,
|
|
|
|
typename = typename __not_alloc_shared_tag<_Deleter>::type>
|
2009-11-06 23:15:17 +01:00
|
|
|
__shared_count(_Ptr __p, _Deleter __d, _Alloc __a) : _M_pi(0)
|
|
|
|
{
|
|
|
|
typedef _Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp> _Sp_cd_type;
|
|
|
|
__try
|
|
|
|
{
|
2014-06-25 22:54:46 +02:00
|
|
|
typename _Sp_cd_type::__allocator_type __a2(__a);
|
|
|
|
auto __guard = std::__allocate_guarded(__a2);
|
|
|
|
_Sp_cd_type* __mem = __guard.get();
|
|
|
|
::new (__mem) _Sp_cd_type(__p, std::move(__d), std::move(__a));
|
2011-11-08 17:45:54 +01:00
|
|
|
_M_pi = __mem;
|
2014-06-25 22:54:46 +02:00
|
|
|
__guard = nullptr;
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
__catch(...)
|
|
|
|
{
|
|
|
|
__d(__p); // Call _Deleter on __p.
|
|
|
|
__throw_exception_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Alloc, typename... _Args>
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
__shared_count(_Tp*& __p, _Sp_alloc_shared_tag<_Alloc> __a,
|
shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter, const _Alloc&), [...]): Take the allocator by value, per N3225.
2010-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter,
const _Alloc&), shared_ptr(nullptr_t, _Deleter, const _Alloc&)): Take
the allocator by value, per N3225.
(shared_ptr<>::shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
allocate_shared(_Alloc, _Args&&...): Viceversa, take the allocator
by const lvalue ref.
* include/bits/shared_ptr_base.h (__shared_count<>::
__shared_count(_Sp_make_shared_tag, _Tp*, _Alloc, _Args&&...),
__shared_ptr<>::__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
__allocate_shared(_Alloc, _Args&&...)): Likewise.
(__shared_ptr<>::__shared_ptr(_Tp1*, _Deleter, const _Alloc&),
__shared_ptr(nullptr_t, _Deleter, const _Alloc&), reset(_Tp1*,
_Deleter, const _Alloc&)): Take the allocator by value.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
From-SVN: r167510
2010-12-06 19:37:00 +01:00
|
|
|
_Args&&... __args)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type;
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
typename _Sp_cp_type::__allocator_type __a2(__a._M_a);
|
2014-06-25 22:54:46 +02:00
|
|
|
auto __guard = std::__allocate_guarded(__a2);
|
|
|
|
_Sp_cp_type* __mem = __guard.get();
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
auto __pi = ::new (__mem)
|
|
|
|
_Sp_cp_type(__a._M_a, std::forward<_Args>(__args)...);
|
2014-06-25 22:54:46 +02:00
|
|
|
__guard = nullptr;
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
_M_pi = __pi;
|
|
|
|
__p = __pi->_M_ptr();
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 21:46:43 +01:00
|
|
|
#if _GLIBCXX_USE_DEPRECATED
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2009-11-06 23:15:17 +01:00
|
|
|
// Special case for auto_ptr<_Tp> to provide the strong guarantee.
|
|
|
|
template<typename _Tp>
|
2010-06-05 19:43:29 +02:00
|
|
|
explicit
|
2012-08-03 02:27:48 +02:00
|
|
|
__shared_count(std::auto_ptr<_Tp>&& __r);
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2009-11-06 23:15:17 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
|
|
|
|
template<typename _Tp, typename _Del>
|
2010-06-05 19:43:29 +02:00
|
|
|
explicit
|
2013-10-08 14:33:37 +02:00
|
|
|
__shared_count(std::unique_ptr<_Tp, _Del>&& __r) : _M_pi(0)
|
|
|
|
{
|
2015-05-13 18:42:18 +02:00
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 2415. Inconsistency between unique_ptr and shared_ptr
|
|
|
|
if (__r.get() == nullptr)
|
|
|
|
return;
|
|
|
|
|
2013-10-08 14:33:37 +02:00
|
|
|
using _Ptr = typename unique_ptr<_Tp, _Del>::pointer;
|
|
|
|
using _Del2 = typename conditional<is_reference<_Del>::value,
|
|
|
|
reference_wrapper<typename remove_reference<_Del>::type>,
|
|
|
|
_Del>::type;
|
|
|
|
using _Sp_cd_type
|
|
|
|
= _Sp_counted_deleter<_Ptr, _Del2, allocator<void>, _Lp>;
|
|
|
|
using _Alloc = allocator<_Sp_cd_type>;
|
|
|
|
using _Alloc_traits = allocator_traits<_Alloc>;
|
|
|
|
_Alloc __a;
|
|
|
|
_Sp_cd_type* __mem = _Alloc_traits::allocate(__a, 1);
|
|
|
|
_Alloc_traits::construct(__a, __mem, __r.release(),
|
|
|
|
__r.get_deleter()); // non-throwing
|
|
|
|
_M_pi = __mem;
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// Throw bad_weak_ptr when __r._M_get_use_count() == 0.
|
|
|
|
explicit __shared_count(const __weak_count<_Lp>& __r);
|
|
|
|
|
2014-01-28 11:23:27 +01:00
|
|
|
// Does not throw if __r._M_get_use_count() == 0, caller must check.
|
|
|
|
explicit __shared_count(const __weak_count<_Lp>& __r, std::nothrow_t);
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
~__shared_count() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2013-10-08 14:33:37 +02:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_release();
|
|
|
|
}
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__shared_count(const __shared_count& __r) noexcept
|
|
|
|
: _M_pi(__r._M_pi)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
if (_M_pi != 0)
|
|
|
|
_M_pi->_M_add_ref_copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
__shared_count&
|
2011-05-19 00:59:17 +02:00
|
|
|
operator=(const __shared_count& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
|
|
|
if (__tmp != _M_pi)
|
|
|
|
{
|
|
|
|
if (__tmp != 0)
|
|
|
|
__tmp->_M_add_ref_copy();
|
|
|
|
if (_M_pi != 0)
|
|
|
|
_M_pi->_M_release();
|
|
|
|
_M_pi = __tmp;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_swap(__shared_count& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
|
|
|
__r._M_pi = _M_pi;
|
|
|
|
_M_pi = __tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_get_use_count() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
|
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_unique() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return this->_M_get_use_count() == 1; }
|
|
|
|
|
|
|
|
void*
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_get_deleter(const std::type_info& __ti) const noexcept
|
2013-04-28 13:38:21 +02:00
|
|
|
{ return _M_pi ? _M_pi->_M_get_deleter(__ti) : nullptr; }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_less(const __shared_count& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
|
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_less(const __weak_count<_Lp>& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
|
|
|
|
|
|
|
|
// Friend function injected into enclosing namespace and found by ADL
|
|
|
|
friend inline bool
|
2011-05-19 00:59:17 +02:00
|
|
|
operator==(const __shared_count& __a, const __shared_count& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __a._M_pi == __b._M_pi; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class __weak_count<_Lp>;
|
|
|
|
|
|
|
|
_Sp_counted_base<_Lp>* _M_pi;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<_Lock_policy _Lp>
|
|
|
|
class __weak_count
|
|
|
|
{
|
|
|
|
public:
|
2014-11-12 12:54:08 +01:00
|
|
|
constexpr __weak_count() noexcept : _M_pi(nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
{ }
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__weak_count(const __shared_count<_Lp>& __r) noexcept
|
|
|
|
: _M_pi(__r._M_pi)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2014-11-12 12:54:08 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_weak_add_ref();
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_count(const __weak_count& __r) noexcept
|
2011-05-19 00:59:17 +02:00
|
|
|
: _M_pi(__r._M_pi)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2014-11-12 12:54:08 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_weak_add_ref();
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_count(__weak_count&& __r) noexcept
|
|
|
|
: _M_pi(__r._M_pi)
|
|
|
|
{ __r._M_pi = nullptr; }
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
~__weak_count() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2014-11-12 12:54:08 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_weak_release();
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_count&
|
2011-05-19 00:59:17 +02:00
|
|
|
operator=(const __shared_count<_Lp>& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
2014-11-12 12:54:08 +01:00
|
|
|
if (__tmp != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
__tmp->_M_weak_add_ref();
|
2014-11-12 12:54:08 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_weak_release();
|
|
|
|
_M_pi = __tmp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_count&
|
|
|
|
operator=(const __weak_count& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
2014-11-12 12:54:08 +01:00
|
|
|
if (__tmp != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
__tmp->_M_weak_add_ref();
|
2014-11-12 12:54:08 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_weak_release();
|
|
|
|
_M_pi = __tmp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_count&
|
|
|
|
operator=(__weak_count&& __r) noexcept
|
|
|
|
{
|
|
|
|
if (_M_pi != nullptr)
|
|
|
|
_M_pi->_M_weak_release();
|
|
|
|
_M_pi = __r._M_pi;
|
|
|
|
__r._M_pi = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
void
|
2014-11-12 12:54:08 +01:00
|
|
|
_M_swap(__weak_count& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
|
|
|
__r._M_pi = _M_pi;
|
|
|
|
_M_pi = __tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
long
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_get_use_count() const noexcept
|
2014-11-12 12:54:08 +01:00
|
|
|
{ return _M_pi != nullptr ? _M_pi->_M_get_use_count() : 0; }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_less(const __weak_count& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
|
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_less(const __shared_count<_Lp>& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
|
|
|
|
|
|
|
|
// Friend function injected into enclosing namespace and found by ADL
|
|
|
|
friend inline bool
|
2011-05-19 00:59:17 +02:00
|
|
|
operator==(const __weak_count& __a, const __weak_count& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __a._M_pi == __b._M_pi; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class __shared_count<_Lp>;
|
|
|
|
|
|
|
|
_Sp_counted_base<_Lp>* _M_pi;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Now that __weak_count is defined we can define this constructor:
|
|
|
|
template<_Lock_policy _Lp>
|
2014-01-28 11:23:27 +01:00
|
|
|
inline
|
|
|
|
__shared_count<_Lp>::__shared_count(const __weak_count<_Lp>& __r)
|
2009-11-06 23:15:17 +01:00
|
|
|
: _M_pi(__r._M_pi)
|
|
|
|
{
|
2014-01-28 11:23:27 +01:00
|
|
|
if (_M_pi != nullptr)
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_pi->_M_add_ref_lock();
|
|
|
|
else
|
|
|
|
__throw_bad_weak_ptr();
|
|
|
|
}
|
|
|
|
|
2014-01-28 11:23:27 +01:00
|
|
|
// Now that __weak_count is defined we can define this constructor:
|
|
|
|
template<_Lock_policy _Lp>
|
|
|
|
inline
|
|
|
|
__shared_count<_Lp>::
|
|
|
|
__shared_count(const __weak_count<_Lp>& __r, std::nothrow_t)
|
|
|
|
: _M_pi(__r._M_pi)
|
|
|
|
{
|
|
|
|
if (_M_pi != nullptr)
|
|
|
|
if (!_M_pi->_M_add_ref_lock_nothrow())
|
|
|
|
_M_pi = nullptr;
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2019-01-15 14:13:11 +01:00
|
|
|
#define __cpp_lib_shared_ptr_arrays 201611L
|
2016-11-13 23:57:45 +01:00
|
|
|
|
|
|
|
// Helper traits for shared_ptr of array:
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
// A pointer type Y* is said to be compatible with a pointer type T* when
|
|
|
|
// either Y* is convertible to T* or Y is U[N] and T is U cv [].
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp_ptr, typename _Tp_ptr>
|
|
|
|
struct __sp_compatible_with
|
|
|
|
: false_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Yp, typename _Tp>
|
|
|
|
struct __sp_compatible_with<_Yp*, _Tp*>
|
|
|
|
: is_convertible<_Yp*, _Tp*>::type
|
|
|
|
{ };
|
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
template<typename _Up, size_t _Nm>
|
|
|
|
struct __sp_compatible_with<_Up(*)[_Nm], _Up(*)[]>
|
|
|
|
: true_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Up, size_t _Nm>
|
|
|
|
struct __sp_compatible_with<_Up(*)[_Nm], const _Up(*)[]>
|
|
|
|
: true_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Up, size_t _Nm>
|
|
|
|
struct __sp_compatible_with<_Up(*)[_Nm], volatile _Up(*)[]>
|
|
|
|
: true_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Up, size_t _Nm>
|
|
|
|
struct __sp_compatible_with<_Up(*)[_Nm], const volatile _Up(*)[]>
|
|
|
|
: true_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
// Test conversion from Y(*)[N] to U(*)[N] without forming invalid type Y[N].
|
|
|
|
template<typename _Up, size_t _Nm, typename _Yp, typename = void>
|
|
|
|
struct __sp_is_constructible_arrN
|
|
|
|
: false_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Up, size_t _Nm, typename _Yp>
|
|
|
|
struct __sp_is_constructible_arrN<_Up, _Nm, _Yp, __void_t<_Yp[_Nm]>>
|
|
|
|
: is_convertible<_Yp(*)[_Nm], _Up(*)[_Nm]>::type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
// Test conversion from Y(*)[] to U(*)[] without forming invalid type Y[].
|
|
|
|
template<typename _Up, typename _Yp, typename = void>
|
|
|
|
struct __sp_is_constructible_arr
|
|
|
|
: false_type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Up, typename _Yp>
|
|
|
|
struct __sp_is_constructible_arr<_Up, _Yp, __void_t<_Yp[]>>
|
|
|
|
: is_convertible<_Yp(*)[], _Up(*)[]>::type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
// Trait to check if shared_ptr<T> can be constructed from Y*.
|
|
|
|
template<typename _Tp, typename _Yp>
|
|
|
|
struct __sp_is_constructible;
|
|
|
|
|
|
|
|
// When T is U[N], Y(*)[N] shall be convertible to T*;
|
|
|
|
template<typename _Up, size_t _Nm, typename _Yp>
|
|
|
|
struct __sp_is_constructible<_Up[_Nm], _Yp>
|
|
|
|
: __sp_is_constructible_arrN<_Up, _Nm, _Yp>::type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
// when T is U[], Y(*)[] shall be convertible to T*;
|
|
|
|
template<typename _Up, typename _Yp>
|
|
|
|
struct __sp_is_constructible<_Up[], _Yp>
|
|
|
|
: __sp_is_constructible_arr<_Up, _Yp>::type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
// otherwise, Y* shall be convertible to T*.
|
|
|
|
template<typename _Tp, typename _Yp>
|
|
|
|
struct __sp_is_constructible
|
|
|
|
: is_convertible<_Yp*, _Tp*>::type
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
|
|
// Define operator* and operator-> for shared_ptr<T>.
|
|
|
|
template<typename _Tp, _Lock_policy _Lp,
|
|
|
|
bool = is_array<_Tp>::value, bool = is_void<_Tp>::value>
|
|
|
|
class __shared_ptr_access
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using element_type = _Tp;
|
|
|
|
|
|
|
|
element_type&
|
|
|
|
operator*() const noexcept
|
|
|
|
{
|
|
|
|
__glibcxx_assert(_M_get() != nullptr);
|
|
|
|
return *_M_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
element_type*
|
|
|
|
operator->() const noexcept
|
|
|
|
{
|
|
|
|
_GLIBCXX_DEBUG_PEDASSERT(_M_get() != nullptr);
|
|
|
|
return _M_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
element_type*
|
|
|
|
_M_get() const noexcept
|
|
|
|
{ return static_cast<const __shared_ptr<_Tp, _Lp>*>(this)->get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define operator-> for shared_ptr<cv void>.
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
2016-11-13 23:57:45 +01:00
|
|
|
class __shared_ptr_access<_Tp, _Lp, false, true>
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
public:
|
|
|
|
using element_type = _Tp;
|
2014-11-12 20:41:36 +01:00
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
element_type*
|
|
|
|
operator->() const noexcept
|
|
|
|
{
|
2016-12-06 15:36:00 +01:00
|
|
|
auto __ptr = static_cast<const __shared_ptr<_Tp, _Lp>*>(this)->get();
|
|
|
|
_GLIBCXX_DEBUG_PEDASSERT(__ptr != nullptr);
|
|
|
|
return __ptr;
|
2016-11-13 23:57:45 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define operator[] for shared_ptr<T[]> and shared_ptr<T[N]>.
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
class __shared_ptr_access<_Tp, _Lp, true, false>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using element_type = typename remove_extent<_Tp>::type;
|
|
|
|
|
|
|
|
#if __cplusplus <= 201402L
|
|
|
|
[[__deprecated__("shared_ptr<T[]>::operator* is absent from C++17")]]
|
|
|
|
element_type&
|
|
|
|
operator*() const noexcept
|
|
|
|
{
|
2016-11-30 15:46:15 +01:00
|
|
|
__glibcxx_assert(_M_get() != nullptr);
|
2016-11-13 23:57:45 +01:00
|
|
|
return *_M_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[__deprecated__("shared_ptr<T[]>::operator-> is absent from C++17")]]
|
|
|
|
element_type*
|
|
|
|
operator->() const noexcept
|
|
|
|
{
|
|
|
|
_GLIBCXX_DEBUG_PEDASSERT(_M_get() != nullptr);
|
|
|
|
return _M_get();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
element_type&
|
|
|
|
operator[](ptrdiff_t __i) const
|
|
|
|
{
|
|
|
|
__glibcxx_assert(_M_get() != nullptr);
|
|
|
|
__glibcxx_assert(!extent<_Tp>::value || __i < extent<_Tp>::value);
|
|
|
|
return _M_get()[__i];
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
private:
|
2016-11-13 23:57:45 +01:00
|
|
|
element_type*
|
|
|
|
_M_get() const noexcept
|
|
|
|
{ return static_cast<const __shared_ptr<_Tp, _Lp>*>(this)->get(); }
|
|
|
|
};
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
class __shared_ptr
|
|
|
|
: public __shared_ptr_access<_Tp, _Lp>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using element_type = typename remove_extent<_Tp>::type;
|
|
|
|
|
|
|
|
private:
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
// Constraint for taking ownership of a pointer of type _Yp*:
|
|
|
|
template<typename _Yp>
|
|
|
|
using _SafeConv
|
|
|
|
= typename enable_if<__sp_is_constructible<_Tp, _Yp>::value>::type;
|
|
|
|
|
|
|
|
// Constraint for construction from shared_ptr and weak_ptr:
|
|
|
|
template<typename _Yp, typename _Res = void>
|
|
|
|
using _Compatible = typename
|
|
|
|
enable_if<__sp_compatible_with<_Yp*, _Tp*>::value, _Res>::type;
|
|
|
|
|
|
|
|
// Constraint for assignment from shared_ptr and weak_ptr:
|
|
|
|
template<typename _Yp>
|
|
|
|
using _Assignable = _Compatible<_Yp, __shared_ptr&>;
|
|
|
|
|
|
|
|
// Constraint for construction from unique_ptr:
|
|
|
|
template<typename _Yp, typename _Del, typename _Res = void,
|
|
|
|
typename _Ptr = typename unique_ptr<_Yp, _Del>::pointer>
|
2016-11-13 23:57:45 +01:00
|
|
|
using _UniqCompatible = typename enable_if<__and_<
|
|
|
|
__sp_compatible_with<_Yp*, _Tp*>, is_convertible<_Ptr, element_type*>
|
|
|
|
>::value, _Res>::type;
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
|
|
|
|
// Constraint for assignment from unique_ptr:
|
|
|
|
template<typename _Yp, typename _Del>
|
|
|
|
using _UniqAssignable = _UniqCompatible<_Yp, _Del, __shared_ptr&>;
|
2016-08-31 18:57:20 +02:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
public:
|
|
|
|
|
2016-08-03 21:09:57 +02:00
|
|
|
#if __cplusplus > 201402L
|
|
|
|
using weak_type = __weak_ptr<_Tp, _Lp>;
|
|
|
|
#endif
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
constexpr __shared_ptr() noexcept
|
|
|
|
: _M_ptr(0), _M_refcount()
|
2009-11-06 23:15:17 +01:00
|
|
|
{ }
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _SafeConv<_Yp>>
|
|
|
|
explicit
|
|
|
|
__shared_ptr(_Yp* __p)
|
2016-11-13 23:57:45 +01:00
|
|
|
: _M_ptr(__p), _M_refcount(__p, typename is_array<_Tp>::type())
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
static_assert( !is_void<_Yp>::value, "incomplete type" );
|
|
|
|
static_assert( sizeof(_Yp) > 0, "incomplete type" );
|
2016-10-19 22:13:14 +02:00
|
|
|
_M_enable_shared_from_this_with(__p);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Deleter, typename = _SafeConv<_Yp>>
|
|
|
|
__shared_ptr(_Yp* __p, _Deleter __d)
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_ptr(__p), _M_refcount(__p, std::move(__d))
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
P0604R0 add invoke_result, is_invocable etc. for C++17
* include/bits/invoke.h (__invoke): Use __invoke_result instead of
result_of, and __is_nothrow_invocable instead of
__is_nothrow_callable.
* include/bits/shared_ptr_base.h (__shared_ptr): Use __is_invocable
instead of __is_callable.
* include/std/functional (invoke): use invoke_result_t instead of
result_of_t and is_nothrow_invocable instead of is_nothrow_callable.
(_Not_fn): Use __invoke_result instead of result_of.
* include/std/type_traits (__result_of_memobj, __result_of_memfun):
Remove partial specializations for reference_wrapper types.
(__result_of_impl): Use __inv_unwrap to strip reference_wrapper.
(__invoke_result): Define replacement for result_of and then use it to
define result_of.
(__is_callable_impl, __is_callable, __is_nothrow_callable): Replace
with __is_invocable_impl, __is_invocable, and __is_nothrow_invocable
respectively.
(invoke_result, invoke_result_t): Define for C++17.
(is_callable, is_nothrow_callable): Replace with is_invocable,
is_invocable_r, is_nothrow_invocable, and is_nothrow_invocable_r.
(is_callable_v, is_nothrow_callable_v): Replace with is_invocable_v,
is_invocable_r_v, is_nothrow_invocable_v, and is_nothrow_invocable_r_v.
* include/std/variant (hash<variant<T...>>): Use is_nothrow_invocable_v
instead of is_nothrow_callable_v.
* testsuite/20_util/function_objects/invoke/59768.cc: Remove unused
main function.
* testsuite/20_util/function_objects/not_fn/1.cc: Use is_invocable
instead of is_callable.
* testsuite/20_util/is_callable/*: Rename directory and adjust tests
to use new traits.
* testsuite/20_util/is_notjrow_callable/*: Likewise.
* testsuite/20_util/optional/hash.cc: Use is_invocable_v instead of
is_callable.
* testsuite/20_util/variant/hash.cc: Likewise.
From-SVN: r246036
2017-03-10 16:29:38 +01:00
|
|
|
static_assert(__is_invocable<_Deleter&, _Yp*&>::value,
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
"deleter expression d(p) is well-formed");
|
2016-10-19 22:13:14 +02:00
|
|
|
_M_enable_shared_from_this_with(__p);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Deleter, typename _Alloc,
|
|
|
|
typename = _SafeConv<_Yp>>
|
|
|
|
__shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a)
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_ptr(__p), _M_refcount(__p, std::move(__d), std::move(__a))
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
P0604R0 add invoke_result, is_invocable etc. for C++17
* include/bits/invoke.h (__invoke): Use __invoke_result instead of
result_of, and __is_nothrow_invocable instead of
__is_nothrow_callable.
* include/bits/shared_ptr_base.h (__shared_ptr): Use __is_invocable
instead of __is_callable.
* include/std/functional (invoke): use invoke_result_t instead of
result_of_t and is_nothrow_invocable instead of is_nothrow_callable.
(_Not_fn): Use __invoke_result instead of result_of.
* include/std/type_traits (__result_of_memobj, __result_of_memfun):
Remove partial specializations for reference_wrapper types.
(__result_of_impl): Use __inv_unwrap to strip reference_wrapper.
(__invoke_result): Define replacement for result_of and then use it to
define result_of.
(__is_callable_impl, __is_callable, __is_nothrow_callable): Replace
with __is_invocable_impl, __is_invocable, and __is_nothrow_invocable
respectively.
(invoke_result, invoke_result_t): Define for C++17.
(is_callable, is_nothrow_callable): Replace with is_invocable,
is_invocable_r, is_nothrow_invocable, and is_nothrow_invocable_r.
(is_callable_v, is_nothrow_callable_v): Replace with is_invocable_v,
is_invocable_r_v, is_nothrow_invocable_v, and is_nothrow_invocable_r_v.
* include/std/variant (hash<variant<T...>>): Use is_nothrow_invocable_v
instead of is_nothrow_callable_v.
* testsuite/20_util/function_objects/invoke/59768.cc: Remove unused
main function.
* testsuite/20_util/function_objects/not_fn/1.cc: Use is_invocable
instead of is_callable.
* testsuite/20_util/is_callable/*: Rename directory and adjust tests
to use new traits.
* testsuite/20_util/is_notjrow_callable/*: Likewise.
* testsuite/20_util/optional/hash.cc: Use is_invocable_v instead of
is_callable.
* testsuite/20_util/variant/hash.cc: Likewise.
From-SVN: r246036
2017-03-10 16:29:38 +01:00
|
|
|
static_assert(__is_invocable<_Deleter&, _Yp*&>::value,
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
"deleter expression d(p) is well-formed");
|
2016-10-19 22:13:14 +02:00
|
|
|
_M_enable_shared_from_this_with(__p);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2010-06-05 19:43:29 +02:00
|
|
|
template<typename _Deleter>
|
|
|
|
__shared_ptr(nullptr_t __p, _Deleter __d)
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_ptr(0), _M_refcount(__p, std::move(__d))
|
2010-06-05 19:43:29 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _Deleter, typename _Alloc>
|
shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter, const _Alloc&), [...]): Take the allocator by value, per N3225.
2010-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter,
const _Alloc&), shared_ptr(nullptr_t, _Deleter, const _Alloc&)): Take
the allocator by value, per N3225.
(shared_ptr<>::shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
allocate_shared(_Alloc, _Args&&...): Viceversa, take the allocator
by const lvalue ref.
* include/bits/shared_ptr_base.h (__shared_count<>::
__shared_count(_Sp_make_shared_tag, _Tp*, _Alloc, _Args&&...),
__shared_ptr<>::__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
__allocate_shared(_Alloc, _Args&&...)): Likewise.
(__shared_ptr<>::__shared_ptr(_Tp1*, _Deleter, const _Alloc&),
__shared_ptr(nullptr_t, _Deleter, const _Alloc&), reset(_Tp1*,
_Deleter, const _Alloc&)): Take the allocator by value.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
From-SVN: r167510
2010-12-06 19:37:00 +01:00
|
|
|
__shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a)
|
2017-06-09 15:20:37 +02:00
|
|
|
: _M_ptr(0), _M_refcount(__p, std::move(__d), std::move(__a))
|
2010-06-05 19:43:29 +02:00
|
|
|
{ }
|
|
|
|
|
2019-05-23 23:41:02 +02:00
|
|
|
// Aliasing constructor
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
__shared_ptr(const __shared_ptr<_Yp, _Lp>& __r,
|
|
|
|
element_type* __p) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
: _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
|
|
|
|
{ }
|
|
|
|
|
2019-05-23 23:41:02 +02:00
|
|
|
// Aliasing constructor
|
|
|
|
template<typename _Yp>
|
|
|
|
__shared_ptr(__shared_ptr<_Yp, _Lp>&& __r,
|
|
|
|
element_type* __p) noexcept
|
|
|
|
: _M_ptr(__p), _M_refcount()
|
|
|
|
{
|
|
|
|
_M_refcount._M_swap(__r._M_refcount);
|
|
|
|
__r._M_ptr = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__shared_ptr(const __shared_ptr&) noexcept = default;
|
|
|
|
__shared_ptr& operator=(const __shared_ptr&) noexcept = default;
|
|
|
|
~__shared_ptr() = default;
|
2009-11-06 23:15:17 +01:00
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__shared_ptr(const __shared_ptr<_Yp, _Lp>& __r) noexcept
|
2011-05-19 00:59:17 +02:00
|
|
|
: _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
|
2010-08-10 18:54:09 +02:00
|
|
|
{ }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__shared_ptr(__shared_ptr&& __r) noexcept
|
|
|
|
: _M_ptr(__r._M_ptr), _M_refcount()
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_M_refcount._M_swap(__r._M_refcount);
|
|
|
|
__r._M_ptr = 0;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__shared_ptr(__shared_ptr<_Yp, _Lp>&& __r) noexcept
|
2011-05-19 00:59:17 +02:00
|
|
|
: _M_ptr(__r._M_ptr), _M_refcount()
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_M_refcount._M_swap(__r._M_refcount);
|
|
|
|
__r._M_ptr = 0;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
explicit __shared_ptr(const __weak_ptr<_Yp, _Lp>& __r)
|
2009-11-06 23:15:17 +01:00
|
|
|
: _M_refcount(__r._M_refcount) // may throw
|
|
|
|
{
|
|
|
|
// It is now safe to copy __r._M_ptr, as
|
|
|
|
// _M_refcount(__r._M_refcount) did not throw.
|
|
|
|
_M_ptr = __r._M_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If an exception is thrown this constructor has no effect.
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Del,
|
|
|
|
typename = _UniqCompatible<_Yp, _Del>>
|
|
|
|
__shared_ptr(unique_ptr<_Yp, _Del>&& __r)
|
2009-11-06 23:15:17 +01:00
|
|
|
: _M_ptr(__r.get()), _M_refcount()
|
|
|
|
{
|
2017-09-13 09:27:40 +02:00
|
|
|
auto __raw = __to_address(__r.get());
|
2009-11-06 23:15:17 +01:00
|
|
|
_M_refcount = __shared_count<_Lp>(std::move(__r));
|
2016-10-19 22:13:14 +02:00
|
|
|
_M_enable_shared_from_this_with(__raw);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2016-11-13 23:57:45 +01:00
|
|
|
#if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATED
|
|
|
|
protected:
|
|
|
|
// If an exception is thrown this constructor has no effect.
|
|
|
|
template<typename _Tp1, typename _Del,
|
|
|
|
typename enable_if<__and_<
|
|
|
|
__not_<is_array<_Tp>>, is_array<_Tp1>,
|
|
|
|
is_convertible<typename unique_ptr<_Tp1, _Del>::pointer, _Tp*>
|
|
|
|
>::value, bool>::type = true>
|
|
|
|
__shared_ptr(unique_ptr<_Tp1, _Del>&& __r, __sp_array_delete)
|
|
|
|
: _M_ptr(__r.get()), _M_refcount()
|
|
|
|
{
|
2017-09-13 09:27:40 +02:00
|
|
|
auto __raw = __to_address(__r.get());
|
2016-11-13 23:57:45 +01:00
|
|
|
_M_refcount = __shared_count<_Lp>(std::move(__r));
|
|
|
|
_M_enable_shared_from_this_with(__raw);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
#endif
|
|
|
|
|
2011-01-31 21:46:43 +01:00
|
|
|
#if _GLIBCXX_USE_DEPRECATED
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
2009-11-06 23:15:17 +01:00
|
|
|
// Postcondition: use_count() == 1 and __r.get() == 0
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__shared_ptr(auto_ptr<_Yp>&& __r);
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2009-11-06 23:15:17 +01:00
|
|
|
#endif
|
|
|
|
|
2014-04-15 20:28:50 +02:00
|
|
|
constexpr __shared_ptr(nullptr_t) noexcept : __shared_ptr() { }
|
2010-06-05 19:43:29 +02:00
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(const __shared_ptr<_Yp, _Lp>& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_M_ptr = __r._M_ptr;
|
|
|
|
_M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-01-31 21:46:43 +01:00
|
|
|
#if _GLIBCXX_USE_DEPRECATED
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(auto_ptr<_Yp>&& __r)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
__shared_ptr(std::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
2017-04-21 15:08:51 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2009-11-06 23:15:17 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
__shared_ptr&
|
2011-05-19 00:59:17 +02:00
|
|
|
operator=(__shared_ptr&& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
__shared_ptr(std::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<class _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(__shared_ptr<_Yp, _Lp>&& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
__shared_ptr(std::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Del>
|
|
|
|
_UniqAssignable<_Yp, _Del>
|
|
|
|
operator=(unique_ptr<_Yp, _Del>&& __r)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
__shared_ptr(std::move(__r)).swap(*this);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
reset() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ __shared_ptr().swap(*this); }
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_SafeConv<_Yp>
|
|
|
|
reset(_Yp* __p) // _Yp must be complete.
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
// Catch self-reset errors.
|
Enable lightweight checks with _GLIBCXX_ASSERTIONS.
* doc/xml/manual/using.xml (_GLIBCXX_ASSERTIONS): Document.
* doc/html/manual/using_macros.html: Regenerate.
* include/bits/c++config: Define _GLIBCXX_ASSERTIONS when
_GLIBCXX_DEBUG is defined. Disable std::string extern templates when
(_GLIBCXX_EXTERN_TEMPLATE, __glibcxx_assert): Depend on
_GLIBCXX_ASSERTIONS instead of _GLIBCXX_DEBUG.
* include/debug/debug.h [!_GLIBCXX_DEBUG]: Define
__glibcxx_requires_non_empty_range and __glibcxx_requires_nonempty.
* include/backward/auto_ptr.h (auto_ptr::operator*,
auto_ptr::operator->): Replace _GLIBCXX_DEBUG_ASSERT with
__glibcxx_assert.
* include/bits/basic_string.h (basic_string::operator[],
basic_string::front, basic_string::back, basic_string::pop_back):
Likewise.
* include/bits/random.h
(uniform_int_distribution::param_type::param_type,
uniform_real_distribution::param_type::param_type,
normal_distribution::param_type::param_type,
gamma_distribution::param_type::param_type,
bernoulli_distribution::param_type::param_type,
binomial_distribution::param_type::param_type,
geometric_distribution::param_type::param_type,
negative_binomial_distribution::param_type::param_type,
poisson_distribution::param_type::param_type,
exponential_distribution::param_type::param_type): Likewise.
* include/bits/regex.h (match_results::operator[],
match_results::prefix, match_results::suffix): Likewise.
* include/bits/regex.tcc (format, regex_iterator::operator++):
Likewise.
* include/bits/regex_automaton.tcc (_StateSeq::_M_clone): Likewise.
* include/bits/regex_compiler.tcc (_Compiler::_Compiler,
_Compiler::_M_insert_character_class_matcher): Likewise.
* include/bits/regex_executor.tcc (_Executor::_M_dfs): Likewise.
* include/bits/regex_scanner.tcc (_Scanner::_M_advance,
_Scanner::_M_scan_normal): Likewise.
* include/bits/shared_ptr_base.h (__shared_ptr::_M_reset,
__shared_ptr::operator*): Likewise.
* include/bits/stl_iterator_base_funcs.h (__advance): Likewise.
* include/bits/unique_ptr.h (unique_ptr::operator*,
unique_ptr::operator[]): Likewise.
* include/experimental/fs_path.h (path::path(string_type, _Type),
path::iterator::operator++, path::iterator::operator--,
path::iterator::operator*): Likewise.
* include/experimental/string_view (basic_string_view::operator[],
basic_string_view::front, basic_string_view::back,
basic_string_view::remove_prefix): Likewise.
* include/ext/random (beta_distribution::param_type::param_type,
normal_mv_distribution::param_type::param_type,
rice_distribution::param_type::param_type,
pareto_distribution::param_type::param_type,
k_distribution::param_type::param_type,
arcsine_distribution::param_type::param_type,
hoyt_distribution::param_type::param_type,
triangular_distribution::param_type::param_type,
von_mises_distribution::param_type::param_type,
hypergeometric_distribution::param_type::param_type,
logistic_distribution::param_type::param_type): Likewise.
* include/ext/vstring.h (__versa_string::operator[]): Likewise.
* include/std/complex (polar): Likewise.
* include/std/mutex [!_GTHREAD_USE_MUTEX_TIMEDLOCK]
(timed_mutex::~timed_mutex, timed_mutex::unlock,
(recursive_timed_mutex::~timed_mutex, recursive_timed_mutex::unlock):
Likewise.
* include/std/shared_mutex [!PTHREAD_RWLOCK_INITIALIZER]
(__shared_mutex_pthread::__shared_mutex_pthread,
__shared_mutex_pthread::~__shared_mutex_pthread): Likewise.
(__shared_mutex_pthread::lock, __shared_mutex_pthread::try_lock,
__shared_mutex_pthread::unlock, __shared_mutex_pthread::lock_shared,
__shared_mutex_pthread::try_lock_shared): Likewise.
(__shared_mutex_cv::~__shared_mutex_cv, __shared_mutex_cv::unlock,
__shared_mutex_cv::unlock_shared): Likewise.
(shared_timed_mutex::try_lock_until,
shared_timed_mutex::try_lock_shared_until): Likewise.
* include/std/valarray (valarray::valarray(const _Tp*, size_t),
valarray::operator=, valarray::sum, valarray::min, valarray::max,
_DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT, _DEFINE_BINARY_OPERATOR):
Likewise.
From-SVN: r227595
2015-09-09 19:12:47 +02:00
|
|
|
__glibcxx_assert(__p == 0 || __p != _M_ptr);
|
2009-11-06 23:15:17 +01:00
|
|
|
__shared_ptr(__p).swap(*this);
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Deleter>
|
|
|
|
_SafeConv<_Yp>
|
|
|
|
reset(_Yp* __p, _Deleter __d)
|
2017-06-09 15:20:37 +02:00
|
|
|
{ __shared_ptr(__p, std::move(__d)).swap(*this); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Deleter, typename _Alloc>
|
|
|
|
_SafeConv<_Yp>
|
|
|
|
reset(_Yp* __p, _Deleter __d, _Alloc __a)
|
2017-06-09 15:20:37 +02:00
|
|
|
{ __shared_ptr(__p, std::move(__d), std::move(__a)).swap(*this); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/// Return the stored pointer.
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
element_type*
|
2011-05-19 00:59:17 +02:00
|
|
|
get() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_ptr; }
|
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/// Return true if the stored pointer is not null.
|
2009-11-06 23:15:17 +01:00
|
|
|
explicit operator bool() const // never throws
|
|
|
|
{ return _M_ptr == 0 ? false : true; }
|
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/// Return true if use_count() == 1.
|
2009-11-06 23:15:17 +01:00
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
unique() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_unique(); }
|
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/// If *this owns a pointer, return the number of owners, otherwise zero.
|
2009-11-06 23:15:17 +01:00
|
|
|
long
|
2011-05-19 00:59:17 +02:00
|
|
|
use_count() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_get_use_count(); }
|
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/// Exchange both the owned pointer and the stored pointer.
|
2009-11-06 23:15:17 +01:00
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
swap(__shared_ptr<_Tp, _Lp>& __other) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
std::swap(_M_ptr, __other._M_ptr);
|
|
|
|
_M_refcount._M_swap(__other._M_refcount);
|
|
|
|
}
|
|
|
|
|
2019-05-10 23:41:11 +02:00
|
|
|
/** @brief Define an ordering based on ownership.
|
|
|
|
*
|
|
|
|
* This function defines a strict weak ordering between two shared_ptr
|
|
|
|
* or weak_ptr objects, such that one object is less than the other
|
|
|
|
* unless they share ownership of the same pointer, or are both empty.
|
|
|
|
* @{
|
|
|
|
*/
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp1>
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
owner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_less(__rhs._M_refcount); }
|
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
owner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_less(__rhs._M_refcount); }
|
2019-05-10 23:41:11 +02:00
|
|
|
// @}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// This constructor is non-standard, it is used by allocate_shared.
|
|
|
|
template<typename _Alloc, typename... _Args>
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
__shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args)
|
|
|
|
: _M_ptr(), _M_refcount(_M_ptr, __tag, std::forward<_Args>(__args)...)
|
|
|
|
{ _M_enable_shared_from_this_with(_M_ptr); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
template<typename _Tp1, _Lock_policy _Lp1, typename _Alloc,
|
|
|
|
typename... _Args>
|
|
|
|
friend __shared_ptr<_Tp1, _Lp1>
|
shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter, const _Alloc&), [...]): Take the allocator by value, per N3225.
2010-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter,
const _Alloc&), shared_ptr(nullptr_t, _Deleter, const _Alloc&)): Take
the allocator by value, per N3225.
(shared_ptr<>::shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
allocate_shared(_Alloc, _Args&&...): Viceversa, take the allocator
by const lvalue ref.
* include/bits/shared_ptr_base.h (__shared_count<>::
__shared_count(_Sp_make_shared_tag, _Tp*, _Alloc, _Args&&...),
__shared_ptr<>::__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
__allocate_shared(_Alloc, _Args&&...)): Likewise.
(__shared_ptr<>::__shared_ptr(_Tp1*, _Deleter, const _Alloc&),
__shared_ptr(nullptr_t, _Deleter, const _Alloc&), reset(_Tp1*,
_Deleter, const _Alloc&)): Take the allocator by value.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
From-SVN: r167510
2010-12-06 19:37:00 +01:00
|
|
|
__allocate_shared(const _Alloc& __a, _Args&&... __args);
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2014-01-28 11:23:27 +01:00
|
|
|
// This constructor is used by __weak_ptr::lock() and
|
|
|
|
// shared_ptr::shared_ptr(const weak_ptr&, std::nothrow_t).
|
|
|
|
__shared_ptr(const __weak_ptr<_Tp, _Lp>& __r, std::nothrow_t)
|
|
|
|
: _M_refcount(__r._M_refcount, std::nothrow)
|
|
|
|
{
|
|
|
|
_M_ptr = _M_refcount._M_get_use_count() ? __r._M_ptr : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class __weak_ptr<_Tp, _Lp>;
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
private:
|
2016-10-19 22:13:14 +02:00
|
|
|
|
|
|
|
template<typename _Yp>
|
|
|
|
using __esft_base_t = decltype(__enable_shared_from_this_base(
|
|
|
|
std::declval<const __shared_count<_Lp>&>(),
|
|
|
|
std::declval<_Yp*>()));
|
|
|
|
|
|
|
|
// Detect an accessible and unambiguous enable_shared_from_this base.
|
|
|
|
template<typename _Yp, typename = void>
|
|
|
|
struct __has_esft_base
|
|
|
|
: false_type { };
|
|
|
|
|
|
|
|
template<typename _Yp>
|
|
|
|
struct __has_esft_base<_Yp, __void_t<__esft_base_t<_Yp>>>
|
2016-11-13 23:57:45 +01:00
|
|
|
: __not_<is_array<_Tp>> { }; // No enable shared_from_this for arrays
|
2016-10-19 22:13:14 +02:00
|
|
|
|
2017-03-28 09:35:04 +02:00
|
|
|
template<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>
|
|
|
|
typename enable_if<__has_esft_base<_Yp2>::value>::type
|
|
|
|
_M_enable_shared_from_this_with(_Yp* __p) noexcept
|
2016-10-19 22:13:14 +02:00
|
|
|
{
|
|
|
|
if (auto __base = __enable_shared_from_this_base(_M_refcount, __p))
|
2017-03-28 09:35:04 +02:00
|
|
|
__base->_M_weak_assign(const_cast<_Yp2*>(__p), _M_refcount);
|
2016-10-19 22:13:14 +02:00
|
|
|
}
|
|
|
|
|
2017-03-28 09:35:04 +02:00
|
|
|
template<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>
|
|
|
|
typename enable_if<!__has_esft_base<_Yp2>::value>::type
|
|
|
|
_M_enable_shared_from_this_with(_Yp*) noexcept
|
2016-10-19 22:13:14 +02:00
|
|
|
{ }
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
void*
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_get_deleter(const std::type_info& __ti) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_get_deleter(__ti); }
|
|
|
|
|
|
|
|
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
|
|
|
|
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
|
|
|
|
|
|
|
|
template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
|
2011-05-19 00:59:17 +02:00
|
|
|
friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept;
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2017-06-16 17:20:14 +02:00
|
|
|
template<typename _Del, typename _Tp1>
|
|
|
|
friend _Del* get_deleter(const shared_ptr<_Tp1>&) noexcept;
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
element_type* _M_ptr; // Contained pointer.
|
2009-11-06 23:15:17 +01:00
|
|
|
__shared_count<_Lp> _M_refcount; // Reference counter.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-10 00:45:20 +02:00
|
|
|
// 20.7.2.2.7 shared_ptr comparisons
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator==(const __shared_ptr<_Tp1, _Lp>& __a,
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
const __shared_ptr<_Tp2, _Lp>& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __a.get() == __b.get(); }
|
|
|
|
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
operator==(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
|
|
|
{ return !__a; }
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
operator==(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
|
|
|
{ return !__a; }
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator!=(const __shared_ptr<_Tp1, _Lp>& __a,
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
const __shared_ptr<_Tp2, _Lp>& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __a.get() != __b.get(); }
|
|
|
|
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
operator!=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
|
|
|
{ return (bool)__a; }
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
operator!=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
|
|
|
{ return (bool)__a; }
|
re PR libstdc++/42925 ([GB 99] Not possible to compare unique_ptr with 0)
2010-08-11 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/42925
* include/bits/unique_ptr.h (operator==(const unique_ptr<>&,
nullptr_t), operator==(nullptr_t, const unique_ptr<>&),
operator!=(const unique_ptr<>&, nullptr_t),
operator!=(nullptr_t, const unique_ptr<>&)): Add.
* include/bits/shared_ptr_base.h (operator==(const __shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const __shared_ptr<>&),
operator!=(const __shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const __shared_ptr<>&)): Likewise.
* include/bits/shared_ptr.h (operator==(const shared_ptr<>&,
nullptr_t), operator==(nullptr_t, const shared_ptr<>&),
operator!=(const shared_ptr<>&, nullptr_t),
operator!=(nullptr_t, const shared_ptr<>&)): Likewise.
* testsuite/20_util/unique_ptr/comparison/42925.cc: New.
* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust
dg-error line numbers.
From-SVN: r163094
2010-08-11 10:49:47 +02:00
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Tp, typename _Up, _Lock_policy _Lp>
|
2009-11-06 23:15:17 +01:00
|
|
|
inline bool
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
operator<(const __shared_ptr<_Tp, _Lp>& __a,
|
|
|
|
const __shared_ptr<_Up, _Lp>& __b) noexcept
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
{
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
using _Tp_elt = typename __shared_ptr<_Tp, _Lp>::element_type;
|
|
|
|
using _Up_elt = typename __shared_ptr<_Up, _Lp>::element_type;
|
|
|
|
using _Vp = typename common_type<_Tp_elt*, _Up_elt*>::type;
|
|
|
|
return less<_Vp>()(__a.get(), __b.get());
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator<(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{
|
|
|
|
using _Tp_elt = typename __shared_ptr<_Tp, _Lp>::element_type;
|
|
|
|
return less<_Tp_elt*>()(__a.get(), nullptr);
|
|
|
|
}
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator<(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{
|
|
|
|
using _Tp_elt = typename __shared_ptr<_Tp, _Lp>::element_type;
|
|
|
|
return less<_Tp_elt*>()(nullptr, __a.get());
|
|
|
|
}
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
|
|
|
|
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator<=(const __shared_ptr<_Tp1, _Lp>& __a,
|
|
|
|
const __shared_ptr<_Tp2, _Lp>& __b) noexcept
|
|
|
|
{ return !(__b < __a); }
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator<=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
|
|
|
{ return !(nullptr < __a); }
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator<=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
|
|
|
{ return !(__a < nullptr); }
|
|
|
|
|
|
|
|
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>(const __shared_ptr<_Tp1, _Lp>& __a,
|
|
|
|
const __shared_ptr<_Tp2, _Lp>& __b) noexcept
|
|
|
|
{ return (__b < __a); }
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{ return nullptr < __a; }
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{ return __a < nullptr; }
|
shared_ptr.h (operator>, [...]): Add, per DR 1401.
2011-03-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (operator>, operator<=, operator>=): Add,
per DR 1401.
(operator==, operator!=, operator<): Fix per the letter of DR 1401.
* include/bits/shared_ptr_base.h: Likewise for __shared_ptr.
* include/bits/unique_ptr.h (operator==, operator!=, operator<,
operator<=, operator>, operator>=): Fix per the letter of DR 1401.
* testsuite/20_util/shared_ptr/comparison/dr1401.cc: New.
* testsuite/20_util/unique_ptr/comparison/dr1401.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust.
From-SVN: r171293
2011-03-22 16:15:03 +01:00
|
|
|
|
|
|
|
template<typename _Tp1, typename _Tp2, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>=(const __shared_ptr<_Tp1, _Lp>& __a,
|
|
|
|
const __shared_ptr<_Tp2, _Lp>& __b) noexcept
|
|
|
|
{ return !(__a < __b); }
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>=(const __shared_ptr<_Tp, _Lp>& __a, nullptr_t) noexcept
|
|
|
|
{ return !(__a < nullptr); }
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline bool
|
|
|
|
operator>=(nullptr_t, const __shared_ptr<_Tp, _Lp>& __a) noexcept
|
|
|
|
{ return !(nullptr < __a); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2013-05-18 22:18:55 +02:00
|
|
|
// 20.7.2.2.8 shared_ptr specialized algorithms.
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline void
|
2011-05-19 00:59:17 +02:00
|
|
|
swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ __a.swap(__b); }
|
|
|
|
|
2013-05-18 22:18:55 +02:00
|
|
|
// 20.7.2.2.9 shared_ptr casts
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// The seemingly equivalent code:
|
|
|
|
// shared_ptr<_Tp, _Lp>(static_cast<_Tp*>(__r.get()))
|
|
|
|
// will eventually result in undefined behaviour, attempting to
|
|
|
|
// delete the same object twice.
|
|
|
|
/// static_pointer_cast
|
|
|
|
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
2011-05-19 00:59:17 +02:00
|
|
|
static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{
|
|
|
|
using _Sp = __shared_ptr<_Tp, _Lp>;
|
|
|
|
return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get()));
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// The seemingly equivalent code:
|
|
|
|
// shared_ptr<_Tp, _Lp>(const_cast<_Tp*>(__r.get()))
|
|
|
|
// will eventually result in undefined behaviour, attempting to
|
|
|
|
// delete the same object twice.
|
|
|
|
/// const_pointer_cast
|
|
|
|
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
2011-05-19 00:59:17 +02:00
|
|
|
const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
{
|
|
|
|
using _Sp = __shared_ptr<_Tp, _Lp>;
|
|
|
|
return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get()));
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// The seemingly equivalent code:
|
|
|
|
// shared_ptr<_Tp, _Lp>(dynamic_cast<_Tp*>(__r.get()))
|
|
|
|
// will eventually result in undefined behaviour, attempting to
|
|
|
|
// delete the same object twice.
|
|
|
|
/// dynamic_pointer_cast
|
|
|
|
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
2011-05-19 00:59:17 +02:00
|
|
|
dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
using _Sp = __shared_ptr<_Tp, _Lp>;
|
|
|
|
if (auto* __p = dynamic_cast<typename _Sp::element_type*>(__r.get()))
|
|
|
|
return _Sp(__r, __p);
|
|
|
|
return _Sp();
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
#if __cplusplus > 201402L
|
|
|
|
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
|
|
|
reinterpret_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
|
|
|
|
{
|
|
|
|
using _Sp = __shared_ptr<_Tp, _Lp>;
|
|
|
|
return _Sp(__r, reinterpret_cast<typename _Sp::element_type*>(__r.get()));
|
|
|
|
}
|
|
|
|
#endif
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
class __weak_ptr
|
|
|
|
{
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename _Res = void>
|
|
|
|
using _Compatible = typename
|
|
|
|
enable_if<__sp_compatible_with<_Yp*, _Tp*>::value, _Res>::type;
|
|
|
|
|
|
|
|
// Constraint for assignment from shared_ptr and weak_ptr:
|
|
|
|
template<typename _Yp>
|
|
|
|
using _Assignable = _Compatible<_Yp, __weak_ptr&>;
|
2014-11-12 20:41:36 +01:00
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
public:
|
2016-11-13 23:57:45 +01:00
|
|
|
using element_type = typename remove_extent<_Tp>::type;
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
constexpr __weak_ptr() noexcept
|
2014-11-12 12:54:08 +01:00
|
|
|
: _M_ptr(nullptr), _M_refcount()
|
2009-11-06 23:15:17 +01:00
|
|
|
{ }
|
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__weak_ptr(const __weak_ptr&) noexcept = default;
|
2014-11-12 12:54:08 +01:00
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
~__weak_ptr() = default;
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
// The "obvious" converting constructor implementation:
|
|
|
|
//
|
|
|
|
// template<typename _Tp1>
|
|
|
|
// __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
|
|
|
|
// : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
|
|
|
|
// { }
|
|
|
|
//
|
|
|
|
// has a serious problem.
|
|
|
|
//
|
|
|
|
// __r._M_ptr may already have been invalidated. The _M_ptr(__r._M_ptr)
|
|
|
|
// conversion may require access to *__r._M_ptr (virtual inheritance).
|
|
|
|
//
|
|
|
|
// It is not possible to avoid spurious access violations since
|
|
|
|
// in multithreaded programs __r._M_ptr may be invalidated at any point.
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__weak_ptr(const __weak_ptr<_Yp, _Lp>& __r) noexcept
|
2011-05-19 00:59:17 +02:00
|
|
|
: _M_refcount(__r._M_refcount)
|
2010-08-10 18:54:09 +02:00
|
|
|
{ _M_ptr = __r.lock().get(); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__weak_ptr(const __shared_ptr<_Yp, _Lp>& __r) noexcept
|
2011-05-19 00:59:17 +02:00
|
|
|
: _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
|
2010-08-10 18:54:09 +02:00
|
|
|
{ }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_ptr(__weak_ptr&& __r) noexcept
|
|
|
|
: _M_ptr(__r._M_ptr), _M_refcount(std::move(__r._M_refcount))
|
|
|
|
{ __r._M_ptr = nullptr; }
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp, typename = _Compatible<_Yp>>
|
|
|
|
__weak_ptr(__weak_ptr<_Yp, _Lp>&& __r) noexcept
|
2014-11-12 12:54:08 +01:00
|
|
|
: _M_ptr(__r.lock().get()), _M_refcount(std::move(__r._M_refcount))
|
|
|
|
{ __r._M_ptr = nullptr; }
|
|
|
|
|
|
|
|
__weak_ptr&
|
|
|
|
operator=(const __weak_ptr& __r) noexcept = default;
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(const __weak_ptr<_Yp, _Lp>& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_M_ptr = __r.lock().get();
|
|
|
|
_M_refcount = __r._M_refcount;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(const __shared_ptr<_Yp, _Lp>& __r) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
_M_ptr = __r._M_ptr;
|
|
|
|
_M_refcount = __r._M_refcount;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:54:08 +01:00
|
|
|
__weak_ptr&
|
|
|
|
operator=(__weak_ptr&& __r) noexcept
|
|
|
|
{
|
|
|
|
_M_ptr = __r._M_ptr;
|
|
|
|
_M_refcount = std::move(__r._M_refcount);
|
|
|
|
__r._M_ptr = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
template<typename _Yp>
|
|
|
|
_Assignable<_Yp>
|
|
|
|
operator=(__weak_ptr<_Yp, _Lp>&& __r) noexcept
|
2014-11-12 12:54:08 +01:00
|
|
|
{
|
|
|
|
_M_ptr = __r.lock().get();
|
|
|
|
_M_refcount = std::move(__r._M_refcount);
|
|
|
|
__r._M_ptr = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
__shared_ptr<_Tp, _Lp>
|
2011-05-19 00:59:17 +02:00
|
|
|
lock() const noexcept
|
2014-01-28 11:23:27 +01:00
|
|
|
{ return __shared_ptr<element_type, _Lp>(*this, std::nothrow); }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
long
|
2011-05-19 00:59:17 +02:00
|
|
|
use_count() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_get_use_count(); }
|
|
|
|
|
|
|
|
bool
|
2011-05-19 00:59:17 +02:00
|
|
|
expired() const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_get_use_count() == 0; }
|
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
owner_before(const __shared_ptr<_Tp1, _Lp>& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_less(__rhs._M_refcount); }
|
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
owner_before(const __weak_ptr<_Tp1, _Lp>& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return _M_refcount._M_less(__rhs._M_refcount); }
|
|
|
|
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
reset() noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ __weak_ptr().swap(*this); }
|
|
|
|
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
swap(__weak_ptr& __s) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
|
|
|
std::swap(_M_ptr, __s._M_ptr);
|
|
|
|
_M_refcount._M_swap(__s._M_refcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Used by __enable_shared_from_this.
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
2015-08-26 23:27:00 +02:00
|
|
|
if (use_count() == 0)
|
|
|
|
{
|
|
|
|
_M_ptr = __ptr;
|
|
|
|
_M_refcount = __refcount;
|
|
|
|
}
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
|
|
|
|
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
|
|
|
|
friend class __enable_shared_from_this<_Tp, _Lp>;
|
|
|
|
friend class enable_shared_from_this<_Tp>;
|
|
|
|
|
Prepare shared_ptr for array support
* include/backward/auto_ptr.h (__shared_ptr(auto_ptr&&))
(shared_ptr(auto_ptr&&)): Adjust template parameter lists.
* include/bits/shared_ptr.h (__sp_compatible_with)
(__sp_is_constructible): New helper traits for shared_ptr.
(shared_ptr::_Convertible): Replace with _Constructible.
(shared_ptr::_Constructible, shared_ptr::_Assignable): Forward checks
to base class.
(shared_ptr::shared_ptr, shared_ptr::operator=): Constrain template
with _Constructible and _Assignable.
(shared_ptr::shared_ptr(shared_ptr<_Tp1>, _Tp*)): Use element_type
instead of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Constructible.
(weak_ptr::_Constructible, weak_ptr::_Assignable): Forward checks
to base class.
(weak_ptr::weak_ptr, weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
* include/bits/shared_ptr_base.h (__shared_ptr::_Convertible): Replace
with _Compatible.
(__shared_ptr::_SafeConv): New constraint for incoming raw pointers.
(__shared_ptr::_Compatible): New constraint for converting from
other types of shared_ptr and weak_ptr.
(__shared_ptr::_Assignable): Define in terms of _Compatible.
(__shared_ptr::_UniqCompatible, __shared_ptr::_UniqAssignable): New
constraints for converting from unique_ptr.
(__shared_ptr::__shared_ptr, __shared_ptr::operator=): Constrain
template with _SaveConf, _Compatible and _Assignable. Remove
__glibcxx_function_requires concept checks. Add static assertion for
deleter expression being well-formed.
(__shared_ptr::__shared_ptr(__shared_ptr<_Tp1>, _Tp*))
(__shared_ptr::operator*, __shared_ptr::operator->)
(__shared_ptr::get, __shared_ptr::_M_ptr): Use element_type instead
of _Tp.
(operator<): Likewise.
(operator>): Define in terms of operator<.
(static_pointer_cast, const_pointer_cast, dynamic_pointer_cast): Use
element_type instead of _Tp.
(reinterpret_pointer_cast): Define for C++17.
(weak_ptr::_Convertible): Replace with _Compatible.
(weak_ptr::_Compatible, weak_ptr::_Assignable): New constraints for
conversions from other types of weak_ptr and shared_ptr.
(__weak_ptr::__weak_ptr, __weak_ptr::operator=): Constrain templates
with _Constructible and _Assignable.
(__weak_ptr::_M_ptr): Use element_type instead of _Tp.
* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Adjust
dg-error pattern.
* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Test conversions.
* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/casts/reinterpret.cc: New test.
From-SVN: r241373
2016-10-20 14:07:45 +02:00
|
|
|
element_type* _M_ptr; // Contained pointer.
|
2009-11-06 23:15:17 +01:00
|
|
|
__weak_count<_Lp> _M_refcount; // Reference counter.
|
|
|
|
};
|
|
|
|
|
2012-08-10 00:45:20 +02:00
|
|
|
// 20.7.2.3.6 weak_ptr specialized algorithms.
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
inline void
|
2011-05-19 00:59:17 +02:00
|
|
|
swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ __a.swap(__b); }
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Tp1>
|
|
|
|
struct _Sp_owner_less : public binary_function<_Tp, _Tp, bool>
|
|
|
|
{
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
operator()(const _Tp& __lhs, const _Tp& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __lhs.owner_before(__rhs); }
|
|
|
|
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
operator()(const _Tp& __lhs, const _Tp1& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __lhs.owner_before(__rhs); }
|
|
|
|
|
|
|
|
bool
|
2017-06-05 11:33:19 +02:00
|
|
|
operator()(const _Tp1& __lhs, const _Tp& __rhs) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return __lhs.owner_before(__rhs); }
|
|
|
|
};
|
|
|
|
|
2016-08-03 20:11:18 +02:00
|
|
|
template<>
|
|
|
|
struct _Sp_owner_less<void, void>
|
|
|
|
{
|
|
|
|
template<typename _Tp, typename _Up>
|
|
|
|
auto
|
2017-06-05 11:33:19 +02:00
|
|
|
operator()(const _Tp& __lhs, const _Up& __rhs) const noexcept
|
2016-08-03 20:11:18 +02:00
|
|
|
-> decltype(__lhs.owner_before(__rhs))
|
|
|
|
{ return __lhs.owner_before(__rhs); }
|
|
|
|
|
|
|
|
using is_transparent = void;
|
|
|
|
};
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
struct owner_less<__shared_ptr<_Tp, _Lp>>
|
|
|
|
: public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
struct owner_less<__weak_ptr<_Tp, _Lp>>
|
|
|
|
: public _Sp_owner_less<__weak_ptr<_Tp, _Lp>, __shared_ptr<_Tp, _Lp>>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
class __enable_shared_from_this
|
|
|
|
{
|
|
|
|
protected:
|
2011-05-19 00:59:17 +02:00
|
|
|
constexpr __enable_shared_from_this() noexcept { }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2011-05-19 00:59:17 +02:00
|
|
|
__enable_shared_from_this(const __enable_shared_from_this&) noexcept { }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
__enable_shared_from_this&
|
2011-05-19 00:59:17 +02:00
|
|
|
operator=(const __enable_shared_from_this&) noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ return *this; }
|
|
|
|
|
|
|
|
~__enable_shared_from_this() { }
|
|
|
|
|
|
|
|
public:
|
|
|
|
__shared_ptr<_Tp, _Lp>
|
|
|
|
shared_from_this()
|
|
|
|
{ return __shared_ptr<_Tp, _Lp>(this->_M_weak_this); }
|
|
|
|
|
|
|
|
__shared_ptr<const _Tp, _Lp>
|
|
|
|
shared_from_this() const
|
|
|
|
{ return __shared_ptr<const _Tp, _Lp>(this->_M_weak_this); }
|
|
|
|
|
2016-08-04 14:33:10 +02:00
|
|
|
#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
|
|
|
|
__weak_ptr<_Tp, _Lp>
|
2016-10-10 13:44:05 +02:00
|
|
|
weak_from_this() noexcept
|
2016-08-04 14:33:10 +02:00
|
|
|
{ return this->_M_weak_this; }
|
|
|
|
|
|
|
|
__weak_ptr<const _Tp, _Lp>
|
2016-10-10 13:44:05 +02:00
|
|
|
weak_from_this() const noexcept
|
2016-08-04 14:33:10 +02:00
|
|
|
{ return this->_M_weak_this; }
|
|
|
|
#endif
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
private:
|
|
|
|
template<typename _Tp1>
|
|
|
|
void
|
2011-05-19 00:59:17 +02:00
|
|
|
_M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const noexcept
|
2009-11-06 23:15:17 +01:00
|
|
|
{ _M_weak_this._M_assign(__p, __n); }
|
|
|
|
|
2017-01-20 01:07:14 +01:00
|
|
|
friend const __enable_shared_from_this*
|
2016-10-19 22:13:14 +02:00
|
|
|
__enable_shared_from_this_base(const __shared_count<_Lp>&,
|
|
|
|
const __enable_shared_from_this* __p)
|
|
|
|
{ return __p; }
|
2009-11-06 23:15:17 +01:00
|
|
|
|
2017-01-20 01:07:14 +01:00
|
|
|
template<typename, _Lock_policy>
|
|
|
|
friend class __shared_ptr;
|
|
|
|
|
2009-11-06 23:15:17 +01:00
|
|
|
mutable __weak_ptr<_Tp, _Lp> _M_weak_this;
|
|
|
|
};
|
|
|
|
|
PR libstdc++/67843 set shared_ptr lock policy at build-time
This resolves a longstanding issue where the lock policy for shared_ptr
reference counting depends on compilation options when the header is
included, so that different -march options can cause ABI changes. For
example, objects compiled with -march=armv7 will use atomics to
synchronize reference counts, and objects compiled with -march=armv5t
will use a mutex. That means the shared_ptr control block will have a
different layout in different objects, causing ODR violations and
undefined behaviour. This was the root cause of PR libstdc++/42734 as
well as PR libstdc++/67843.
The solution is to decide on the lock policy at build time, when
libstdc++ is configured. The configure script checks for the
availability of the necessary atomic built-ins for the target and fixes
that choice permanently. Different -march flags used to compile user
code will not cause changes to the lock policy. This results in an ABI
change for certain compilations, but only where there was already an ABI
incompatibility between the libstdc++.so library and objects built with
an incompatible -march option. In general, this means a more stable ABI
that isn't silently altered when -march flags make addition atomic ops
available.
To force a target to use "atomic" or "mutex" the new configure option
--with-libstdcxx-lock-policy can be used.
In order to turn ODR violations into linker errors, the uses of
shared_ptr in filesystem directory iterators have been replaced
with __shared_ptr, and explicit instantiations are declared. This
ensures that object files using those types cannot link to libstdc++
libs unless they use the same lock policy.
PR libstdc++/67843
* acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add new macro
that defines _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_ENABLE_LOCK_POLICY.
* doc/xml/manual/configure.xml: Document new configure option.
* include/bits/fs_dir.h (directory_iterator): Use __shared_ptr
instead of shared_ptr.
(recursive_directory_iterator): Likewise.
(__shared_ptr<_Dir>): Add explicit instantiation declaration.
(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
* include/bits/shared_ptr_base.h (__allocate_shared, __make_shared):
Add default template argument for _Lock_policy template parameter.
* include/ext/concurrence.h (__default_lock_policy): Check macro
_GLIBCXX_HAVE_ATOMIC_LOCK_POLICY instead of checking if the current
target supports the builtins for compare-and-swap.
* src/filesystem/std-dir.cc (__shared_ptr<_Dir>): Add explicit
instantiation definition.
(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
(directory_iterator, recursive_directory_iterator): Use __make_shared
instead of make_shared.
From-SVN: r266533
2018-11-28 00:25:56 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy,
|
|
|
|
typename _Alloc, typename... _Args>
|
2009-11-06 23:15:17 +01:00
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter, const _Alloc&), [...]): Take the allocator by value, per N3225.
2010-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter,
const _Alloc&), shared_ptr(nullptr_t, _Deleter, const _Alloc&)): Take
the allocator by value, per N3225.
(shared_ptr<>::shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
allocate_shared(_Alloc, _Args&&...): Viceversa, take the allocator
by const lvalue ref.
* include/bits/shared_ptr_base.h (__shared_count<>::
__shared_count(_Sp_make_shared_tag, _Tp*, _Alloc, _Args&&...),
__shared_ptr<>::__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
__allocate_shared(_Alloc, _Args&&...)): Likewise.
(__shared_ptr<>::__shared_ptr(_Tp1*, _Deleter, const _Alloc&),
__shared_ptr(nullptr_t, _Deleter, const _Alloc&), reset(_Tp1*,
_Deleter, const _Alloc&)): Take the allocator by value.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
From-SVN: r167510
2010-12-06 19:37:00 +01:00
|
|
|
__allocate_shared(const _Alloc& __a, _Args&&... __args)
|
2009-11-06 23:15:17 +01:00
|
|
|
{
|
PR libstdc++/88782 avoid ODR problems in std::make_shared
The old version of _Sp_counted_ptr_inplace::_M_get_deleter (up to GCC
8.2.0) expects to be passed a real std::typeinfo object, so mixing that
with the new definition of the __shared_ptr constructor (which always
passes the fake tag) leads to accessing the fake object as a real
std::typeinfo. Instead of trying to make it safe to mix the old and new
definitions, just stop using that function. By passing a reference to
__shared_ptr::_M_ptr to the __shared_count constructor it can be set
directly, without needing to obtain the pointer via the _M_get_deleter
back-channel. This avoids a virtual dispatch (which fixes PR 87514).
This means that code built against new libstdc++ headers doesn't use
_M_get_deleter at all, and so make_shared works the same whether RTTI is
enabled or not.
Also change _M_get_deleter so that it checks for a real type_info object
even when RTTI is disabled, by calling a library function. Unless
libstdc++ itself is built without RTTI that library function will be
able to test if it's the right type_info. This means the new definition
of _M_get_deleter can handle both the fake type_info tag and a real
type_info object, even if built without RTTI.
If linking to objects built against older versions of libstdc++ then if
all objects use -frtti or all use -fno-rtti, then the caller of
_M_get_deleter and the definition of _M_get_deleter will be consistent
and it will work. If mixing -frtti with -fno-rtti it can still fail if
the linker picks an old definition of _M_get_deleter and an old
__shared_ptr constructor that are incompatible. In that some or all
objects might need to be recompiled.
PR libstdc++/87514
PR libstdc++/87520
PR libstdc++/88782
* config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export new symbol.
* include/bits/shared_ptr.h
(shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...))
(allocate_shared): Change to use new tag type.
* include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_eq):
Declare new member function.
(_Sp_alloc_shared_tag): Define new type.
(_Sp_counted_ptr_inplace): Declare __shared_count<_Lp> as a friend.
(_Sp_counted_ptr_inplace::_M_get_deleter) [!__cpp_rtti]: Use
_Sp_make_shared_tag::_S_eq to check type_info.
(__shared_count(Ptr, Deleter),__shared_count(Ptr, Deleter, Alloc)):
Constrain to prevent being called with _Sp_alloc_shared_tag.
(__shared_count(_Sp_make_shared_tag, const _Alloc&, Args&&...)):
Replace constructor with ...
(__shared_count(Tp*&, _Sp_alloc_shared_tag<_Alloc>, Args&&...)): Use
reference parameter so address of the new object can be returned to
the caller. Obtain the allocator from the tag type.
(__shared_ptr(_Sp_make_shared_tag, const Alloc&, Args&&...)): Replace
constructor with ...
(__shared_ptr(_Sp_alloc_shared_tag<Alloc>, Args&&...)): Pass _M_ptr
to the __shared_count constructor.
(__allocate_shared): Change to use new tag type.
* src/c++11/shared_ptr.cc (_Sp_make_shared_tag::_S_eq): Define.
From-SVN: r268086
2019-01-18 22:28:48 +01:00
|
|
|
return __shared_ptr<_Tp, _Lp>(_Sp_alloc_shared_tag<_Alloc>{__a},
|
shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter, const _Alloc&), [...]): Take the allocator by value, per N3225.
2010-12-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/shared_ptr.h (shared_ptr<>::shared_ptr(_Tp1*, _Deleter,
const _Alloc&), shared_ptr(nullptr_t, _Deleter, const _Alloc&)): Take
the allocator by value, per N3225.
(shared_ptr<>::shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
allocate_shared(_Alloc, _Args&&...): Viceversa, take the allocator
by const lvalue ref.
* include/bits/shared_ptr_base.h (__shared_count<>::
__shared_count(_Sp_make_shared_tag, _Tp*, _Alloc, _Args&&...),
__shared_ptr<>::__shared_ptr(_Sp_make_shared_tag, _Alloc, _Args&&...),
__allocate_shared(_Alloc, _Args&&...)): Likewise.
(__shared_ptr<>::__shared_ptr(_Tp1*, _Deleter, const _Alloc&),
__shared_ptr(nullptr_t, _Deleter, const _Alloc&), reset(_Tp1*,
_Deleter, const _Alloc&)): Take the allocator by value.
* testsuite/20_util/shared_ptr/cons/43820.cc: Adjust dg-error line
numbers.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
From-SVN: r167510
2010-12-06 19:37:00 +01:00
|
|
|
std::forward<_Args>(__args)...);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
PR libstdc++/67843 set shared_ptr lock policy at build-time
This resolves a longstanding issue where the lock policy for shared_ptr
reference counting depends on compilation options when the header is
included, so that different -march options can cause ABI changes. For
example, objects compiled with -march=armv7 will use atomics to
synchronize reference counts, and objects compiled with -march=armv5t
will use a mutex. That means the shared_ptr control block will have a
different layout in different objects, causing ODR violations and
undefined behaviour. This was the root cause of PR libstdc++/42734 as
well as PR libstdc++/67843.
The solution is to decide on the lock policy at build time, when
libstdc++ is configured. The configure script checks for the
availability of the necessary atomic built-ins for the target and fixes
that choice permanently. Different -march flags used to compile user
code will not cause changes to the lock policy. This results in an ABI
change for certain compilations, but only where there was already an ABI
incompatibility between the libstdc++.so library and objects built with
an incompatible -march option. In general, this means a more stable ABI
that isn't silently altered when -march flags make addition atomic ops
available.
To force a target to use "atomic" or "mutex" the new configure option
--with-libstdcxx-lock-policy can be used.
In order to turn ODR violations into linker errors, the uses of
shared_ptr in filesystem directory iterators have been replaced
with __shared_ptr, and explicit instantiations are declared. This
ensures that object files using those types cannot link to libstdc++
libs unless they use the same lock policy.
PR libstdc++/67843
* acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add new macro
that defines _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_ENABLE_LOCK_POLICY.
* doc/xml/manual/configure.xml: Document new configure option.
* include/bits/fs_dir.h (directory_iterator): Use __shared_ptr
instead of shared_ptr.
(recursive_directory_iterator): Likewise.
(__shared_ptr<_Dir>): Add explicit instantiation declaration.
(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
* include/bits/shared_ptr_base.h (__allocate_shared, __make_shared):
Add default template argument for _Lock_policy template parameter.
* include/ext/concurrence.h (__default_lock_policy): Check macro
_GLIBCXX_HAVE_ATOMIC_LOCK_POLICY instead of checking if the current
target supports the builtins for compare-and-swap.
* src/filesystem/std-dir.cc (__shared_ptr<_Dir>): Add explicit
instantiation definition.
(__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise.
(directory_iterator, recursive_directory_iterator): Use __make_shared
instead of make_shared.
From-SVN: r266533
2018-11-28 00:25:56 +01:00
|
|
|
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy,
|
|
|
|
typename... _Args>
|
2009-11-06 23:15:17 +01:00
|
|
|
inline __shared_ptr<_Tp, _Lp>
|
|
|
|
__make_shared(_Args&&... __args)
|
|
|
|
{
|
|
|
|
typedef typename std::remove_const<_Tp>::type _Tp_nc;
|
2011-07-31 22:28:45 +02:00
|
|
|
return std::__allocate_shared<_Tp, _Lp>(std::allocator<_Tp_nc>(),
|
|
|
|
std::forward<_Args>(__args)...);
|
2009-11-06 23:15:17 +01:00
|
|
|
}
|
|
|
|
|
2010-06-11 18:20:24 +02:00
|
|
|
/// std::hash specialization for __shared_ptr.
|
|
|
|
template<typename _Tp, _Lock_policy _Lp>
|
|
|
|
struct hash<__shared_ptr<_Tp, _Lp>>
|
2011-07-31 22:28:45 +02:00
|
|
|
: public __hash_base<size_t, __shared_ptr<_Tp, _Lp>>
|
2010-06-11 18:20:24 +02:00
|
|
|
{
|
|
|
|
size_t
|
hash-long-double-aux.cc: Rename to...
2011-11-18 Paolo Carlini <paolo.carlini@oracle.com>
* src/hash-long-double-aux.cc: Rename to...
* src/hash-long-double-tr1-aux.cc: ... this.
* src/compatibility-ldbl.cc: Adjust.
* src/hash_tr1.cc: Likewise.
* src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc.
* include/bits/functional_hash.h (hash<_Tp*>::operator(), specs
for integer types, hash<float>::operator(), hash<double>::operator(),
hash<long double>::operator()): Declare noexcept.
* include/debug/bitset (hash<__debug::bitset>::operator()): Likewise.
* include/debug/vector (hash<__debug::vector>::operator()): Likewise.
* include/std/system_error (hash<error_code>::operator()): Likewise.
* include/std/thread (hash<thread::id>::operator()): Likewise.
* include/std/bitset (hash<bitset>::operator()): Likewise.
* include/std/typeindex (hash<type_index>::operator()): Likewise.
* include/profile/bitset (hash<__profile::vector>::operator()):
Likewise.
* include/profile/vector (hash<__profile::vector>::operator()):
Likewise.
* include/ext/vstring.h (hash<__vstring>::operator(),
hash<__wvstring>::operator(), hash<__u16vstring>::operator(),
hash<__u32vstring>::operator()): Likewise.
* include/bits/shared_ptr.h (hash<shared_ptr>::operator()): Likewise.
* include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()):
Likewise.
* include/bits/unique_ptr.h (hash<unique_ptr>::operator()): Likewise.
* include/bits/basic_string.h (hash<string>::operator(),
hash<wstring>::operator(), hash<u16string>::operator(),
hash<u32string>::operator()): Likewise.
* include/bits/vector.tcc (hash<vector>::operator()): Likewise.
* include/bits/stl_bvector.h (hash<vector>::operator()): Likewise.
* libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of
throw().
From-SVN: r181473
2011-11-18 13:37:06 +01:00
|
|
|
operator()(const __shared_ptr<_Tp, _Lp>& __s) const noexcept
|
2016-11-12 04:24:34 +01:00
|
|
|
{
|
|
|
|
return hash<typename __shared_ptr<_Tp, _Lp>::element_type*>()(
|
|
|
|
__s.get());
|
|
|
|
}
|
2010-06-11 18:20:24 +02:00
|
|
|
};
|
|
|
|
|
PR libstdc++/36104 part four
2011-01-30 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/36104 part four
* include/bits/c++config (_GLIBCXX_STD): Remove.
(_GLIBCXX_STD_D, _GLIBCXX_PR): Now _GLIBCXX_STD_C.
(_GLIBCXX_P): Now _GLIBCXX_STD_A.
(_GLIBCXX_NAMESPACE_DEBUG, _GLIBCXX_NAMESPACE_PARALLEL,
_GLIBCXX_NAMESPACE_PROFILE, _GLIBCXX_NAMESPACE_VERSION): Remove.
(_GLIBCXX_INLINE_DEBUG, _GLIBCXX_INLINE_PARALLEL,
_GLIBCXX_INLINE_PROFILE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE(X)): Remove.
(_GLIBCXX_END_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y)): Remove.
(_GLIBCXX_END_NESTED_NAMESPACE): Remove.
(_GLIBCXX_BEGIN_NAMESPACE_ALGO): Add.
(_GLIBCXX_END_NAMESPACE_ALGO): Add.
(_GLIBCXX_BEGIN_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_END_NAMESPACE_CONTAINER): Add.
(_GLIBCXX_BEGIN_NAMESPACE_VERSION): Add.
(_GLIBCXX_END_NAMESPACE_VERSION): Add.
(_GLIBCXX_BEGIN_LDBL_NAMESPACE): To _GLIBCXX_BEGIN_NAMESPACE_LDBL.
(_GLIBCXX_END_LDBL_NAMESPACE): To _GLIBCXX_END_NAMESPACE_LDBL.
(_GLIBCXX_VISIBILITY_ATTR): Revert to _GLIBCXX_VISIBILITY.
* include/*: Use new macros for namespace scope.
* config/*: Same.
* src/*: Same.
* src/Makefile.am (sources): Remove debug_list.cc, add
compatibility-debug_list-2.cc.
(parallel_sources): Remove parallel_list.cc, add
compatibility-parallel_list-2.cc.
(compatibility-parallel_list-2.[o,lo]): New rule.
* src/Makefile.in: Regenerate.
* src/debug_list.cc: Remove.
* src/parallel_list.cc: Remove.
* src/compatibility-list-2.cc: New.
* src/compatibility-debug_list-2.cc: New.
* src/compatibility-parallel_list-2.cc: New.
* doc/doxygen/user.cfg.in: Adjust macros.
* testsuite/20_util/auto_ptr/assign_neg.cc: Adjust line numbers, macros.
* testsuite/20_util/declval/requirements/1_neg.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/forward/c_neg.cc: Same.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Same.
* testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Same.
* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/forward_list/capacity/1.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Same.
* testsuite/23_containers/list/capacity/29134.cc: Same.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/bool/capacity/29134.cc: Same.
* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/25_algorithms/sort/35588.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* testsuite/ext/profile/mutex_extensions_neg.cc: Same.
* testsuite/ext/profile/profiler_algos.cc: Same.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Same.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Same.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
From-SVN: r169421
2011-01-30 23:39:36 +01:00
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
|
|
} // namespace
|
2009-11-06 23:15:17 +01:00
|
|
|
|
|
|
|
#endif // _SHARED_PTR_BASE_H
|