2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wredundant-move1.C
blob5d4a25dbc3b55539ca8d6f7020f9929ef0336acd
1 // PR c++/87029
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wredundant-move" }
5 // Define std::move.
6 namespace std {
7   template<typename _Tp>
8     struct remove_reference
9     { typedef _Tp   type; };
11   template<typename _Tp>
12     struct remove_reference<_Tp&>
13     { typedef _Tp   type; };
15   template<typename _Tp>
16     struct remove_reference<_Tp&&>
17     { typedef _Tp   type; };
19   template<typename _Tp>
20     constexpr typename std::remove_reference<_Tp>::type&&
21     move(_Tp&& __t) noexcept
22     { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
25 struct T {
26   T() { }
27   T(const T&) { }
28   T(T&&) { }
31 struct U {
32   U() { }
33   U(const U&) { }
34   U(U&&) { }
35   U(T) { }
39 fn1 (T t)
41   return t;
45 fn2 (T t)
47   // Will use move even without std::move.
48   return std::move (t); // { dg-warning "redundant move in return statement" }
52 fn3 (const T t)
54   // t is const: will decay into copy.
55   return t;
59 fn4 (const T t)
61   // t is const: will decay into copy despite std::move, so it's redundant.
62   return std::move (t); // { dg-warning "redundant move in return statement" }
65 int
66 fn5 (int i)
68   // Not a class type.
69   return std::move (i);
73 fn6 (T t, bool b)
75   if (b)
76     throw std::move (t);
77   return std::move (t); // { dg-warning "redundant move in return statement" }
81 fn7 (T t)
83   // Core 1579 means we'll get a move here.
84   return t;
88 fn8 (T t)
90   // Core 1579 means we'll get a move here.  Even without std::move.
91   return std::move (t);  // { dg-warning "redundant move in return statement" }
95 fn9 (T& t)
97   // T is a reference and the move isn't redundant.
98   return std::move (t);
102 fn10 (T&& t)
104   // T is a reference and the move isn't redundant.
105   return std::move (t);