Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wredundant-move1.C
blobc227019cce1cb7d919bb9118e58c7001437e1215
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   // We used to warn about this, but no longer since c++/87378.
63   // Now we warn again since c++/90428.
64   return std::move (t);  // { dg-warning "redundant move" }
67 int
68 fn5 (int i)
70   // Not a class type.
71   return std::move (i);
75 fn6 (T t, bool b)
77   if (b)
78     throw std::move (t);
79   return std::move (t); // { dg-warning "redundant move in return statement" }
83 fn7 (T t)
85   // Core 1579 means we'll get a move here.
86   return t;
90 fn8 (T t)
92   // Core 1579 means we'll get a move here.  Even without std::move.
93   return std::move (t);  // { dg-warning "redundant move in return statement" }
97 fn9 (T& t)
99   // T is a reference and the move isn't redundant.
100   return std::move (t);
104 fn10 (T&& t)
106   // T is a reference and the move isn't redundant.
107   return std::move (t);