Home Dashboard Directory Help
Search

Internal compiler error while compiling specific initializer of global object. by Waldemar Pawlaszek


Status: 

Closed
 as Fixed Help for as Fixed


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

Description

Internal compiler error occurs while compiling the following code:

#include <functional>

int fun( std::function<void()> f )
{
    return 0;
}

int b = fun( []() { int i = 0; } );

int main()
{
}


Required elements of the bug:
1. There must be a conversion of the lambda to std::function object to match function parameters,
2. lambda passed to the function must have initialization of automatic variable.
Details
Sign in to post a comment.
Posted by Waldemar Pawlaszek on 11/2/2011 at 1:04 AM
Thank you.

One question though. I've managed to replicate the error with similar (although little more complicated) code in VC11 Developer Preview. Does it mean that the bug has not been fixed prior to that release or this is a different issue?

Regards,
Waldemar Pawlaszek

Posted by Microsoft on 11/1/2011 at 1:16 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-Moderator09 [Feedback Moderator] on 10/28/2011 at 2:15 AM
Thank you for submitting feedback on Visual Studio 2010 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.
Posted by MS-Moderator01 on 10/28/2011 at 1:50 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.
Posted by Waldemar Pawlaszek on 10/28/2011 at 1:46 AM
Use a function factory:

#include <functional>

std::function<void()> factory()
{
    return []() { int i = 0; };
}

int fun( std::function<void()> f )
{
    return 0;
}

int b = fun( factory() );

int main()
{
}
Posted by Waldemar Pawlaszek on 10/28/2011 at 1:38 AM
Don't initialize the automatic variable in the lambda (of course it's only to point out when the compiler error disappears):

#include <functional>

int fun( std::function<void()> f )
{
    return 0;
}

int b = fun( []() { int i; } );

int main()
{
}
Posted by Waldemar Pawlaszek on 10/28/2011 at 1:32 AM
Make the helper function a template:

template< typename F >
int fun( F f )
{
    return 0;
}

int b = fun( []() { int i = 0; } );

int main()
{
}