Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/implicit-move3.C

raw
1 // Testcase from P1825R0, modified for rvalue refs.
2 // { dg-do compile { target c++20 } }
3
4 extern "C" void abort();
5
6 int m;
7
8 struct T
9 {
10 int i;
11 T(): i (42) { }
12 T(const T& t) = delete;
13 T(T&& t): i(t.i) { t.i = 0; ++m; }
14 };
15
16 struct U
17 {
18 int i;
19 U(): i (42) { }
20 U(const U& t): i(t.i) { }
21 U(U&& t) = delete;
22 };
23
24 template <class V> void g(const V&);
25 void h();
26
27 bool b;
28
29 void f()
30 {
31 U&& x = U();
32 try {
33 T&& y = T();
34 try { h(); }
35 catch(...) {
36 if (b)
37 throw x; // does not move
38 throw y; // moves
39 }
40 g(y);
41 } catch(...) {
42 g(x);
43 }
44 }
45
46 int main()
47 {
48 f();
49 }