testsuite: 32 bit AIX 2 byte wchar
[official-gcc.git] / gcc / testsuite / g++.dg / cpp23 / subscript2.C
blobf8ec87d88efcb9d840179966cb1f1754aaa6a4b1
1 // P2128R6
2 // { dg-do compile }
3 // { dg-options "-std=c++23" }
5 struct S
7   S () : a {} {};
8   int &operator[] () { return a[0]; }
9   int &operator[] (int x) { return a[x]; }
10   int &operator[] (int x, long y) { return a[x + y * 8]; }
11   int a[64];
14 struct T
16   operator int () { return 42; };
19 int buf[64];
21 struct U
23   operator int * () { return buf; }
26 struct V
28   V () : a {} {};
29   V (int x, int y, int z) : a {x, y, z} {};
30   int &operator[] () { return a[0]; }                           // { dg-message "candidate" }
31   int &operator[] (int x, long y) { return a[x + y * 8]; }      // { dg-message "candidate" }
32   int a[64];
35 void
36 foo ()
38   S s;
39   T t;
40   U u;
41   V v;
42   auto &a = buf[];              // { dg-error "built-in subscript operator without expression list" }
43   auto &b = buf[1, 2];          // { dg-warning "top-level comma expression in array subscript changed meaning in" }
44   auto &c = s[1, 2, 3];         // { dg-warning "top-level comma expression in array subscript changed meaning in" }
45   auto &d = v[1];               // { dg-error "no match for 'operator\\\[\\\]' in 'v\\\[1\\\]' \\\(operand types are 'V' and 'int'\\\)" }
46   auto &e = v[1, 2, 3];         // { dg-error "no match for call to 'V::operator\\\[\\\] \\\(int, int, int\\\)'" }
47   auto &f = t[42, u];           // { dg-warning "top-level comma expression in array subscript changed meaning in" }
48   auto &g = u[42, t];           // { dg-warning "top-level comma expression in array subscript changed meaning in" }
49   auto &h = buf[42, 2.5];       // { dg-warning "top-level comma expression in array subscript changed meaning in" }
50                                 // { dg-error "invalid types \[^\n\r]* for array subscript" "" { target *-*-* } .-1 }