Search

std::result_of not working with functors by NikLazarov

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 732529
Opened: 3/22/2012 1:43:49 AM
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>

struct F
{
    float operator()(int i) const { return float(i); }
};


int main()
{
    typedef ::std::result_of<F(int)>::type RetType;

    return 0;
}

It fails to compile.
This works fine with GCC 4.6. I know their implementation of result_of is different, but still... Also, GCC works both with and without "template" after "typedef"
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Try to compile:


#include <functional>

struct F
{
    float operator()(int i) const { return float(i); }
};


int main()
{
    typedef ::std::result_of<F(int)>::type RetType;

    return 0;
}

Product Language

English

Operating System

Windows XP

Operating System Language

English

Actual results

1>------ Rebuild All started: Project: vc2010, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files\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\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,
1>             _Arg0=int &
1>         ]
1>         c:\program files\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,
1>             _Farg0=int &
1>         ]
1>         c:\program files\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=F (int)
1>         ]
1>         c:\goldy\build\test\main.cpp(21) : see reference to class template instantiation 'std::tr1::result_of<_Fty>' being compiled
1>         with
1>         [
1>             _Fty=F (int)
1>         ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xxresult(28): error C2039: 'result' : is not a member of 'F'
1>         c:\goldy\build\test\main.cpp(11) : see declaration of 'F'
1>c:\program files\microsoft visual studio 10.0\vc\include\xxresult(28): error C2143: syntax error : missing ';' before '<'
1>c:\program files\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\microsoft visual studio 10.0\vc\include\xxresult(28): error C2039: 'type' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\xxresult(28): error C2238: unexpected token(s) preceding ';'
1>c:\program files\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,
1>             _Arg0=int &
1>         ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xxresult(40): error C2146: syntax error : missing ';' before identifier '_Type'
1>c:\program files\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\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,
1>             _Farg0=int &
1>         ]
1>         c:\program files\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,
1>             _Farg0=int &
1>         ]
1>c:\program files\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,
1>             _Farg0=int &
1>         ]
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Expected results

Should compile.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 3/22/2012 at 3:54 PM
Hi,

Thanks for reporting this bug. We've already fixed it in VC11 Beta.

result_of was originally specified by TR1, which was a set of library extensions that could be added to a C++98/03 compiler. In C++98/03, there's no way to tell what return type you'd get if you invoked a given functor with given arguments, so result_of was specified to follow a certain protocol. Given things like function pointers, result_of could automatically determine the return type. But given functors of class type, result_of needed the return type to be manually specified, through a result_type typedef. If you add "typedef float result_type;" to F, your code will compile in VC10 SP1.

In C++11, things are different and better. The Core Language has decltype, and result_of is now powered by it. This allows it to always get the correct return type, without programmer assistance. In VC11, we've changed our result_of implementation accordingly. (This is most important for lambdas, which are compiler-generated classes that don't have result_type typedefs.)

Although decltype was originally implemented in VC10, we didn't have time back then to change result_of to use it.

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 MS-Moderator08 [Feedback Moderator] on 3/22/2012 at 2:48 AM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.

Sign in to post a workaround.