Debian Codegraph @

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

raw
1 // P2662R3 - Pack Indexing
2 // PR c++/113798
3 // { dg-do compile { target c++26 } }
4
5 template<class, class> struct same_type;
6 template<class T> struct same_type<T, T> {};
7
8 void
9 fn1 (auto... Ts)
10 {
11 decltype(auto) a1 = Ts...[0];
12 same_type<decltype(a1), int>();
13 decltype(auto) a2 = (Ts...[0]);
14 same_type<decltype(a2), int&>();
15 }
16
17 template<auto... Is>
18 void
19 fn2 ()
20 {
21 decltype(auto) a1 = Is...[0];
22 same_type<decltype(a1), int>();
23 decltype(auto) a2 = (Is...[0]);
24 same_type<decltype(a2), int>();
25 decltype(auto) a3 = Is...[1];
26 same_type<decltype(a3), unsigned int>();
27 decltype(auto) a4 = (Is...[1]);
28 same_type<decltype(a4), unsigned int>();
29 decltype(auto) a5 = Is...[2];
30 same_type<decltype(a5), double>();
31 decltype(auto) a6 = (Is...[2]);
32 same_type<decltype(a6), double>();
33 decltype(auto) a7 = Is...[3];
34 same_type<decltype(a7), float>();
35 decltype(auto) a8 = (Is...[3]);
36 same_type<decltype(a8), float>();
37 decltype(auto) a9 = Is...[4];
38 same_type<decltype(a9), unsigned char>();
39 decltype(auto) a10 = (Is...[4]);
40 same_type<decltype(a10), unsigned char>();
41 }
42
43 static constexpr unsigned char c = 'A';
44
45 void
46 g ()
47 {
48 int i = 42;
49 fn1 (i, 42u);
50 fn2<0, 1u, 2.0, 3.f, c>();
51 }