aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/static-operator-call4.C
blob: 83ccde3b9c5b832b9d5f18e7798ef312692059e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// PR c++/107624
// { dg-do run { target c++11 } }
// { dg-options "" }

int n[3];
struct S {
  static void operator() (int x) { n[0] |= (1 << x); }	// { dg-warning "may be a static member function only with" "" { target c++20_down } }
  static void baz (int x) { n[1] |= (1 << x); }
  int s;
};
volatile S s[2];

S &
foo (int x)
{
  static S t;
  n[2] |= (1 << x);
  return t;
}

int
main ()
{
  int i = 0;
  foo (0) (0);
  if (n[0] != 1 || n[1] || n[2] != 1)
    __builtin_abort ();
  foo (1).baz (1);
  if (n[0] != 1 || n[1] != 2 || n[2] != 3)
    __builtin_abort ();
  s[i++] (2);
  if (i != 1 || n[0] != 5 || n[1] != 2 || n[2] != 3)
    __builtin_abort ();
  s[--i].baz (3);
  if (i != 0 || n[0] != 5 || n[1] != 10 || n[2] != 3)
    __builtin_abort ();
}