move_copy.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// test move 11 12#include <utility> 13#include <cassert> 14 15int copy_ctor = 0; 16int move_ctor = 0; 17 18class A 19{ 20#ifdef _LIBCPP_MOVE 21#else 22#endif 23 24public: 25 26#ifdef _LIBCPP_MOVE 27 A(const A&) {++copy_ctor;} 28 A& operator=(const A&); 29 30 A(A&&) {++move_ctor;} 31 A& operator=(A&&); 32#else 33 A(const A&) {++copy_ctor;} 34 A& operator=(A&); 35 36 operator std::__rv<A> () {return std::__rv<A>(*this);} 37 A(std::__rv<A>) {++move_ctor;} 38#endif 39 40 A() {} 41}; 42 43A source() {return A();} 44const A csource() {return A();} 45 46void test(A) {} 47 48int main() 49{ 50 A a; 51 const A ca = A(); 52 53 assert(copy_ctor == 0); 54 assert(move_ctor == 0); 55 56 A a2 = a; 57 assert(copy_ctor == 1); 58 assert(move_ctor == 0); 59 60 A a3 = std::move(a); 61 assert(copy_ctor == 1); 62 assert(move_ctor == 1); 63 64 A a4 = ca; 65 assert(copy_ctor == 2); 66 assert(move_ctor == 1); 67 68 A a5 = std::move(ca); 69 assert(copy_ctor == 3); 70 assert(move_ctor == 1); 71} 72