Search

VC++ cannot resolve function overload as template parameter by goffioul

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 697006
Opened: 10/27/2011 1:52:33 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
When using function as template parameter, along with template overload with different function signatures, VC++ is unable to resolve the function template parameter correctly. The following piece of code illustrates the issue:

#include <cmath>
#include <complex>
#include <iostream>

template <class T>
class A
{
public:
        A (T t) : _t (t) { }
        A (const A& a) : _t (a._t) { }
        A& operator= (const A& a)
        {
                _t = a._t;
                return *this;
        }

        T val (void) const { return _t; }

private:
        T _t;
};

template <class R, class T, R fun (T)>
inline A<R> mapper (const A<T>& a)
{
        return A<R> (fun (a.val ()));
}

template <class R, class T, R fun (const T&)>
inline A<R> mapper (const A<T>& a)
{
        return A<R> (fun (a.val ()));
}

int main (int argc, char **argv)
{
        A<double> d (-1);
        A< std::complex<double> > c (std::complex<double> (1, 1));

        std::cout << d.val () << " -> " << mapper<double, double, std::abs> (d).val () << std::endl;
        std::cout << c.val () << " -> " << mapper<double, std::complex<double>, std::abs> (c).val () << std::endl;

        return 0;
}
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010

Steps to reproduce

Try to compile the sample code in the description.

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

Set of compilation errors: C2563, C2440, C2973, C2668.

Expected results

The code compiles fine.
File Attachments
File Name Submitted By Submitted On File Size  
test.cpp 10/27/2011 951 bytes
test.cpp 10/27/2011 951 bytes
test2.cpp 11/29/2011 2 KB
test2.cpp 11/29/2011 2 KB
Sign in to post a comment.
Posted by goffioul on 11/29/2011 at 3:14 AM
Great. Will the fix also solve the compilation issues with this second (similar) example? (see attached file test2.cpp). Or shall I open another bug report for it?
Posted by Microsoft on 11/15/2011 at 10:13 AM
Hi:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by MS-Moderator08 [Feedback Moderator] on 10/27/2011 at 8:26 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 10/27/2011 at 2:47 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.