Search

C++ - fatal error C1001 when using static local variable with non-trivial constructor in static local lambda by c9xeo

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 715680
Opened: 12/27/2011 10:24:26 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The following snippet triggers an internal compiler error when the static local variable 'n' has a non-trivial constructor.

struct nontrivial{
    nontrivial(){}
};

int main(){
    static auto ICE = []()->int{
        static nontrivial n; // comment out to resolve error
        return 0;
    };
}

If the static local variable is changed to a type that has a trivial constructor, or if the lambda is changed to non-static, the compilation succeeds as expected.
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Copy + paste above code, build.

Product Language

English

Operating System

Windows 7

Operating System Language

German

Actual results

fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1420)

Expected results

Successful compilation
File Attachments
0 attachments
Sign in to post a comment.
Posted by c9xeo on 12/29/2011 at 5:57 PM
That's... very interesting, that a simple additional static local variable with a trivial constructor fixes it. Thanks!
Posted by Microsoft on 12/29/2011 at 4:25 PM
Hi Philipp:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.
    Here is one of the possible workaround:

struct nontrivial{
    nontrivial(){}
};

int main(){
    static auto ICE = []()->int{
        static nontrivial n; // comment out to resolve error
        static int i = 0; // workaround
        return 0;
    };
}

Xiang Fan
Visual C++ Team
Posted by MS-Moderator08 [Feedback Moderator] on 12/28/2011 at 1:06 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 investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 12/27/2011 at 10:42 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.