Search

std::result_of not working with lambdas by Sylvester Hesp

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 689815
Opened: 9/20/2011 3:39:33 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
Consider the following piece of code

==============
#include <functional>

int main()
{
    auto f = [](int i) { return 0.f; };
    typedef decltype(f) f_type;
    std::result_of<f_type(int)>::type v;
}
==============

This fails to compile, and will result in the error:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2903: 'result' : symbol is neither a class template nor a function template

Apparently, a lambda doesn't define a result_type typedef. Now, C++11 doesn't say that it should, but then again, C++11 defines result_of<> using decltype(). Perhaps VC++ should implement result_of similarly? Or, in the mean time, simply add a result_type typedef to the compiler generated function object.
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Create a new C++ project, and compile this code:

#include <functional>

int main()
{
    auto f = [](int i) { return 0.f; };
    typedef decltype(f) f_type;
    std::result_of<f_type(int)>::type v;
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2903: 'result' : symbol is neither a class template nor a function template
1>         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40) : see reference to class template instantiation 'std::tr1::_Result_type1<__formal,_Fty,_Arg0>' being compiled
1>         with
1>         [
1>             __formal=false,
1>             _Fty=f_type,
1>             _Arg0=int &
1>         ]
1>         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(597) : see reference to class template instantiation 'std::tr1::_Result_of1<_Fty,_Farg0>' being compiled
1>         with
1>         [
1>             _Fty=f_type,
1>             _Farg0=int &
1>         ]
1>         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xrefwrap(28) : see reference to class template instantiation 'std::tr1::_Result_of<_Ty>' being compiled
1>         with
1>         [
1>             _Ty=`anonymous-namespace'::<lambda0> (int)
1>         ]
1>         main.cpp(7) : see reference to class template instantiation 'std::tr1::result_of<_Fty>' being compiled
1>         with
1>         [
1>             _Fty=f_type (int)
1>         ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2039: 'result' : is not a member of '`anonymous-namespace'::<lambda0>'
1>         main.cpp(5) : see declaration of '`anonymous-namespace'::<lambda0>'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2143: syntax error : missing ';' before '<'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2039: 'type' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2039: '_Type' : is not a member of 'std::tr1::_Result_type1<__formal,_Fty,_Arg0>'
1>         with
1>         [
1>             __formal=false,
1>             _Fty=f_type,
1>             _Arg0=int &
1>         ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2146: syntax error : missing ';' before identifier '_Type'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2602: 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type' is not a member of a base class of 'std::tr1::_Result_of1<_Fty,_Farg0>'
1>         with
1>         [
1>             _Fty=f_type,
1>             _Farg0=int &
1>         ]
1>         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40) : see declaration of 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type'
1>         with
1>         [
1>             _Fty=f_type,
1>             _Farg0=int &
1>         ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2868: 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type' : illegal syntax for using-declaration; expected qualified-name
1>         with
1>         [
1>             _Fty=f_type,
1>             _Farg0=int &
1>         ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected results

Should compile fine.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 9/21/2011 at 10:44 AM
Hi:
    This issue has been fixed and it should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by MS-Moderator07 [Feedback Moderator] on 9/20/2011 at 10:21 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 MS-Moderator01 on 9/20/2011 at 4:45 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.