summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/template/ptrmem18.C
blob: c3124cd81bfc932b6899f8ab29025ca4cba16c14 (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
38
39
40
41
42
43
44
45
46
47
48
49
// PR c++/33616
// { dg-do run }
// { dg-options "-O2" }

extern "C" void abort ();

struct S {
  int c;
  S () : c (0) {}
  virtual void f1 () { c += 1; }
  virtual void f2 () { c += 16; }
};

struct T {
  S s;
};

typedef void (S::*Q) ();

template <Q P>
void test1 (T *t)
{
  (t->s.*P)();
}

template <Q P>
void test2 (T *t)
{
  S &s = t->s;
  (s.*P)();
}

int
main ()
{
  T t;
  test1 <&S::f1> (&t);
  if (t.s.c != 1)
    abort ();
  test1 <&S::f2> (&t);
  if (t.s.c != 17)
    abort ();
  test2 <&S::f1> (&t);
  if (t.s.c != 18)
    abort ();
  test2 <&S::f2> (&t);
  if (t.s.c != 34)
    abort ();
}