Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / warn / Wself-move1.C
blob5c9fc92c3479fee7ff6ca1de42c9a925838309a9
1 // PR c++/81159
2 // { dg-do compile { target c++11 } }
3 // { dg-options "-Wself-move" }
5 // Define std::move.
6 namespace std {
7   template<typename _Tp>
8     struct remove_reference
9     { typedef _Tp   type; };
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); }
25 int g;
27 struct S {
28   int x;
29   S(S&& o) {
30     x = std::move (x); // { dg-warning "moving '\[^\n\r]*S::x' of type .int. to itself" }
31     x = std::move (o.x);
32     o.x = std::move (x);
33     o.x = std::move (o.x); // { dg-warning "moving 'o.S::x' of type .int. to itself" }
34   }
35   void foo (int x) {
36     x = std::move (x); // { dg-warning "moving 'x' of type .int. to itself" }
37   }
40 struct X {
41   int x;
42   X(int x) : x(std::move (x)) { }
45 struct A {};
46 struct B { A a; };
47 struct C { C(); ~C(); };
48 struct D { D(); D(const D&); D(D&&); D& operator=(const D&); };
50 void
51 test ()
53   int i = 42;
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" }
60   A a;
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" }
64   B b;
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" }
70   C c;
71   c = std::move (c); // { dg-warning "moving 'c' of type .C. to itself" }
72   D d;
73   d = std::move (d); // { dg-warning "moving 'd' of type .D. to itself" }
76 template<typename T>
77 void ttest ()
79   T t;
80   t = std::move (t); // { dg-warning "moving 't' of type .A. to itself" }
83 template void ttest<A>();
85 void
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.
93 template<typename T>
94 void
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" }
119 void
120 call_testargs ()
122   int i = 42;
123   int *p = &i;
124   testargs<int>(&i, &p, i, 42, &i);