aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/subscript5.C
blob: eac6a2457280f8cc292698784b4fc6d19f6a89d2 (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
// P2128R6
// { dg-do run { target c++11 } }
// { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }

#include <initializer_list>
#include <cstdlib>

struct S
{
  S () : a {} {};
  int &operator[] (std::initializer_list<int> l) {
    int sum = 0;
    for (auto x : l)
      sum += x;
    return a[sum];
  }
  int a[64];
};

int
main ()
{
  S s;
  if (&s[{0}] != &s.a[0]
      || &s[{42}] != &s.a[42]
      || &s[{5, 7, 9}] != &s.a[5 + 7 + 9]
      || &s[{1, 2, 3, 4}] != &s.a[1 + 2 + 3 + 4])
    abort ();
}