]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
30ffc3cbadf95cba5a8955a230ec9cccc321d0a9
1 // { dg-options "-std=gnu++11" }
4 // Copyright (C) 2012-2013 Free Software Foundation, Inc.
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)
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.
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/>.
21 // 20.7.1 Class template unique_ptr [unique.ptr]
25 struct A
{ virtual ~A() = default; };
29 // Construction from objects with different cv-qualification
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
);
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
);
50 std::unique_ptr
<A
> upA
;
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
));
60 std::unique_ptr
<B
> upB
;
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
));
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]);
78 std::unique_ptr
<A
[]> upA
;
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
));
85 struct A_pointer
{ operator A
*() const { return nullptr; } };
90 // Allow conversions from user-defined pointer-like types
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
);
103 deleter(const deleter
<U
>) { }
105 void operator()(T
) const { }
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
));