]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/assign/cv_qual.cc
re PR c++/59378 (Internal compiler error when using __builtin_shuffle in a template...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / assign / cv_qual.cc
1 // { dg-options "-std=gnu++11" }
2 // { dg-do compile }
3
4 // Copyright (C) 2012-2013 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
25 struct A { virtual ~A() = default; };
26
27 struct B : A { };
28
29 // Assignment from objects with different cv-qualification
30
31 void
32 test01()
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
44 void
45 test02()
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
57 void
58 test03()
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
70 struct A_pointer { operator A*() const { return nullptr; } };
71
72 template<typename T>
73 struct 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
82 void
83 test04()
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 }