Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / cpp0x / Wpessimizing-move6.C
blob646755661155c183220eb8b3541e926ceef94c00
1 // PR c++/86981
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wpessimizing-move" }
5 // Define std::move.
6 namespace std {
7   inline namespace _8 { }
8   namespace _8 {
9     template<typename _Tp>
10       struct remove_reference
11       { typedef _Tp   type; };
13     template<typename _Tp>
14       struct remove_reference<_Tp&>
15       { typedef _Tp   type; };
17     template<typename _Tp>
18       struct remove_reference<_Tp&&>
19       { typedef _Tp   type; };
21     template<typename _Tp>
22       constexpr typename std::remove_reference<_Tp>::type&&
23       move(_Tp&& __t) noexcept
24       { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
25   }
28 struct T {
29   T() { }
30   T(const T&) { }
31   T(T&&) { }
33 struct U {
34   U() { }
35   U(const U&) { }
36   U(U&&) { }
37   U(T) { }
40 T g;
43 fn1 ()
45   T t;
46   return std::move (t); // { dg-warning "moving a local object in a return statement prevents copy elision" }
50 fn2 ()
52   // Not a local variable.
53   return std::move (g);
56 int
57 fn3 ()
59   int i = 42;
60   // Not a class type.
61   return std::move (i);
65 fn4 (bool b)
67   T t;
68   if (b)
69     throw std::move (t);
70   return std::move (t); // { dg-warning "moving a local object in a return statement prevents copy elision" }
74 fn5 (T t)
76   // Function parameter; std::move is redundant but not pessimizing.
77   return std::move (t);
81 fn6 (T t, U u, bool b)
83   if (b)
84     return std::move (t);
85   else
86     // Function parameter; std::move is redundant but not pessimizing.
87     return std::move (u);
91 fn6 (bool b)
93   T t;
94   U u;
95   if (b)
96     return std::move (t);
97   else
98     return std::move (u); // { dg-warning "moving a local object in a return statement prevents copy elision" }
102 fn7 ()
104   static T t;
105   // Non-local; don't warn.
106   return std::move (t);
110 fn8 ()
112   return T();
116 fn9 (int i)
118   T t;
120   switch (i)
121     {
122     case 1:
123       return std::move ((t)); // { dg-warning "moving a local object in a return statement prevents copy elision" }
124     case 2:
125       return (std::move (t)); // { dg-warning "moving a local object in a return statement prevents copy elision" }
126     default:
127       return (std::move ((t))); // { dg-warning "moving a local object in a return statement prevents copy elision" }
128     }
132 fn10 ()
134   return std::move (42);