Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/subscript6.C

raw
1 // P2128R6
2 // { dg-do run }
3 // { dg-options "-std=c++23" }
4 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
5
6 #include <initializer_list>
7 #include <cstdlib>
8
9 struct S
10 {
11 S () : a {} {};
12 int &operator[] (std::initializer_list<int> l, std::initializer_list<int> m) {
13 int sum = 0;
14 for (auto x : l)
15 sum += x;
16 for (auto x : m)
17 sum += x;
18 return a[sum];
19 }
20 int a[64];
21 };
22
23 int
24 main ()
25 {
26 S s;
27 if (&s[{0}, {3, 1, 2}] != &s.a[0 + 3 + 1 + 2]
28 || &s[{42}, {11, 1}] != &s.a[42 + 11 + 1]
29 || &s[{5, 7, 9}, {3}] != &s.a[5 + 7 + 9 + 3]
30 || &s[{1, 2, 3, 4}, {3, 5, 8}] != &s.a[1 + 2 + 3 + 4 + 3 + 5 + 8])
31 abort ();
32 }