1// { dg-options "-std=gnu++11" }
2// { dg-do compile }
3
4// Copyright (C) 2012-2015 Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library.  This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3.  If not see
19// <http://www.gnu.org/licenses/>.
20
21// 20.7.1 Class template unique_ptr [unique.ptr]
22
23#include <memory>
24
25struct A { virtual ~A() = default; };
26
27struct B : A { };
28
29// Assignment from objects with different cv-qualification
30
31void
32test01()
33{
34  std::unique_ptr<A> upA;
35
36  std::unique_ptr<const A> cA;
37  cA = std::move(upA);
38  std::unique_ptr<volatile A> vA;
39  vA = std::move(upA);
40  std::unique_ptr<const volatile A> cvA;
41  cvA = std::move(upA);
42}
43
44void
45test02()
46{
47  std::unique_ptr<B> upB;
48
49  std::unique_ptr<const A> cA;
50  cA = std::move(upB);
51  std::unique_ptr<volatile A> vA;
52  vA = std::move(upB);
53  std::unique_ptr<const volatile A> cvA;
54  cvA = std::move(upB);
55}
56
57void
58test03()
59{
60  std::unique_ptr<A[]> upA;
61
62  std::unique_ptr<const A[]> cA;
63  cA = std::move(upA);
64  std::unique_ptr<volatile A[]> vA;
65  vA = std::move(upA);
66  std::unique_ptr<const volatile A[]> cvA;
67  cvA = std::move(upA);
68}
69
70struct A_pointer { operator A*() const { return nullptr; } };
71
72template<typename T>
73struct deleter
74{
75  deleter() = default;
76  template<typename U>
77    deleter(const deleter<U>) { }
78  typedef T pointer;
79  void operator()(T) const { }
80};
81
82void
83test04()
84{
85  // Allow conversions from user-defined pointer-like types
86  std::unique_ptr<B[], deleter<A_pointer>> p;
87  std::unique_ptr<A[], deleter<A*>> upA;
88  upA = std::move(p);
89}
90