This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/5458: fails to cast to correct pointer type with overloading with templates



>Number:         5458
>Category:       c++
>Synopsis:       fails to cast to correct pointer type with overloading with templates
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 22 16:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Karl Nelson
>Release:        g++ version 3.0.3
>Organization:
>Environment:
All (platform independent)
>Description:
While attempting to use the std function ptr_fun on an overloaded function (sin), I found the compiler would fail if <complex> was included.  This traced to an error in the lookups of functions.  

Apparently, you can use template specifiers to choose
the overload only when a templated version of the 
function has not been encountered.  I boiled all of the 
headers down to the following example.  
ptr_fun<double>(&foo) only works if there is no
complex<T> version declared.  I verified this was 
valid code on HPUX compilers, but do not have access to 
the standard to clarify code is proper completely.

Example program generates incorrect error message.

kenelson:/tmp> g++-3 ptr_fun.cc 
ptr_fun.cc: In function `int main()':
ptr_fun.cc:7: no matching function for call to `ptr_fun(<unknown type>)'
>How-To-Repeat:
#include <complex>
template <class T> std::complex<T> foo(std::complex<T>) {}
void foo(int) {}
float foo(float) {}
template <class T_arg, class T_result>
void ptr_fun(T_result (*f)(T_arg)) {}
main() { ptr_fun<float>(foo);   }
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]