Debian Codegraph @

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

raw
1 // P2128R6
2 // { dg-do run }
3 // { dg-options "-std=c++23" }
4
5 extern "C" void abort ();
6
7 struct S
8 {
9 constexpr S () : a {} {};
10 constexpr S (int x, int y, int z) : a {x, y, z} {};
11 constexpr int &operator[] () { return a[0]; }
12 constexpr int &operator[] (int x) { return a[x]; }
13 constexpr int &operator[] (int x, long y) { return a[x + y * 8]; }
14 int a[64];
15 };
16 int buf[26];
17
18 template <class ...Ts>
19 auto &
20 foo (S &s, Ts... args)
21 {
22 return s[args...];
23 }
24
25 template <typename T, class ...Ts>
26 auto &
27 bar (T &s, Ts... args)
28 {
29 return s[args...];
30 }
31
32 int
33 main ()
34 {
35 S s;
36 if (&foo (s) != &s.a[0]
37 || &foo (s, 42) != &s.a[42]
38 || &foo (s, 5, 4) != &s.a[37]
39 || &bar (s) != &s.a[0]
40 || &bar (s, 22) != &s.a[22]
41 || &bar (s, 17, 3L) != &s.a[41]
42 || &bar (buf, 5) != &buf[5])
43 abort ();
44 }