c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wredundant-move9.C
blob489ecd2b9c9b370d9954882df4c19b06d6bab56e
1 // { dg-do compile { target c++11 } }
2 // { dg-options "-Wredundant-move" }
4 // Define std::move.
5 namespace std {
6   template<typename _Tp>
7     struct remove_reference
8     { typedef _Tp   type; };
10   template<typename _Tp>
11     struct remove_reference<_Tp&>
12     { typedef _Tp   type; };
14   template<typename _Tp>
15     struct remove_reference<_Tp&&>
16     { typedef _Tp   type; };
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); }
24 template<typename Tp>
25 struct T {
26   T() { }
27   T(const T&) { }
28   T(T&&) { }
31 template<typename Tp>
32 struct U {
33   U() { }
34   U(const U&) { }
35   U(U&&) { }
36   U(T<Tp>) { }
39 T<int>
40 fn1 (T<int> t)
42   return t;
45 T<int>
46 fn2 (T<int> t)
48   // Will use move even without std::move.
49   return std::move (t); // { dg-warning "redundant move in return statement" }
52 T<int>
53 fn3 (const T<int> t)
55   // t is const: will decay into copy.
56   return t;
59 T<int>
60 fn4 (const T<int> t)
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" }
68 int
69 fn5 (int i)
71   // Not a class type.
72   return std::move (i);
75 T<int>
76 fn6 (T<int> t, bool b)
78   if (b)
79     throw std::move (t);
80   return std::move (t); // { dg-warning "redundant move in return statement" }
83 U<int>
84 fn7 (T<int> t)
86   // Core 1579 means we'll get a move here.
87   return t;
90 U<int>
91 fn8 (T<int> t)
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" }
97 T<int>
98 fn9 (T<int>& t)
100   // T is a reference and the move isn't redundant.
101   return std::move (t);
104 T<int>
105 fn10 (T<int>&& t)
107   // T is a reference and the move isn't redundant.
108   return std::move (t);