C++ compiler bug: template and non template function overload resolution 
Author Message
 C++ compiler bug: template and non template function overload resolution

If I compile the following file:

template <class T> struct X
{
   X(T *);
   void f(X const &);
   template <class T2> void f(X<T2> const &);

Quote:
};

void g(X<char> & x)
{
   x.f(0);

Quote:
}

with the VS.Net compiler using "cl bug1.cpp" I get the following error
message on the call to x.f:

bug1.cpp(10) : error C2784: 'void X<T>::f(const X<T2> &)' : could not
deduce template argument for 'const X<<template parameter>> &' from
'int'
        with
        [
            T=char
        ]

I don't think this message is correct. It's true that the template
argument cannot be deduced, but that just means that the template
function f shouldn't be considered a candidate for overload
resolution, and so the non-templated version should be called (using
the X(T *) constructor to convert the argument). See 14.8.3/1 in the
standard, particularly where it says "If, for a given function
template, argument deduction fails, no such function is added to the
set of candidate functions for that template.".

Regards,

Alan



Tue, 01 Feb 2005 18:16:12 GMT  
 C++ compiler bug: template and non template function overload resolution
Thanks for reporting this. Yes, this is fixed in the compiler we have
referred to (but won't ship as) 7.1.

Ronald Laeremans
Visual C++ compiler and libraries team


Quote:
> If I compile the following file:

> template <class T> struct X
> {
>    X(T *);
>    void f(X const &);
>    template <class T2> void f(X<T2> const &);
> };

> void g(X<char> & x)
> {
>    x.f(0);
> }

> with the VS.Net compiler using "cl bug1.cpp" I get the following error
> message on the call to x.f:

> bug1.cpp(10) : error C2784: 'void X<T>::f(const X<T2> &)' : could not
> deduce template argument for 'const X<<template parameter>> &' from
> 'int'
>         with
>         [
>             T=char
>         ]

> I don't think this message is correct. It's true that the template
> argument cannot be deduced, but that just means that the template
> function f shouldn't be considered a candidate for overload
> resolution, and so the non-templated version should be called (using
> the X(T *) constructor to convert the argument). See 14.8.3/1 in the
> standard, particularly where it says "If, for a given function
> template, argument deduction fails, no such function is added to the
> set of candidate functions for that template.".

> Regards,

> Alan



Tue, 01 Feb 2005 21:19:42 GMT  
 C++ compiler bug: template and non template function overload resolution

Quote:
> I don't think this message is correct. It's true that the template
> argument cannot be deduced, but that just means that the template
> function f shouldn't be considered a candidate for overload
> resolution, and so the non-templated version should be called (using
> the X(T *) constructor to convert the argument). See 14.8.3/1 in the
> standard, particularly where it says "If, for a given function
> template, argument deduction fails, no such function is added to the
> set of candidate functions for that template.".

Definitely a bug, yep!

Comeau compiles it withouth error, as does the 13.10.2154.8 version (IA64
only) of the compiler that's in the PSDK.

-cd



Tue, 01 Feb 2005 21:23:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Compiler bug: Overloaded function template pattern matching

2. (Bug?) choosing between template and non-template version

3. Bug with overloaded function template

4. pb with template function in non template class

5. template member function - non template class - VC5 - error

6. Template function in non-template class

7. Template function in a non-template class

8. Template function in non-template class

9. template function inside template class bug

10. C2660 with template member function: Compiler bug?

11. BUG: Template Friend Function Causes Compiler Error C2248 still NOT CORRECTED in VC++6.0

12. template function compiler bug?

 

 
Powered by phpBB® Forum Software