Bug with function cast!

Francois flessard@microtec.net
Fri Jun 11 06:11:00 GMT 1999


The following code produces the error message: 
conversion from void (*)(const int&) to non-scalar type, when using either 
gcc-2.8.1 or egcs-1.1.2 on a SUN machine with Solaris version 2.5:
 
// BUG with function cast syntax within template 
class. // template <class T> void apply1(void 
(*applyFunc)(T&)) { } template <class T> void 
apply(void (*applyFunc)(const T&)) {   apply1((void 
(*)(T&))applyFunc); } void applyFun(const int& 
i) { } int main(void) {   
apply(&applyFun); }
 
Compilation was done with the following command: 
g++ CppBugs.cxx, where CppBugs.cxx is the name of the source file containing the 
code above.
 
By the way, such function casts are accepted in 
non-template code. For example, the following code compiles 
successfully:
 

void apply1(void 
(*applyFunc)(int&)) { } void apply(void (*applyFunc)(const 
int&)) {   apply1((void 
(*)(int&))applyFunc); } void applyFun(const int& 
i) { } int main(void) {   
apply(&applyFun); }



More information about the Gcc-bugs mailing list