aboutsummaryrefslogtreecommitdiff
path: root/SingleSource/UnitTests/member-function-pointers.cpp
blob: 54e9a5f8f0831dba889823aec354b71d84ce2bb0 (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
#include <cstdio>

// Test for member function pointers.


struct A {
  virtual void f0() {
    printf("CHECK 0\n");
  }
  virtual void f1() {
    printf("CHECK 1\n");
  }
};
typedef void (A::*MFP)();

MFP f0_a() {
  return &A::f0;
}
MFP f0_b() {
  return &A::f1;
}
int main() {
  A a;

  // Check conversion to bool. We explicitly check a virtual function whose
  // offset will be 0, on some platforms this may be a corner case.
  MFP x = f0_a();
  MFP y = f0_b();
  if (x)
    (a.*x)();
  if (y)
    (a.*y)();

  return 0;
}