Fix location of invocable check for unique_ptr deleter
The deleter only needs to be invocable when the unique_ptr destructor and reset member function are instantiated. In other contexts it might not be possible to pass unique_ptr<T, D>::pointer to the deleter, if that requires a derived-to-base conversion from T* and T is incomplete. * include/bits/unique_ptr.h (__uniq_ptr_impl): Remove static assertion checking invocable condition. (unique_ptr::~unique_ptr, unique_ptr::reset): Restore static assertion here, where types must be complete. Pass pointer to deleter as an rvalue. * testsuite/20_util/unique_ptr/requirements/incomplete.cc: New test. From-SVN: r264399
This commit is contained in:
parent
f96c8666f5
commit
a12c16de52
3 changed files with 48 additions and 4 deletions
|
@ -1,3 +1,12 @@
|
|||
2018-09-18 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/bits/unique_ptr.h (__uniq_ptr_impl): Remove static assertion
|
||||
checking invocable condition.
|
||||
(unique_ptr::~unique_ptr, unique_ptr::reset): Restore static assertion
|
||||
here, where types must be complete. Pass pointer to deleter as an
|
||||
rvalue.
|
||||
* testsuite/20_util/unique_ptr/requirements/incomplete.cc: New test.
|
||||
|
||||
2018-09-13 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* include/std/variant (variant) [__clang__]: Limit workaround to
|
||||
|
|
|
@ -142,8 +142,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
static_assert( !is_rvalue_reference<_Dp>::value,
|
||||
"unique_ptr's deleter type must be a function object type"
|
||||
" or an lvalue reference type" );
|
||||
static_assert( __is_invocable<_Dp&, pointer&>::value,
|
||||
"unique_ptr's deleter must be invocable with a pointer" );
|
||||
|
||||
__uniq_ptr_impl() = default;
|
||||
__uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
|
||||
|
@ -282,9 +280,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
/// Destructor, invokes the deleter if the stored pointer is not null.
|
||||
~unique_ptr() noexcept
|
||||
{
|
||||
static_assert(__is_invocable<deleter_type&, pointer>::value,
|
||||
"unique_ptr's deleter must be invocable with a pointer");
|
||||
auto& __ptr = _M_t._M_ptr();
|
||||
if (__ptr != nullptr)
|
||||
get_deleter()(__ptr);
|
||||
get_deleter()(std::move(__ptr));
|
||||
__ptr = pointer();
|
||||
}
|
||||
|
||||
|
@ -389,10 +389,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
void
|
||||
reset(pointer __p = pointer()) noexcept
|
||||
{
|
||||
static_assert(__is_invocable<deleter_type&, pointer>::value,
|
||||
"unique_ptr's deleter must be invocable with a pointer");
|
||||
using std::swap;
|
||||
swap(_M_t._M_ptr(), __p);
|
||||
if (__p != pointer())
|
||||
get_deleter()(__p);
|
||||
get_deleter()(std::move(__p));
|
||||
}
|
||||
|
||||
/// Exchange the pointer and deleter with another object.
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2018 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct Base; // incomplete
|
||||
|
||||
struct BaseDeleter {
|
||||
void operator()(Base*) const;
|
||||
};
|
||||
|
||||
struct Derived; // incomplete
|
||||
|
||||
struct X {
|
||||
std::unique_ptr<Derived, BaseDeleter> p;
|
||||
~X(); // defined elsewhere, where Derived is complete
|
||||
};
|
Loading…
Add table
Reference in a new issue