| 1 | // { dg-do compile { target c++11 } } |
| 2 | // { dg-options "-Wno-unused-variable" } |
| 3 | // { dg-additional-options "-D_GLIBCXX_DEBUG" { target c++17_down } } |
| 4 | // { dg-skip-if "cannot mix with DEBUG" { *-*-* } { "-D_GLIBCXX_PARALLEL" } } |
| 5 | #include <tuple> |
| 6 | #include <utility> |
| 7 | |
| 8 | #if __cplusplus >= 202002L |
| 9 | // For C++20 and later, constructors are constrained to disallow dangling. |
| 10 | static_assert(!std::is_constructible_v<std::tuple<const int&>, long>); |
| 11 | static_assert(!std::is_constructible_v<std::tuple<const int&, int>, long, int>); |
| 12 | static_assert(!std::is_constructible_v<std::tuple<int, const int&>, int, long>); |
| 13 | static_assert(!std::is_constructible_v<std::tuple<const int&, int>, |
| 14 | std::tuple<long, long>>); |
| 15 | static_assert(!std::is_constructible_v<std::tuple<int, const int&>, |
| 16 | std::tuple<long, long>>); |
| 17 | static_assert(!std::is_constructible_v<std::tuple<const int&, int>, |
| 18 | const std::tuple<long, long>&>); |
| 19 | static_assert(!std::is_constructible_v<std::tuple<int, const int&>, |
| 20 | const std::tuple<long, long>&>); |
| 21 | static_assert(!std::is_constructible_v<std::tuple<const int&, int>, |
| 22 | std::pair<long, long>>); |
| 23 | static_assert(!std::is_constructible_v<std::tuple<int, const int&>, |
| 24 | std::pair<long, long>>); |
| 25 | static_assert(!std::is_constructible_v<std::tuple<const int&, int>, |
| 26 | const std::pair<long, long>&>); |
| 27 | static_assert(!std::is_constructible_v<std::tuple<int, const int&>, |
| 28 | const std::pair<long, long>&>); |
| 29 | #endif |
| 30 | |
| 31 | void |
| 32 | test_ary_ctors() |
| 33 | { |
| 34 | std::tuple<const int&> t1(1L); |
| 35 | // { dg-error "here" "" { target { c++17_down && hosted } } 34 } |
| 36 | // { dg-error "use of deleted function" "" { target c++20 } 34 } |
| 37 | |
| 38 | std::tuple<const int&, int> t2(1L, 2); |
| 39 | // { dg-error "here" "" { target { c++17_down && hosted } } 38 } |
| 40 | // { dg-error "use of deleted function" "" { target c++20 } 38 } |
| 41 | |
| 42 | std::tuple<int, const int&> t3(1, 2L); |
| 43 | // { dg-error "here" "" { target { c++17_down && hosted } } 42 } |
| 44 | // { dg-error "use of deleted function" "" { target c++20 } 42 } |
| 45 | |
| 46 | std::tuple<const int&, const int&> t4(1L, 2L); |
| 47 | // { dg-error "here" "" { target { c++17_down && hosted } } 46 } |
| 48 | // { dg-error "use of deleted function" "" { target c++20 } 46 } |
| 49 | |
| 50 | std::tuple<const int&, const int&> t5(std::pair<long, int>{}); |
| 51 | // { dg-error "here" "" { target { c++17_down && hosted } } 50 } |
| 52 | // { dg-error "use of deleted function" "" { target c++20 } 50 } |
| 53 | |
| 54 | std::pair<int, long> p; |
| 55 | std::tuple<const int&, const int&> t6(p); |
| 56 | // { dg-error "here" "" { target { c++17_down && hosted } } 55 } |
| 57 | // { dg-error "use of deleted function" "" { target c++20 } 55 } |
| 58 | |
| 59 | std::tuple<const int&, int, int> t7(1L, 2, 3); |
| 60 | // { dg-error "here" "" { target { c++17_down && hosted } } 59 } |
| 61 | // { dg-error "use of deleted function" "" { target c++20 } 59 } |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | test_converting_ctors() |
| 66 | { |
| 67 | std::tuple<long> t10; |
| 68 | |
| 69 | std::tuple<const int&> t11(t10); |
| 70 | // { dg-error "here" "" { target { c++17_down && hosted } } 69 } |
| 71 | // { dg-error "use of deleted function" "" { target c++20 } 69 } |
| 72 | |
| 73 | std::tuple<const int&> t12(std::move(t10)); |
| 74 | // { dg-error "here" "" { target { c++17_down && hosted } } 73 } |
| 75 | // { dg-error "use of deleted function" "" { target c++20 } 73 } |
| 76 | |
| 77 | std::tuple<long, long> t20; |
| 78 | |
| 79 | std::tuple<const int&, int> t21(t20); |
| 80 | // { dg-error "here" "" { target { c++17_down && hosted } } 79 } |
| 81 | // { dg-error "use of deleted function" "" { target c++20 } 79 } |
| 82 | |
| 83 | std::tuple<int, const int&> t22(t20); |
| 84 | // { dg-error "here" "" { target { c++17_down && hosted } } 83 } |
| 85 | // { dg-error "use of deleted function" "" { target c++20 } 83 } |
| 86 | |
| 87 | std::tuple<const int&, const int&> t23(t20); |
| 88 | // { dg-error "here" "" { target { c++17_down && hosted } } 87 } |
| 89 | // { dg-error "use of deleted function" "" { target c++20 } 87 } |
| 90 | |
| 91 | std::tuple<const int&, int> t24(std::move(t20)); |
| 92 | // { dg-error "here" "" { target { c++17_down && hosted } } 91 } |
| 93 | // { dg-error "use of deleted function" "" { target c++20 } 91 } |
| 94 | |
| 95 | std::tuple<int, const int&> t25(std::move(t20)); |
| 96 | // { dg-error "here" "" { target { c++17_down && hosted } } 95 } |
| 97 | // { dg-error "use of deleted function" "" { target c++20 } 95 } |
| 98 | |
| 99 | std::tuple<const int&, const int&> t26(std::move(t20)); |
| 100 | // { dg-error "here" "" { target { c++17_down && hosted } } 99 } |
| 101 | // { dg-error "use of deleted function" "" { target c++20 } 99 } |
| 102 | |
| 103 | std::pair<long, long> p0; |
| 104 | std::tuple<const int&, int> t27(p0); |
| 105 | // { dg-error "here" "" { target { c++17_down && hosted } } 104 } |
| 106 | // { dg-error "use of deleted function" "" { target c++20 } 104 } |
| 107 | |
| 108 | std::tuple<int, const int&> t28(p0); |
| 109 | // { dg-error "here" "" { target { c++17_down && hosted } } 108 } |
| 110 | // { dg-error "use of deleted function" "" { target c++20 } 108 } |
| 111 | |
| 112 | std::tuple<const int&, int> t29(std::move(p0)); |
| 113 | // { dg-error "here" "" { target { c++17_down && hosted } } 112 } |
| 114 | // { dg-error "use of deleted function" "" { target c++20 } 112 } |
| 115 | |
| 116 | std::tuple<int, const int&> t210(std::move(p0)); |
| 117 | // { dg-error "here" "" { target { c++17_down && hosted } } 116 } |
| 118 | // { dg-error "use of deleted function" "" { target c++20 } 116 } |
| 119 | } |
| 120 | |
| 121 | #include <memory> |
| 122 | |
| 123 | void |
| 124 | test_allocator_extended_ctors() |
| 125 | { |
| 126 | std::allocator<int> a; |
| 127 | |
| 128 | std::tuple<const int&> t1(std::allocator_arg, a, 1L); |
| 129 | // { dg-error "here" "" { target { c++17_down && hosted } } 128 } |
| 130 | // { dg-error "use of deleted function" "" { target c++20 } 128 } |
| 131 | |
| 132 | std::tuple<const int&, int> t2(std::allocator_arg, a, 1L, 2); |
| 133 | // { dg-error "here" "" { target { c++17_down && hosted } } 132 } |
| 134 | // { dg-error "use of deleted function" "" { target c++20 } 132 } |
| 135 | |
| 136 | std::tuple<long> tl; |
| 137 | |
| 138 | std::tuple<const int&> t3(std::allocator_arg, a, tl); |
| 139 | // { dg-error "here" "" { target { c++17_down && hosted } } 138 } |
| 140 | // { dg-error "use of deleted function" "" { target c++20 } 138 } |
| 141 | |
| 142 | std::tuple<const int&> t4(std::allocator_arg, a, std::move(tl)); |
| 143 | // { dg-error "here" "" { target { c++17_down && hosted } } 142 } |
| 144 | // { dg-error "use of deleted function" "" { target c++20 } 142 } |
| 145 | |
| 146 | std::tuple<long, long> tll; |
| 147 | |
| 148 | std::tuple<const int&, int> t5(std::allocator_arg, a, tll); |
| 149 | // { dg-error "here" "" { target { c++17_down && hosted } } 148 } |
| 150 | // { dg-error "use of deleted function" "" { target c++20 } 148 } |
| 151 | |
| 152 | std::tuple<const int&, int> t6(std::allocator_arg, a, std::move(tll)); |
| 153 | // { dg-error "here" "" { target { c++17_down && hosted } } 152 } |
| 154 | // { dg-error "use of deleted function" "" { target c++20 } 152 } |
| 155 | |
| 156 | std::pair<long, long> pll; |
| 157 | |
| 158 | std::tuple<const int&, int> t7(std::allocator_arg, a, pll); |
| 159 | // { dg-error "here" "" { target { c++17_down && hosted } } 158 } |
| 160 | // { dg-error "use of deleted function" "" { target c++20 } 158 } |
| 161 | |
| 162 | std::tuple<const int&, int> t8(std::allocator_arg, a, std::move(pll)); |
| 163 | // { dg-error "here" "" { target { c++17_down && hosted } } 162 } |
| 164 | // { dg-error "use of deleted function" "" { target c++20 } 162 } |
| 165 | } |
| 166 | |
| 167 | // { dg-error "static assert.* dangling reference" "" { target { c++17_down && hosted } } 0 } |