public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: martin@xemacs.org
To: gcc-gnats@gcc.gnu.org
Subject: c++/9053: g++ confused about ambiguity of overloaded function templates
Date: Tue, 24 Dec 2002 10:36:00 -0000	[thread overview]
Message-ID: <20021224182715.1415.qmail@sources.redhat.com> (raw)


>Number:         9053
>Category:       c++
>Synopsis:       g++ confused about ambiguity of overloaded function templates
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 24 10:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Martin Buchholz
>Release:        g++ 3.2.1
>Organization:
>Environment:
Linux x86
>Description:
g++ must consider whether return types
of function templates lead to substitution failure
before giving an ambiguity error.  Considering only
arguments is insufficient.

These two function templates

template <class T> typename bar<T>::type foo (T);
template <class T> typename qux<T>::type foo (T);

look ambiguous, but may not be if, when instantiated
with a particular type, one of bar<T> or qux<T>
leads to substitution failure.

Easier to give an example than explain...

The code below compiles under icc and Comeau C++,
but not g++.

(Also: g++ gives ambiguity errors even if foo is never
instantiated, which is probably wrong.)

g++ gives:
ambiguous-template-bug2.cc:10: new declaration `template<class T> qux::type 
   foo(T)'
ambiguous-template-bug2.cc:7: ambiguates old declaration `template<class T> 
   bar::type foo(T)'


source code:

template <typename T> class bar;
template <> struct bar<const char*> { typedef void type; };
template <typename T> class qux;
template <> struct qux<int> { typedef void type; };

template <typename T>
typename bar<T>::type foo (T t) { }

template <typename T>
typename qux<T>::type foo (T t) { }


int
main (int argc, char *argv[])
{
  foo ("foo");
  foo (7);
}
>How-To-Repeat:
Compile source code with g++
>Fix:

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


             reply	other threads:[~2002-12-24 18:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-24 10:36 martin [this message]
2002-12-24 11:25 nathan
2002-12-24 14:11 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=20021224182715.1415.qmail@sources.redhat.com \
    --to=martin@xemacs.org \
    --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).