[PR c++/84702] ICE with default tmpl arg of overload set
[official-gcc.git] / gcc / testsuite / g++.dg / ext / attr-ifunc-1.C
blob4a29e8bb4d69aef2aff03266b16c7d00dd2f1c19
1 /* { dg-do run }  */
2 /* { dg-require-ifunc "" } */
3 /* { dg-options "-Wno-pmf-conversions" } */
5 struct Klass
7   int a[4];
9   int implementation ();
10   int magic ();
12   /* An ifunc resolver must return a pointer to an ordinary (non-member)
13      function.  To make it possible to use ifunc with member functions,
14      the resolver must convert a member function pointer to an ordinary
15      function pointer (slicing off the high word).  */
16   typedef int Func (Klass*);
18   static Func* resolver ();
21 int Klass::implementation ()
23   __builtin_printf ("'ere I am JH\n");
24   return a[0] + a[1] + a[2] + a[3];
27 Klass::Func* Klass::resolver (void)
29   /* GCC guarantees this conversion to be safe and the resulting pointer
30      usable to call the member function using ordinary (i.e., non-member)
31      function call syntax.  */
33   return reinterpret_cast<Func*>(&Klass::implementation);
36 int f (void) __attribute__ ((ifunc ("foo")));
38 typedef int (F)(void);
39 extern "C" F* foo () { return 0; }
42 int Klass::magic () __attribute__ ((ifunc ("_ZN5Klass8resolverEv")));
44 int main ()
46   Klass obj;
48   obj.a[0] = 1;
49   obj.a[1] = 2;
50   obj.a[2] = 3;
51   obj.a[3] = 4;
53   return !(obj.magic () == 10);