Jason Merrill | 4b2e63de | 2014-03-07 15:01:12 -0500 | [diff] [blame] | 1 | // { dg-do link { target c++11 } } |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 2 | |
Jason Merrill | e7f1930 | 2009-07-31 22:26:42 -0400 | [diff] [blame] | 3 | template<typename _Tp> |
| 4 | inline _Tp&& |
| 5 | movel(_Tp& __t) |
| 6 | { return static_cast<_Tp&&>(__t); } |
| 7 | |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 8 | struct S {}; |
| 9 | struct T |
| 10 | { |
Jason Merrill | e7f1930 | 2009-07-31 22:26:42 -0400 | [diff] [blame] | 11 | T(S && s_) : s(movel(s_)) {} |
| 12 | S && get() { return movel(s); } |
| 13 | operator S&&() { return movel(s); } |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 14 | S && s; |
Jason Merrill | 4757b07 | 2011-06-30 17:09:55 -0400 | [diff] [blame] | 15 | S s2; |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | void named(S const &) {} |
| 19 | void named(S&&); |
| 20 | |
| 21 | void unnamed(S const &); |
| 22 | void unnamed(S&&) {} |
| 23 | |
| 24 | void f(S && p) |
| 25 | { |
Jason Merrill | e7f1930 | 2009-07-31 22:26:42 -0400 | [diff] [blame] | 26 | S && s(movel(p)); |
| 27 | T t(movel(s)); |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 28 | |
| 29 | named(s); // variable reference |
| 30 | named(p); // parameter reference |
| 31 | named(t.s); // class member access |
| 32 | |
| 33 | unnamed(t.get()); // function return |
| 34 | unnamed(t); // implicit conversion |
| 35 | unnamed(static_cast<S&&>(s)); // cast to rvalue |
Jason Merrill | 4757b07 | 2011-06-30 17:09:55 -0400 | [diff] [blame] | 36 | unnamed(static_cast<T&&>(t).s2); // cast to rvalue |
Russell Yanofsky | 8af2fec | 2007-05-31 01:18:22 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | } |