public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: kenelson@ece.ucdavis.edu
To: gcc-gnats@gcc.gnu.org
Subject: c++/5458: fails to cast to correct pointer type with overloading with templates
Date: Tue, 22 Jan 2002 16:26:00 -0000	[thread overview]
Message-ID: <20020123002040.4823.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-01-23  0:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-22 16:26 kenelson [this message]
2002-04-25  7:44 nathan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020123002040.4823.qmail@sources.redhat.com \
    --to=kenelson@ece.ucdavis.edu \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).