]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / assign / 48635.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2011-2014 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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/>.
19
20 #include <memory>
21 #include <testsuite_hooks.h>
22
23 struct Deleter
24 {
25 Deleter() = default;
26 Deleter(const Deleter&) = default;
27 Deleter(Deleter&&) = default;
28
29 Deleter&
30 operator=(const Deleter&)
31 {
32 bool test __attribute__((unused)) = true;
33 VERIFY( true );
34 return *this;
35 }
36
37 Deleter&
38 operator=(Deleter&&)
39 {
40 bool test __attribute__((unused)) = true;
41 VERIFY( false );
42 return *this;
43 }
44
45 template<class T>
46 void
47 operator()(T*) const { }
48 };
49
50 struct DDeleter : Deleter { };
51
52 // libstdc++/48635
53 void test01()
54 {
55 Deleter d;
56
57 std::unique_ptr<int, Deleter&> p1(nullptr, d), p2(nullptr, d);
58 p2 = std::move(p1);
59
60 DDeleter dd;
61
62 std::unique_ptr<int, DDeleter&> p1t(nullptr, dd);
63 std::unique_ptr<int, Deleter&> p2t(nullptr, d);
64 p2t = std::move(p1t);
65
66 std::unique_ptr<int[], Deleter&> p1a(nullptr, d), p2a(nullptr, d);
67 p2a = std::move(p1a);
68
69 std::unique_ptr<int[], DDeleter&> p1at(nullptr, dd);
70 std::unique_ptr<int[], Deleter&> p2at(nullptr, d);
71 p2at = std::move(p1at);
72 }
73
74 int main()
75 {
76 test01();
77 return 0;
78 }