]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / cons / cv_qual.cc
CommitLineData
23df8534
JW
1// { dg-options "-std=gnu++11" }
2// { dg-do compile }
3
5624e564 4// Copyright (C) 2012-2015 Free Software Foundation, Inc.
23df8534
JW
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// Construction from objects with different cv-qualification
30
31void
32test01()
33{
34 std::unique_ptr<const A> cA(new A);
35 std::unique_ptr<volatile A> vA(new A);
36 std::unique_ptr<const volatile A> cvA(new A);
37}
38
39void
40test02()
41{
42 std::unique_ptr<const A> cB(new B);
43 std::unique_ptr<volatile A> vB(new B);
44 std::unique_ptr<const volatile A> cvB(new B);
45}
46
47void
48test03()
49{
50 std::unique_ptr<A> upA;
51
52 std::unique_ptr<const A> cA(std::move(upA));
53 std::unique_ptr<volatile A> vA(std::move(upA));
54 std::unique_ptr<const volatile A> cvA(std::move(upA));
55}
56
57void
58test04()
59{
60 std::unique_ptr<B> upB;
61
62 std::unique_ptr<const A> cA(std::move(upB));
63 std::unique_ptr<volatile A> vA(std::move(upB));
64 std::unique_ptr<const volatile A> cvA(std::move(upB));
65}
66
67void
68test05()
69{
70 std::unique_ptr<const A[]> cA(new A[1]);
71 std::unique_ptr<volatile A[]> vA(new A[1]);
72 std::unique_ptr<const volatile A[]> cvA(new A[1]);
73}
74
75void
76test06()
77{
78 std::unique_ptr<A[]> upA;
79
80 std::unique_ptr<const A[]> cA(std::move(upA));
81 std::unique_ptr<volatile A[]> vA(std::move(upA));
82 std::unique_ptr<const volatile A[]> cvA(std::move(upA));
83}
84
85struct A_pointer { operator A*() const { return nullptr; } };
86
87void
88test07()
89{
90 // Allow conversions from user-defined pointer-like types
91 A_pointer p;
92 std::unique_ptr<A[]> upA(p);
93 std::unique_ptr<const A[]> cA(p);
94 std::unique_ptr<volatile A[]> vA(p);
95 std::unique_ptr<const volatile A[]> cvA(p);
96}
97
98template<typename T>
99struct deleter
100{
101 deleter() = default;
102 template<typename U>
103 deleter(const deleter<U>) { }
104 typedef T pointer;
105 void operator()(T) const { }
106};
107
108void
109test08()
110{
111 // Allow conversions from user-defined pointer-like types
112 std::unique_ptr<B[], deleter<A_pointer>> p;
113 std::unique_ptr<A[], deleter<A*>> upA(std::move(p));
114}
115
This page took 0.233179 seconds and 5 git commands to generate.