aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/subscript4.C
blob: 085095d9dee6594bb4fcc4343ff06a63e9bc5c20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// P2128R6
// { dg-do run }
// { dg-options "-std=c++23" }

extern "C" void abort ();

struct S
{
  constexpr S () : a {} {};
  constexpr S (int x, int y, int z) : a {x, y, z} {};
  constexpr int &operator[] () { return a[0]; }
  constexpr int &operator[] (int x) { return a[x]; }
  constexpr int &operator[] (int x, long y) { return a[x + y * 8]; }
  int a[64];
};
int buf[26];

template <class ...Ts>
auto &
foo (S &s, Ts... args)
{
  return s[args...];
}

template <typename T, class ...Ts>
auto &
bar (T &s, Ts... args)
{
  return s[args...];
}

int
main ()
{
  S s;
  if (&foo (s) != &s.a[0]
      || &foo (s, 42) != &s.a[42]
      || &foo (s, 5, 4) != &s.a[37]
      || &bar (s) != &s.a[0]
      || &bar (s, 22) != &s.a[22]
      || &bar (s, 17, 3L) != &s.a[41]
      || &bar (buf, 5) != &buf[5])
    abort ();
}