2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / operators4.C
blob1f033a6bb79de9e76c08e77afccf45cdf9e27987
1 // { dg-do assemble  }
2 // GROUPS passed operators
3 // Check that the & operator, when applied to a global function
4 // or member function returns a proper value as long as the context
5 // in which the result of & is used requires a pointer to a specific
6 // unambigous (function-pointer) type.
7 //
8 // This test fails (in test5()) when compiled with g++ 1.34.1.
10 extern "C" int printf (const char *, ...); 
12 int function (char c);
13 int function (float f);
15 class base {
16         int filler;
17 public:
18         int method (char);
19         int method (float);
22 void* vp;
24 typedef int (*ptr_to_func_of_char)(char);
25 typedef int (*ptr_to_func_of_float)(float);
26 typedef int (base::*ptr_to_method_of_char)(char);
27 typedef int (base::*ptr_to_method_of_float)(float);
29 int test2 (void*);
30 int test3 (void*);
31 int test4 (void*);
32 int test5 (void*);
34 base* base_ptr;
36 int fail ()
38   printf ("FAIL\n");
39   return 1;
42 int main ()
44         base_ptr = new base;
46         ptr_to_func_of_char p0 = &function;
47         vp = (void*) p0;
48         if (test2 (vp))
49                 return fail ();
50         ptr_to_func_of_float p1 = &function;
51         vp = (void*) p1;
52         if (test3 (vp))
53                 return fail ();
54         ptr_to_method_of_char p2 = &base::method;
55         vp = (void*) p2; // { dg-error "" } 
56         if (test4 (vp))
57                 return fail ();
58         ptr_to_method_of_float p3 = &base::method;
59         vp = (void*) p3; // { dg-error "" } 
60         if (test5 (vp))
61                 return fail ();
63         printf ("PASS\n");
64         return 0;
67 int test2 (void* vp)
69         char ch = 'x';
71         return (((ptr_to_func_of_char)vp)(ch) !=  9901);
74 int test3 (void* vp)
76         float flt = 9.9;
78         return (((ptr_to_func_of_float)vp)(flt) !=  9902);
81 int test4 (void* vp)
83         char ch = 'x';
84         ptr_to_method_of_char p = (ptr_to_method_of_char) vp; // { dg-error "" } bad type conversion
86         return ((base_ptr->*p)(ch) !=  9904);
89 int test5 (void* vp)
91         float flt = 9.9;
92         ptr_to_method_of_float p = (ptr_to_method_of_float) vp; // { dg-error "" } bad type conversion
94         if ((base_ptr->*p)(flt) !=  9905) {
95                 return 1;
96         } else
97                 return 0;
100 int function (char c)
102         c = c;
103         return 9901;
106 int function (float f)
108         f = f;
109         return 9902;
112 int base::method (char c)
114         c = c;
115         return 9904;
118 int base::method (float f)
120         f = f;
121         return 9905;