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++/9053: g++ confused about ambiguity of overloaded function templates


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


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