view gcc/testsuite/g++.dg/template/ptrmem18.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

// 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 ();
}