| 1 |
// PR c++/106276 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "-Wpessimizing-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 A { A(); A(const A&) = delete; A(A&&); }; |
| 26 |
struct B { B(A); }; |
| 27 |
|
| 28 |
static A foo (); |
| 29 |
|
| 30 |
A |
| 31 |
fn1 () |
| 32 |
{ |
| 33 |
return std::move (A{}); // { dg-warning "moving a temporary object prevents copy elision" } |
| 34 |
return std::move (A()); // { dg-warning "moving a temporary object prevents copy elision" } |
| 35 |
return std::move (foo ()); // { dg-warning "moving a temporary object prevents copy elision" } |
| 36 |
} |
| 37 |
|
| 38 |
B fn2 () |
| 39 |
{ |
| 40 |
return std::move (A()); // { dg-warning "moving a temporary object prevents copy elision" } |
| 41 |
return std::move (A{}); // { dg-warning "moving a temporary object prevents copy elision" } |
| 42 |
return std::move (foo ()); // { dg-warning "moving a temporary object prevents copy elision" } |
| 43 |
} |
| 44 |
|
| 45 |
template <typename T1, typename T2> |
| 46 |
T1 |
| 47 |
fn3 () |
| 48 |
{ |
| 49 |
return std::move (T2{}); // { dg-warning "moving a temporary object prevents copy elision" } |
| 50 |
} |
| 51 |
|
| 52 |
void |
| 53 |
do_fn3 () |
| 54 |
{ |
| 55 |
fn3<A, A>(); |
| 56 |
fn3<B, A>(); |
| 57 |
} |
| 58 |
|
| 59 |
char take_buffer; |
| 60 |
struct label_text { |
| 61 |
label_text take() { return std::move(label_text(&take_buffer)); } // { dg-warning "moving a temporary object prevents copy elision" } |
| 62 |
label_text(char *); |
| 63 |
}; |