PR c++/85553
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-ifunc-3.C
blob6d494244331278a257f75514cfec2097d3538f45
1 /* { dg-do run }  */
2 /* { dg-require-ifunc "" } */
3 /* { dg-options "-Wno-pmf-conversions" } */
5 #include <stdio.h>
7 struct Klass
9   int a[4];
11   int implementation ();
12   int magic ();
14   typedef int Func (Klass*);
16   static Func* resolver ();
19 int Klass::implementation (void)
21   printf ("'ere I am JH\n");
22   return a[0] + a[1] + a[2] + a[3];
25 Klass::Func* Klass::resolver ()
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.  */
31   return reinterpret_cast<Func*>(&Klass::implementation);
34 int Klass::magic (void) __attribute__ ((ifunc ("_ZN5Klass8resolverEv")));
36 int Foo (Klass &obj, int (Klass::*pmf) ())
38   return (obj.*pmf) ();
41 int main ()
43   Klass obj;
45   obj.a[0] = 1;
46   obj.a[1] = 2;
47   obj.a[2] = 3;
48   obj.a[3] = 4;
50   return Foo (obj, &Klass::magic) != 10;