2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wself-move" }
8 struct remove_reference
11 template<typename _Tp>
12 struct remove_reference<_Tp&>
13 { typedef _Tp type; };
15 template<typename _Tp>
16 struct remove_reference<_Tp&&>
17 { typedef _Tp type; };
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); }
30 x = std::move (x); // { dg-warning "moving '\[^\n\r]*S::x' of type .int. to itself" }
33 o.x = std::move (o.x); // { dg-warning "moving 'o.S::x' of type .int. to itself" }
36 x = std::move (x); // { dg-warning "moving 'x' of type .int. to itself" }
42 X(int x) : x(std::move (x)) { }
47 struct C { C(); ~C(); };
48 struct D { D(); D(const D&); D(D&&); D& operator=(const D&); };
54 i = std::move (i); // { dg-warning "moving 'i' of type .int. to itself" }
55 (i) = std::move (i); // { dg-warning "moving 'i' of type .int. to itself" }
57 g = std::move (g); // { dg-warning "moving 'g' of type .int. to itself" }
58 (g) = std::move (g); // { dg-warning "moving 'g' of type .int. to itself" }
61 a = std::move (a); // { dg-warning "moving 'a' of type .A. to itself" }
62 (a) = std::move (a); // { dg-warning "moving 'a' of type .A. to itself" }
65 b = std::move (b); // { dg-warning "moving 'b' of type .B. to itself" }
66 (b) = std::move (b); // { dg-warning "moving 'b' of type .B. to itself" }
67 b.a = std::move (b.a); // { dg-warning "moving 'b.B::a' of type .A. to itself" }
68 (b.a) = std::move (b.a); // { dg-warning "moving 'b.B::a' of type .A. to itself" }
71 c = std::move (c); // { dg-warning "moving 'c' of type .C. to itself" }
73 d = std::move (d); // { dg-warning "moving 'd' of type .D. to itself" }
80 t = std::move (t); // { dg-warning "moving 't' of type .A. to itself" }
83 template void ttest<A>();
86 testref (int &r, int &&rr)
88 r = std::move (r); // { dg-warning "moving 'r' of type .int. to itself" }
89 rr = std::move (rr); // { dg-warning "moving 'rr' of type .int. to itself" }
92 // Test various other arguments to std::move.
95 testargs (T *Tptr, T **Tpptr, T& Tref, T&& Trref, const T *Tcptr)
97 Tptr = std::move (Tptr); // { dg-warning "moving 'Tptr' of type 'int\\*' to itself" }
98 *Tptr = std::move (*Tptr); // { dg-warning "moving '\\* Tptr' of type 'int' to itself" }
99 *Tptr = std::move (*(Tptr)); // { dg-warning "moving '\\* Tptr' of type 'int' to itself" }
100 *(Tptr) = std::move (*Tptr); // { dg-warning "moving '\\* Tptr' of type 'int' to itself" }
101 *(Tptr + 1) = std::move (*(Tptr + 1)); // { dg-warning "moving '\[^\n\r]*Tptr\[^\n\r]*' of type 'int' to itself" }
102 *(Tptr + 1) = std::move (*(Tptr + 2));
103 (*(Tptr)) = std::move (*Tptr); // { dg-warning "moving '\\* Tptr' of type 'int' to itself" }
104 *Tpptr = std::move (*Tpptr); // { dg-warning "moving '\\* Tpptr' of type 'int\\*' to itself" }
105 **Tpptr = std::move (**Tpptr); // { dg-warning "moving '\\* \\* Tpptr' of type 'int' to itself" }
106 Tref = std::move (Tref); // { dg-warning "moving 'Tref' of type 'int' to itself" }
107 Trref = std::move (Trref); // { dg-warning "moving 'Trref' of type 'int' to itself" }
108 Tcptr = std::move (Tcptr); // { dg-warning "moving 'Tcptr' of type 'const int\\*' to itself" }
109 (Tptr) = std::move (Tptr); // { dg-warning "moving 'Tptr' of type 'int\\*' to itself" }
110 (*Tptr) = std::move (*Tptr); // { dg-warning "moving '\\* Tptr' of type 'int' to itself" }
111 (*Tpptr) = std::move (*Tpptr); // { dg-warning "moving '\\* Tpptr' of type 'int\\*' to itself" }
112 (**Tpptr) = std::move (**Tpptr); // { dg-warning "moving '\\* \\* Tpptr' of type 'int' to itself" }
113 (*(*(Tpptr))) = std::move (**Tpptr); // { dg-warning "moving '\\* \\* Tpptr' of type 'int' to itself" }
114 (Tref) = std::move (Tref); // { dg-warning "moving 'Tref' of type 'int' to itself" }
115 (Trref) = std::move (Trref); // { dg-warning "moving 'Trref' of type 'int' to itself" }
116 (Tcptr) = std::move (Tcptr); // { dg-warning "moving 'Tcptr' of type 'const int\\*' to itself" }
124 testargs<int>(&i, &p, i, 42, &i);