1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // test move
11 
12 // UNSUPPORTED: c++98, c++03
13 
14 #include <utility>
15 #include <cassert>
16 
17 int copy_ctor = 0;
18 int move_ctor = 0;
19 
20 class A
21 {
22 public:
23 
A(const A &)24     A(const A&) {++copy_ctor;}
25     A& operator=(const A&);
26 
A(A &&)27     A(A&&) {++move_ctor;}
28     A& operator=(A&&);
29 
A()30     A() {}
31 };
32 
source()33 A source() {return A();}
csource()34 const A csource() {return A();}
35 
test(A)36 void test(A) {}
37 
main()38 int main()
39 {
40     A a;
41     const A ca = A();
42 
43     assert(copy_ctor == 0);
44     assert(move_ctor == 0);
45 
46     A a2 = a;
47     assert(copy_ctor == 1);
48     assert(move_ctor == 0);
49 
50     A a3 = std::move(a);
51     assert(copy_ctor == 1);
52     assert(move_ctor == 1);
53 
54     A a4 = ca;
55     assert(copy_ctor == 2);
56     assert(move_ctor == 1);
57 
58     A a5 = std::move(ca);
59     assert(copy_ctor == 3);
60     assert(move_ctor == 1);
61 }
62