Home Dashboard Directory Help
Search

Auto type deduction gets confused for multiple variables by CornedBee


Status: 

Closed
 as Fixed Help for as Fixed


1
1
Sign in
to vote
Type: Bug
ID: 728741
Opened: 3/5/2012 2:02:15 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Consider:

void fn(const std::vector<std::wstring>& v)
{
    for (auto it = v.begin(), e = v.end(); it != e; ++it) {
    }
}

This simple snippet works and does what it should: iterate over all elements of the vector.
Now change it so that it skips the first element:

void fn(const std::vector<std::wstring>& v)
{
    for (auto it = v.begin() + 1, e = v.end(); it != e; ++it) {
    }
}

and the compiler issues an error:
1> error C3538: in a declarator-list 'auto' must always deduce to the same type
1>         could be 'std::_Vector_const_iterator<_Myvec>'
1>         with
1>         [
1>             _Myvec=std::_Vector_val<std::wstring,std::allocator<std::wstring>>
1>         ]
1>         or     'std::_Vector_const_iterator<_Myvec>'
1>         with
1>         [
1>             _Myvec=std::_Vector_val<std::wstring,std::allocator<std::wstring>>
1>         ]

So although it still seems like it deduces the same type for both it and e, it complains.
Details
Sign in to post a comment.
Posted by CornedBee on 3/8/2012 at 2:13 AM
Thank you. I'm impressed at the speed at which this got fixed.

Just to be clear: "next release" means the RTM of VS 2012, right?
Posted by Microsoft on 3/7/2012 at 12:07 PM
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-Moderator10 [Feedback Moderator] on 3/5/2012 at 9:45 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-Moderator10 on 3/5/2012 at 6:01 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.