testsuite: 32 bit AIX 2 byte wchar
[official-gcc.git] / gcc / testsuite / g++.dg / cpp23 / subscript3.C
blob2d735e4e0e0ca347b68df680bc9f995c3dda5e49
1 // P2128R6
2 // { dg-do run }
3 // { dg-options "-std=c++23" }
5 extern "C" void abort ();
7 struct S
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];
17 struct T
19   operator int () { return 42; };
22 int buf[64];
24 struct U
26   operator int * () { return buf; }
29 template <int N>
30 void
31 foo ()
33   static_assert (S ()[1] == 0);
34   static_assert (S (1, 2, 42)[2] == 42);
35   static_assert (S ()[3, 4] == 0);
36   static_assert (S (1, 43, 2)[1, 0] == 43);
37   static_assert (S ()[] == 0);
38   static_assert (S (44, 1, 2)[] == 44);
39   S s;
40   for (int i = 0; i < 64; i++)
41     s.a[i] = 64 - i;
42   if (s[] != 64 || s[3] != 61 || s[4, 5] != 20)
43     abort ();
44   s[]++;
45   s[42]++;
46   ++s[3, 2];
47   if (s.a[0] != 65 || s.a[42] != 23 || s.a[19] != 46)
48     abort ();
49   T t;
50   U u;
51   if (&u[t] != &buf[42])
52     abort ();
53   if (&t[u] != &buf[42])
54     abort ();
57 template <typename V, typename W, typename X>
58 void
59 bar ()
61   static_assert (V ()[1] == 0);
62   static_assert (V (1, 2, 42)[2] == 42);
63   static_assert (V ()[3, 4] == 0);
64   static_assert (V (1, 43, 2)[1, 0] == 43);
65   static_assert (V ()[] == 0);
66   static_assert (V (44, 1, 2)[] == 44);
67   V s;
68   for (int i = 0; i < 64; i++)
69     s.a[i] = 64 - i;
70   if (s[] != 64 || s[3] != 61 || s[4, 5] != 20)
71     abort ();
72   s[]++;
73   s[42]++;
74   ++s[3, 2];
75   if (s.a[0] != 65 || s.a[42] != 23 || s.a[19] != 46)
76     abort ();
77   W t;
78   X u;
79   if (&u[t] != &buf[42])
80     abort ();
81   if (&t[u] != &buf[42])
82     abort ();
85 int
86 main ()
88   foo <0> ();
89   bar <S, T, U> ();