1 // PR c++/33616 2 // { dg-do run } 3 // { dg-options "-O2" } 4 5 extern "C" void abort (); 6 7 struct S { 8 int c; SS9 S () : c (0) {} f1S10 virtual void f1 () { c += 1; } f2S11 virtual void f2 () { c += 16; } 12 }; 13 14 struct T { 15 S s; 16 }; 17 18 typedef void (S::*Q) (); 19 20 template <Q P> test1(T * t)21void test1 (T *t) 22 { 23 (t->s.*P)(); 24 } 25 26 template <Q P> test2(T * t)27void test2 (T *t) 28 { 29 S &s = t->s; 30 (s.*P)(); 31 } 32 33 int main()34main () 35 { 36 T t; 37 test1 <&S::f1> (&t); 38 if (t.s.c != 1) 39 abort (); 40 test1 <&S::f2> (&t); 41 if (t.s.c != 17) 42 abort (); 43 test2 <&S::f1> (&t); 44 if (t.s.c != 18) 45 abort (); 46 test2 <&S::f2> (&t); 47 if (t.s.c != 34) 48 abort (); 49 } 50