| 1 |
// PR c++/108437 |
| 2 |
// { dg-do run { target c++23 } } |
| 3 |
|
| 4 |
struct S { static int &operator[] (int x) { static int a[2]; return a[x]; } }; |
| 5 |
struct U { static int &operator[] (int x, int y, int z) { static int a[2]; return a[x + y + z]; } }; |
| 6 |
struct V { static int &operator[] () { static int a; return a; } }; |
| 7 |
int cnt; |
| 8 |
|
| 9 |
template <typename T> |
| 10 |
T & |
| 11 |
bar (T &x) |
| 12 |
{ |
| 13 |
++cnt; |
| 14 |
return x; |
| 15 |
} |
| 16 |
|
| 17 |
template <class T, class W, class X> void |
| 18 |
foo () |
| 19 |
{ |
| 20 |
S s; |
| 21 |
bar (s)[0]++; |
| 22 |
T t; |
| 23 |
bar (t)[0]++; |
| 24 |
U u; |
| 25 |
bar (u)[0, 0, 0]++; |
| 26 |
V v; |
| 27 |
bar (v)[]++; |
| 28 |
W w; |
| 29 |
bar (w)[0, 0, 0]++; |
| 30 |
X x; |
| 31 |
bar (x)[]++; |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main () |
| 36 |
{ |
| 37 |
S::operator[] (0) = 1; |
| 38 |
U::operator[] (0, 0, 0) = 2; |
| 39 |
V::operator[] () = 3; |
| 40 |
foo <S, U, V> (); |
| 41 |
if (S::operator[] (0) != 3 || U::operator[] (0, 0, 0) != 4 || V::operator[] () != 5 || cnt != 6) |
| 42 |
__builtin_abort (); |
| 43 |
} |