1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11
10
11// Make sure that we don't blow up the template instantiation recursion depth
12// for tuples of size <= 512.
13
14#include <tuple>
15#include <cassert>
16#include <utility>
17
18#include "test_macros.h"
19
20template <std::size_t... I>
21constexpr void CreateTuple(std::index_sequence<I...>) {
22 using LargeTuple = std::tuple<std::integral_constant<std::size_t, I>...>;
23 using TargetTuple = std::tuple<decltype(I)...>;
24 LargeTuple tuple(std::integral_constant<std::size_t, I>{}...);
25 assert(std::get<0>(tuple).value == 0);
26 assert(std::get<sizeof...(I)-1>(tuple).value == sizeof...(I)-1);
27
28 TargetTuple t1 = tuple; // converting copy constructor from &
29 TargetTuple t2 = static_cast<LargeTuple const&>(tuple); // converting copy constructor from const&
30 TargetTuple t3 = std::move(tuple); // converting rvalue constructor
31 TargetTuple t4 = static_cast<LargeTuple const&&>(tuple); // converting const rvalue constructor
32 TargetTuple t5; // default constructor
33 (void)t1; (void)t2; (void)t3; (void)t4; (void)t5;
34
35#if TEST_STD_VER >= 20
36 t1 = tuple; // converting assignment from &
37 t1 = static_cast<LargeTuple const&>(tuple); // converting assignment from const&
38 t1 = std::move(tuple); // converting assignment from &&
39 t1 = static_cast<LargeTuple const&&>(tuple); // converting assignment from const&&
40 swap(t1, t2); // swap
41#endif
42 // t1 == tuple; // comparison does not work yet (we blow the constexpr stack)
43}
44
45constexpr bool test() {
46 CreateTuple(std::make_index_sequence<512>{});
47 return true;
48}
49
50int main(int, char**) {
51 test();
52 static_assert(test(), "");
53 return 0;
54}
55

source code of libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp