]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/g++.dg/cpp0x/Wredundant-move9.C
Regenerate riscv.opt.urls and i386.opt.urls
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wredundant-move9.C
1 // { dg-do compile { target c++11 } }
2 // { dg-options "-Wredundant-move" }
3
4 // Define std::move.
5 namespace std {
6 template<typename _Tp>
7 struct remove_reference
8 { typedef _Tp type; };
9
10 template<typename _Tp>
11 struct remove_reference<_Tp&>
12 { typedef _Tp type; };
13
14 template<typename _Tp>
15 struct remove_reference<_Tp&&>
16 { typedef _Tp type; };
17
18 template<typename _Tp>
19 constexpr typename std::remove_reference<_Tp>::type&&
20 move(_Tp&& __t) noexcept
21 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
22 }
23
24 template<typename Tp>
25 struct T {
26 T() { }
27 T(const T&) { }
28 T(T&&) { }
29 };
30
31 template<typename Tp>
32 struct U {
33 U() { }
34 U(const U&) { }
35 U(U&&) { }
36 U(T<Tp>) { }
37 };
38
39 T<int>
40 fn1 (T<int> t)
41 {
42 return t;
43 }
44
45 T<int>
46 fn2 (T<int> t)
47 {
48 // Will use move even without std::move.
49 return std::move (t); // { dg-warning "redundant move in return statement" }
50 }
51
52 T<int>
53 fn3 (const T<int> t)
54 {
55 // t is const: will decay into copy.
56 return t;
57 }
58
59 T<int>
60 fn4 (const T<int> t)
61 {
62 // t is const: will decay into copy despite std::move, so it's redundant.
63 // We used to warn about this, but no longer since c++/87378.
64 // Now we warn again since c++/90428.
65 return std::move (t); // { dg-warning "redundant move" }
66 }
67
68 int
69 fn5 (int i)
70 {
71 // Not a class type.
72 return std::move (i);
73 }
74
75 T<int>
76 fn6 (T<int> t, bool b)
77 {
78 if (b)
79 throw std::move (t);
80 return std::move (t); // { dg-warning "redundant move in return statement" }
81 }
82
83 U<int>
84 fn7 (T<int> t)
85 {
86 // Core 1579 means we'll get a move here.
87 return t;
88 }
89
90 U<int>
91 fn8 (T<int> t)
92 {
93 // Core 1579 means we'll get a move here. Even without std::move.
94 return std::move (t); // { dg-warning "redundant move in return statement" }
95 }
96
97 T<int>
98 fn9 (T<int>& t)
99 {
100 // T is a reference and the move isn't redundant.
101 return std::move (t);
102 }
103
104 T<int>
105 fn10 (T<int>&& t)
106 {
107 // T is a reference and the move isn't redundant.
108 return std::move (t);
109 }