]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc
1 // { dg-do compile { target c++11 } }
3 // Copyright (C) 2012-2021 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.7.1 Class template unique_ptr [unique.ptr]
24 struct A
{ virtual ~A() = default; };
28 // Construction from objects with different cv-qualification
33 std::unique_ptr
<const A
> cA(new A
);
34 std::unique_ptr
<volatile A
> vA(new A
);
35 std::unique_ptr
<const volatile A
> cvA(new A
);
41 std::unique_ptr
<const A
> cB(new B
);
42 std::unique_ptr
<volatile A
> vB(new B
);
43 std::unique_ptr
<const volatile A
> cvB(new B
);
49 std::unique_ptr
<A
> upA
;
51 std::unique_ptr
<const A
> cA(std::move(upA
));
52 std::unique_ptr
<volatile A
> vA(std::move(upA
));
53 std::unique_ptr
<const volatile A
> cvA(std::move(upA
));
59 std::unique_ptr
<B
> upB
;
61 std::unique_ptr
<const A
> cA(std::move(upB
));
62 std::unique_ptr
<volatile A
> vA(std::move(upB
));
63 std::unique_ptr
<const volatile A
> cvA(std::move(upB
));
69 std::unique_ptr
<const A
[]> cA(new A
[1]);
70 std::unique_ptr
<volatile A
[]> vA(new A
[1]);
71 std::unique_ptr
<const volatile A
[]> cvA(new A
[1]);
77 std::unique_ptr
<A
[]> upA
;
79 std::unique_ptr
<const A
[]> cA(std::move(upA
));
80 std::unique_ptr
<volatile A
[]> vA(std::move(upA
));
81 std::unique_ptr
<const volatile A
[]> cvA(std::move(upA
));
84 struct A_pointer
{ operator A
*() const { return nullptr; } };
89 // Allow conversions from user-defined pointer-like types
90 // for the single-object version
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 // Allow conversions from user-defined pointer-like types
97 // for the array version when the type is converted explicitly
98 std::unique_ptr
<A
[]> upA2((A
*)p
);
99 std::unique_ptr
<const A
[]> cA2((A
*)p
);
100 std::unique_ptr
<volatile A
[]> vA2((A
*)p
);
101 std::unique_ptr
<const volatile A
[]> cvA2((A
*)p
);