Search

Initializer list in a lambda crashes by BudVVeezer

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 743303
Opened: 5/23/2012 9:39:59 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The following reduced testcase produces an ICE with the compiler. If you modify the code slightly, it produces an incorrect compile error.
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

struct foo {
void *bar;
};
auto str = ([]() -> int { static const foo val = { nullptr }; return 0; }()); // 1
auto str = ([]() -> int { static const struct foo val = { 0 }; return 0; }()); // 2

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

The first example crashes the compiler. The second example incorrectly emits the following diagnostic:

error C2552: 'val' : non-aggregates cannot be initialized with initializer list
'`anonymous-namespace'::<lambda0>::()::foo' : Types with user defined constructors are not aggregate

Expected results

I'd expect this to work without crashing.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/24/2012 at 10:25 AM
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-Moderator10 [Feedback Moderator] on 5/23/2012 at 11:25 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 BudVVeezer on 5/23/2012 at 10:21 AM
Also note that moving the structure declaration to the top level changes the behavior.

1) Local to function == causes crash/error
2) At translation unit level, with static const declaration == causes internal error with the compiler

fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\p2symtab.c', line 5858)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information

3) At translation unit level, without static const declaration == compiles cleanly
Posted by MS-Moderator01 on 5/23/2012 at 9:42 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)
Posted by BudVVeezer on 5/23/2012 at 9:41 AM
Note that removing the static const has no effect on the outcome.
Sign in to post a workaround.