Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/static-operator-call4.C

raw
1 // PR c++/107624
2 // { dg-do run { target c++11 } }
3 // { dg-options "" }
4
5 int n[3];
6 struct S {
7 static void operator() (int x) { n[0] |= (1 << x); } // { dg-warning "may be a static member function only with" "" { target c++20_down } }
8 static void baz (int x) { n[1] |= (1 << x); }
9 int s;
10 };
11 volatile S s[2];
12
13 S &
14 foo (int x)
15 {
16 static S t;
17 n[2] |= (1 << x);
18 return t;
19 }
20
21 int
22 main ()
23 {
24 int i = 0;
25 foo (0) (0);
26 if (n[0] != 1 || n[1] || n[2] != 1)
27 __builtin_abort ();
28 foo (1).baz (1);
29 if (n[0] != 1 || n[1] != 2 || n[2] != 3)
30 __builtin_abort ();
31 s[i++] (2);
32 if (i != 1 || n[0] != 5 || n[1] != 2 || n[2] != 3)
33 __builtin_abort ();
34 s[--i].baz (3);
35 if (i != 0 || n[0] != 5 || n[1] != 10 || n[2] != 3)
36 __builtin_abort ();
37 }