+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
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; }
/// 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();
}
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.
--- /dev/null
+// 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
+};