Debian Codegraph @

libstdc++-v3/testsuite/20_util/pair/40925.cc

raw
1 // { dg-do compile { target c++11 } }
2
3 // Copyright (C) 2009-2025 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 <utility>
21
22 struct X
23 {
24 explicit X(int, int) { }
25
26 private:
27 X(const X&) = delete;
28 };
29
30 struct move_only
31 {
32 move_only() { }
33 move_only(move_only&&) { }
34
35 private:
36 move_only(const move_only&) = delete;
37 };
38
39 // libstdc++/40925 and LWG 811
40 void test01()
41 {
42 int *ip = 0;
43 int X::*mp = 0;
44
45 std::pair<int*, int*> p1(0, 0);
46 std::pair<int*, int*> p2(ip, 0);
47 std::pair<int*, int*> p3(0, ip);
48 std::pair<int*, int*> p4(ip, ip);
49
50 std::pair<int X::*, int*> p5(0, 0);
51 std::pair<int X::*, int X::*> p6(mp, 0);
52 std::pair<int X::*, int X::*> p7(0, mp);
53 std::pair<int X::*, int X::*> p8(mp, mp);
54
55 // LWG 811 resolution doesn't support move-only types,
56 // so we have to use nullptr here not a literal 0.
57 std::pair<int*, move_only> p9(nullptr, move_only());
58 std::pair<int X::*, move_only> p10(nullptr, move_only());
59 std::pair<move_only, int*> p11(move_only(), nullptr);
60 std::pair<move_only, int X::*> p12(move_only(), nullptr);
61
62 std::pair<int*, move_only> p13(ip, move_only());
63 std::pair<int X::*, move_only> p14(mp, move_only());
64 std::pair<move_only, int*> p15(move_only(), ip);
65 std::pair<move_only, int X::*> p16(move_only(), mp);
66
67 std::pair<move_only, move_only> p17{move_only(), move_only()};
68 }