Debian Codegraph @

gcc/testsuite/g++.dg/cpp26/pack-indexing1.C

raw
1 // P2662R3 - Pack Indexing
2 // PR c++/113798
3 // { dg-do compile { target c++17 } }
4 // { dg-options "" }
5
6 template<class, class> struct same_type;
7 template<class T> struct same_type<T, T> {};
8
9 template<int I, typename... Ts>
10 using Type = Ts...[I]; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
11
12 template<int I, auto... Ts>
13 constexpr auto Var = Ts...[I]; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
14
15 template <int I, auto...Ts>
16 int
17 foo ()
18 {
19 return Ts...[I]; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
20 }
21
22 template<typename... Ts>
23 struct S {
24 Ts...[0] a; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
25 #if __cpp_concepts >= 201907L
26 void foo (auto... Vs) {
27 decltype(Vs...[1]) d1 = Vs...[1]; // { dg-warning "pack indexing only available with" "" { target { c++20 && c++23_down } } }
28 }
29 #endif
30 };
31
32 int
33 g ()
34 {
35 using U = Type<1, char, int, float>;
36 using U = int;
37
38 constexpr auto V = Var<2, 0, 1, 42>;
39 static_assert (V == 42);
40
41 U r = foo<2, 0, 1, 42>();
42
43 return r;
44 }
45
46 void
47 fn1 ()
48 {
49 int i = 0;
50 [&i](auto... pack) {
51 // type is int
52 decltype(pack...[0]) x5 = 42; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
53 // type is int&
54 [[maybe_unused]] decltype((pack...[0])) x6 = i; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
55 }(0);
56 }
57
58 #if __cpp_concepts >= 201907L
59 int
60 bar (auto... pack)
61 {
62 (void) pack...[0]; // { dg-warning "pack indexing only available with" "" { target { c++20 && c++23_down } } }
63 int x = pack...[0]; // { dg-warning "pack indexing only available with" "" { target { c++20 && c++23_down } } }
64 return x;
65 }
66 #endif
67
68 template<auto...pack>
69 void
70 fn2 ()
71 {
72 [[maybe_unused]] decltype(pack...[0]) x1; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
73 [[maybe_unused]] decltype((pack...[0])) x2; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
74 same_type<decltype(x1), int>();
75 same_type<decltype(x2), int>();
76 }
77
78 template<typename... T>
79 void
80 fn3 (int p)
81 {
82 T...[0] a = p; // { dg-warning "pack indexing only available with" "" { target c++23_down } }
83 (T...[0])(a); // { dg-warning "pack indexing only available with" "" { target c++23_down } }
84 }
85
86 template<int... Is>
87 void fn4 ()
88 {
89 same_type<decltype(Is...[0]), int>(); // { dg-warning "pack indexing only available with" "" { target c++23_down } }
90 same_type<decltype((Is...[0])), int>(); // { dg-warning "pack indexing only available with" "" { target c++23_down } }
91 }
92
93 void
94 g3 ()
95 {
96 fn2<0>();
97 #if __cpp_concepts >= 201907L
98 bar (0);
99 #endif
100 S<int> s;
101 fn4<0, 1, 2>();
102 }