Search

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

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)
1
User(s) can reproduce this bug
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 (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Compile the code mentioned in description.

Product Language

English

Operating System

Windows 7

Operating System Language

Polish

Actual results

d:\>cl bug.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

bug.cpp
bug.cpp(8) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1420)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Internal Compiler Error in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe. You will be prompted to send an error report to Microsoft later.

Expected results

Successful compilation.
File Attachments
0 attachments
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()
{
}