1 /* { dg-do run } */ 2 /* { dg-require-ifunc "" } */ 3 /* { dg-options "-Wno-pmf-conversions" } */ 4 5 #include <stdio.h> 6 7 struct Klass 8 { 9 int a[4]; 10 11 int implementation (); 12 int magic (); 13 14 typedef int Func (Klass*); 15 16 static Func* resolver (); 17 }; 18 implementation(void)19int Klass::implementation (void) 20 { 21 printf ("'ere I am JH\n"); 22 return a[0] + a[1] + a[2] + a[3]; 23 } 24 resolver()25Klass::Func* Klass::resolver () 26 { 27 /* GCC guarantees this conversion to be safe and the resulting pointer 28 usable to call the member function using ordinary (i.e., non-member) 29 function call syntax. */ 30 31 return reinterpret_cast<Func*>(&Klass::implementation); 32 } 33 34 int Klass::magic (void) __attribute__ ((ifunc ("_ZN5Klass8resolverEv"))); 35 Foo(Klass & obj,int (Klass::* pmf)())36int Foo (Klass &obj, int (Klass::*pmf) ()) 37 { 38 return (obj.*pmf) (); 39 } 40 main()41int main () 42 { 43 Klass obj; 44 45 obj.a[0] = 1; 46 obj.a[1] = 2; 47 obj.a[2] = 3; 48 obj.a[3] = 4; 49 50 return Foo (obj, &Klass::magic) != 10; 51 } 52