Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / operators4.C
blobd5613f15847d1cda222c253bb001410a0629e571
1 // { dg-do assemble  }
2 // { dg-options "" }
4 // GROUPS passed operators
5 // Check that the & operator, when applied to a global function
6 // or member function returns a proper value as long as the context
7 // in which the result of & is used requires a pointer to a specific
8 // unambigous (function-pointer) type.
9 //
10 // This test fails (in test5()) when compiled with g++ 1.34.1.
12 extern "C" int printf (const char *, ...); 
14 int function (char c);
15 int function (float f);
17 class base {
18         int filler;
19 public:
20         int method (char);
21         int method (float);
24 void* vp;
26 typedef int (*ptr_to_func_of_char)(char);
27 typedef int (*ptr_to_func_of_float)(float);
28 typedef int (base::*ptr_to_method_of_char)(char);
29 typedef int (base::*ptr_to_method_of_float)(float);
31 int test2 (void*);
32 int test3 (void*);
33 int test4 (void*);
34 int test5 (void*);
36 base* base_ptr;
38 int fail ()
40   printf ("FAIL\n");
41   return 1;
44 int main ()
46         base_ptr = new base;
48         ptr_to_func_of_char p0 = &function;
49         vp = (void*) p0;
50         if (test2 (vp))
51                 return fail ();
52         ptr_to_func_of_float p1 = &function;
53         vp = (void*) p1;
54         if (test3 (vp))
55                 return fail ();
56         ptr_to_method_of_char p2 = &base::method;
57         vp = (void*) p2; // { dg-error "" } 
58         if (test4 (vp))
59                 return fail ();
60         ptr_to_method_of_float p3 = &base::method;
61         vp = (void*) p3; // { dg-error "" } 
62         if (test5 (vp))
63                 return fail ();
65         printf ("PASS\n");
66         return 0;
69 int test2 (void* vp)
71         char ch = 'x';
73         return (((ptr_to_func_of_char)vp)(ch) !=  9901);
76 int test3 (void* vp)
78         float flt = 9.9;
80         return (((ptr_to_func_of_float)vp)(flt) !=  9902);
83 int test4 (void* vp)
85         char ch = 'x';
86         ptr_to_method_of_char p = (ptr_to_method_of_char) vp; // { dg-error "" } bad type conversion
88         return ((base_ptr->*p)(ch) !=  9904);
91 int test5 (void* vp)
93         float flt = 9.9;
94         ptr_to_method_of_float p = (ptr_to_method_of_float) vp; // { dg-error "" } bad type conversion
96         if ((base_ptr->*p)(flt) !=  9905) {
97                 return 1;
98         } else
99                 return 0;
102 int function (char c)
104         c = c;
105         return 9901;
108 int function (float f)
110         f = f;
111         return 9902;
114 int base::method (char c)
116         c = c;
117         return 9904;
120 int base::method (float f)
122         f = f;
123         return 9905;