Search

Incorrect Overload Resolution by WorkingHorse

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 606746
Opened: 9/29/2010 11:13:57 AM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
The C++ compiler cannot match the correct overload for the std::transform template in the algorithm library -- this is just one example, there are no doubt others where code that used to work in Visual Studio 2005 no longer works in 2010.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

Open up Visual Studio 2010 and create a C++ project using the Win32 Console Application wizard. Then, enter the following code in your main .cpp file:

#include <vector>
#include <map>
#include <algorithm>
#include <iterator>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    vector<string> a;
    vector<string> b;
    map<string, string> c;

    // Populate vectors

    transform(a.begin(), a.end(), b.begin(), inserter(c, c.begin()), make_pair<string, string>);

    return 0;
}

Finally, attempt to compile this program.

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

The compiler fails with the following error sequence:

1>------ Build started: Project: Test Vector To Map, Configuration: Debug Win32 ------
1> Test Vector To Map.cpp
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_InTy (&)[_InSize]' from 'std::_Vector_iterator<_Myvec>'
1>         with
1>         [
1>             _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1>         ]
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1293) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutTy *std::transform(_InIt1,_InIt1,_InIt2,_OutTy (&)[_OutSize],_Fn2)' : could not deduce template argument for '_OutTy (&)[_OutSize]' from 'std::insert_iterator<_Container>'
1>         with
1>         [
1>             _Container=std::map<std::string,std::string>
1>         ]
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1279) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InTy (&)[_InSize],_OutIt,_Fn2)' : could not deduce template argument for '_InTy (&)[_InSize]' from 'std::_Vector_iterator<_Myvec>'
1>         with
1>         [
1>             _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1>         ]
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1267) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2914: 'std::transform' : cannot deduce template argument as function argument is ambiguous
1>c:\test vector to map\test vector to map.cpp(22): error C2784: '_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::insert_iterator<_Container>'
1>         with
1>         [
1>             _Container=std::map<std::string,std::string>
1>         ]
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1249) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2780: '_OutTy *std::transform(_InIt,_InIt,_OutTy (&)[_OutSize],_Fn1)' : expects 4 arguments - 5 provided
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1127) : see declaration of 'std::transform'
1>c:\test vector to map\test vector to map.cpp(22): error C2780: '_OutIt std::transform(_InIt,_InIt,_OutIt,_Fn1)' : expects 4 arguments - 5 provided
1>         c:\program files\microsoft visual studio 10.0\vc\include\algorithm(1111) : see declaration of 'std::transform'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected results

The compiler should match the std::transform template against the definition:

template<class _InIt1,
    class _InIt2,
    class _OutIt,
    class _Fn2> inline
    _OutIt transform(_InIt1 _First1, _InIt1 _Last1,
        _InIt2 _First2, _OutIt _Dest, _Fn2 _Func);
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/16/2011 at 8:11 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11. Note that due to changes between C++98/03 and C++0x, you'll have to use either make_pair<string&, string&> or make_pair<const string&, const string&>. Here's an example:

C:\Temp>type meow.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void print(const map<string, string>& m) {
    for (auto i = m.begin(); i != m.end(); ++i) {
        cout << "(" << i->first << ", " << i->second << ")" << endl;
    }
}

int main() {
    vector<string> series;
    series.push_back("TOS");
    series.push_back("TNG");
    series.push_back("DS9");
    series.push_back("VOY");
    series.push_back("ENT");

    vector<string> captains;
    captains.push_back("Kirk");
    captains.push_back("Picard");
    captains.push_back("Sisko");
    captains.push_back("Janeway");
    captains.push_back("Archer");

    map<string, string> m;

    transform(series.begin(), series.end(), captains.begin(), inserter(m, m.end()), make_pair<string&, string&>);

    print(m);

    cout << "-----" << endl;
    m.clear();

    const vector<string> vs = series;
    const vector<string> vc = captains;

    transform(vc.begin(), vc.end(), vs.begin(), inserter(m, m.end()), make_pair<const string&, const string&>);

    print(m);
}

C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp

C:\Temp>meow
(DS9, Sisko)
(ENT, Archer)
(TNG, Picard)
(TOS, Kirk)
(VOY, Janeway)
-----
(Archer, ENT)
(Janeway, VOY)
(Kirk, TOS)
(Picard, TNG)
(Sisko, DS9)

Also, please note that the STL's headers include each other in unspecified ways, so you should always be careful to include the headers that you need (e.g. <string> for string and <utility> for make_pair).

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 9/29/2010 at 7:44 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will

follow-up with your issue.

Posted by Microsoft on 9/29/2010 at 6:23 PM
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.