| 1 |
// PR c++/90428 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "-Wredundant-move" } |
| 4 |
|
| 5 |
// Define std::move. |
| 6 |
namespace std { |
| 7 |
template<typename _Tp> |
| 8 |
struct remove_reference |
| 9 |
{ typedef _Tp type; }; |
| 10 |
|
| 11 |
template<typename _Tp> |
| 12 |
struct remove_reference<_Tp&> |
| 13 |
{ typedef _Tp type; }; |
| 14 |
|
| 15 |
template<typename _Tp> |
| 16 |
struct remove_reference<_Tp&&> |
| 17 |
{ typedef _Tp type; }; |
| 18 |
|
| 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); } |
| 23 |
} |
| 24 |
|
| 25 |
struct T { T(); T(const T&); T(T&&) = delete; }; |
| 26 |
struct S : T { }; |
| 27 |
struct W { W(const W&); W(W&&) = delete; W(const W&&); }; |
| 28 |
|
| 29 |
T f1(T t) |
| 30 |
{ |
| 31 |
const T& rt = t; |
| 32 |
return std::move(rt); // { dg-warning "redundant move" } |
| 33 |
} |
| 34 |
|
| 35 |
T f2(const T& t) |
| 36 |
{ |
| 37 |
return std::move(t); // { dg-warning "redundant move" } |
| 38 |
} |
| 39 |
|
| 40 |
W f3(const W& w) |
| 41 |
{ |
| 42 |
return std::move(w); |
| 43 |
} |
| 44 |
|
| 45 |
T f4(const S& s) |
| 46 |
{ |
| 47 |
return std::move(s); |
| 48 |
} |
| 49 |
|
| 50 |
T f5(const T t) |
| 51 |
{ |
| 52 |
return std::move(t); // { dg-warning "redundant move" } |
| 53 |
} |
| 54 |
|
| 55 |
struct S1 { S1(S1 &&) = delete; S1(const S1&); }; |
| 56 |
struct S2: S1 {}; |
| 57 |
|
| 58 |
S1 f3(const S2 s) |
| 59 |
{ |
| 60 |
return std::move(s); // { dg-warning "redundant move" } |
| 61 |
} |