Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/subscript14.C

raw
1 // PR c++/109319
2 // { dg-do compile { target c++11 } }
3 // { dg-options "" }
4
5 struct A { static int &operator[] (int x) { static int a[2]; return a[x]; } }; // { dg-warning "may be a static member function only with" "" { target c++20_down } }
6 struct B { int &operator[] (int x) { static int b[2]; return b[x]; } };
7 int c[2];
8
9 template <typename T, typename U, typename V>
10 int
11 foo ()
12 {
13 A a;
14 ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
15 B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
16 ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
17 // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
18 ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
19 T d; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
20 ++d[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
21 U e; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
22 ++e[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
23 extern V f[2]; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
24 ++f[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
25 return 0; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
26 }
27
28 int f[2];
29
30 int
31 main ()
32 {
33 A a;
34 ++a[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
35 B b; // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
36 ++b[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
37 // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
38 ++c[0, 1]; // { dg-warning "top-level comma expression in array subscript changed meaning" "" { target c++23 } }
39 foo <A, B, int> (); // { dg-warning "top-level comma expression in array subscript is deprecated" "" { target c++20_only } .-1 }
40 if (a.operator[] (1) != 3 || b.operator[] (1) != 3 || c[1] != 2 || f[1] != 1)
41 __builtin_abort ();
42 }