Debian Codegraph @

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

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