blob: 0cda96846f7170bcca1b618a3c6e6709186f7bcc [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <tuple>
11
12// template <class... Types> class tuple;
13
14// tuple(tuple&& u);
15
Eric Fiselierf0630522015-02-19 02:10:42 +000016// UNSUPPORTED: c++98, c++03
17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018#include <tuple>
Marshall Clow6b913d72015-01-09 20:25:52 +000019#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include <cassert>
21
Marshall Clowdf00d5e2015-01-28 21:22:53 +000022#include "MoveOnly.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023
Eric Fiselier9020c082014-07-24 18:48:34 +000024struct ConstructsWithTupleLeaf
25{
26 ConstructsWithTupleLeaf() {}
27
28 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); }
29 ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {}
30
31 template <class T>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070032 ConstructsWithTupleLeaf(T t)
33 { assert(false); }
Eric Fiselier9020c082014-07-24 18:48:34 +000034};
35
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036int main()
37{
38 {
39 typedef std::tuple<> T;
40 T t0;
41 T t = std::move(t0);
Eric Fiselier75fdf0e2015-02-05 20:28:37 +000042 ((void)t); // Prevent unused warning
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 }
44 {
45 typedef std::tuple<MoveOnly> T;
46 T t0(MoveOnly(0));
47 T t = std::move(t0);
48 assert(std::get<0>(t) == 0);
49 }
50 {
51 typedef std::tuple<MoveOnly, MoveOnly> T;
52 T t0(MoveOnly(0), MoveOnly(1));
53 T t = std::move(t0);
54 assert(std::get<0>(t) == 0);
55 assert(std::get<1>(t) == 1);
56 }
57 {
58 typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
59 T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
60 T t = std::move(t0);
61 assert(std::get<0>(t) == 0);
62 assert(std::get<1>(t) == 1);
63 assert(std::get<2>(t) == 2);
64 }
Eric Fiselier9020c082014-07-24 18:48:34 +000065 // A bug in tuple caused __tuple_leaf to use its explicit converting constructor
66 // as its move constructor. This tests that ConstructsWithTupleLeaf is not called
67 // (w/ __tuple_leaf)
68 {
69 typedef std::tuple<ConstructsWithTupleLeaf> d_t;
70 d_t d((ConstructsWithTupleLeaf()));
71 d_t d2(static_cast<d_t &&>(d));
72 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073}