| 1 |
// PR c++/107363 |
| 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 |
template <typename T, typename U> |
| 26 |
struct Optional { |
| 27 |
U &value(); |
| 28 |
T release_value() { |
| 29 |
T t = std::move (value ()); |
| 30 |
return t; |
| 31 |
} |
| 32 |
}; |
| 33 |
|
| 34 |
struct Foo {}; |
| 35 |
void test(Optional<const Foo, const Foo> o) { o.release_value(); } |
| 36 |
|
| 37 |
struct F { |
| 38 |
F(const F&); |
| 39 |
F(F&&) = delete; |
| 40 |
}; |
| 41 |
|
| 42 |
struct Z { |
| 43 |
Z(const Z&) = delete; |
| 44 |
Z(Z&&) = delete; |
| 45 |
Z(const Z&&); |
| 46 |
}; |
| 47 |
|
| 48 |
const F& constfref(); |
| 49 |
const Z& constzref(); |
| 50 |
|
| 51 |
void |
| 52 |
g () |
| 53 |
{ |
| 54 |
// Will call F::F(const F&) w/ and w/o std::move. So it's redundant. |
| 55 |
F f = std::move (constfref()); // { dg-warning "redundant move in initialization" } |
| 56 |
(void) f; |
| 57 |
// Will call Z::Z(const Z&&) w/ std::move, and Z::Z(const Z&) w/o. |
| 58 |
// So it's not redundant. |
| 59 |
Z z = std::move (constzref()); |
| 60 |
(void) z; |
| 61 |
} |