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 // <tuple> 11 12 // template <class... Types> class tuple; 13 14 // tuple(tuple&& u); 15 16 #include <tuple> 17 #include <cassert> 18 19 #include "../MoveOnly.h" 20 21 struct ConstructsWithTupleLeaf 22 { ConstructsWithTupleLeafConstructsWithTupleLeaf23 ConstructsWithTupleLeaf() {} 24 ConstructsWithTupleLeafConstructsWithTupleLeaf25 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); } ConstructsWithTupleLeafConstructsWithTupleLeaf26 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {} 27 28 template <class T> ConstructsWithTupleLeafConstructsWithTupleLeaf29 ConstructsWithTupleLeaf(T t) 30 { assert(false); } 31 }; 32 main()33int main() 34 { 35 { 36 typedef std::tuple<> T; 37 T t0; 38 T t = std::move(t0); 39 } 40 { 41 typedef std::tuple<MoveOnly> T; 42 T t0(MoveOnly(0)); 43 T t = std::move(t0); 44 assert(std::get<0>(t) == 0); 45 } 46 { 47 typedef std::tuple<MoveOnly, MoveOnly> T; 48 T t0(MoveOnly(0), MoveOnly(1)); 49 T t = std::move(t0); 50 assert(std::get<0>(t) == 0); 51 assert(std::get<1>(t) == 1); 52 } 53 { 54 typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T; 55 T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2)); 56 T t = std::move(t0); 57 assert(std::get<0>(t) == 0); 58 assert(std::get<1>(t) == 1); 59 assert(std::get<2>(t) == 2); 60 } 61 // A bug in tuple caused __tuple_leaf to use its explicit converting constructor 62 // as its move constructor. This tests that ConstructsWithTupleLeaf is not called 63 // (w/ __tuple_leaf) 64 { 65 typedef std::tuple<ConstructsWithTupleLeaf> d_t; 66 d_t d((ConstructsWithTupleLeaf())); 67 d_t d2(static_cast<d_t &&>(d)); 68 } 69 } 70