gcc/libstdc++-v3/testsuite/20_util/unique_ptr/dr2899.cc
Jonathan Wakely 1b18663e0f LWG 2899 - Make is_move_constructible correct for unique_ptr
* include/bits/unique_ptr.h (__uniq_ptr_impl): Add move constructor,
	move assignment operator.
	(__uniq_ptr_impl::release(), __uniq_ptr_impl::reset(pointer)): Add.
	(__uniq_ptr_data): New class template with conditionally deleted
	special members.
	(unique_ptr, unique_ptr<T[], D>): Change type of data member from
	__uniq_ptr_impl<T, D> to __uniq_ptr_data<T, D>. Define move
	constructor and move assignment operator as defaulted.
	(unique_ptr::release(), unique_ptr<T[], D>::release()): Forward to
	__uniq_ptr_impl::release().
	(unique_ptr::reset(pointer), unique_ptr<T[], D>::reset<U>(U)): Forward
	to __uniq_ptr_impl::reset(pointer).
	* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__):
	Check for new __uniq_ptr_data type.
	* testsuite/20_util/unique_ptr/dr2899.cc: New test.

From-SVN: r271158
2019-05-14 12:17:11 +01:00

54 lines
1.7 KiB
C++

// Copyright (C) 2019 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 Del {
Del() = default;
Del(Del&&) = delete;
void operator()(int*) const;
};
static_assert(!std::is_move_constructible<std::unique_ptr<int, Del>>::value);
static_assert(std::is_move_constructible<std::unique_ptr<int, Del&>>::value);
struct Del2 {
Del2() = default;
Del2(Del2&&) = default;
Del2& operator=(Del2&&) = delete;
Del2& operator=(const Del2&) = default;
void operator()(int*) const;
};
static_assert(!std::is_move_assignable<std::unique_ptr<int, Del2>>::value);
static_assert(std::is_move_assignable<std::unique_ptr<int, Del2&>>::value);
struct Del3 {
Del3() = default;
Del3(Del3&&) = default;
Del3& operator=(Del3&&) = default;
Del3& operator=(const Del3&) = delete;
void operator()(int*) const;
};
static_assert(std::is_move_assignable<std::unique_ptr<int, Del3>>::value);
static_assert(!std::is_move_assignable<std::unique_ptr<int, Del3&>>::value);