Home Dashboard Directory Help

Visual Studio 2010 C++: Static objects imported via using directives in lambdas cause compilation issues! by srbr27


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 741267
Opened: 5/8/2012 10:15:31 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
User(s) can reproduce this bug


The following piece of code causes a C2065: 'cout' : undeclared identifier.
#include <iostream>
#include <algorithm>

int main() {
using namespace std;
int a[] = { 1, 2, 3 };
for_each(&a[0], &a[0] + 3, [](int i){ cout << i << “\n”; });
As per §5.1.2/3, the closure type of the lambda is declared in main. (Nit: `cout` being a static object and the capture clause being empty guarantees no capture takes place.) However, since the using directive should ideally make `cout` available not only to main but also to the lambda.

This issue is not reproducible in Visual Studio 2011 beta.
Sign in to post a comment.
Posted by Microsoft on 5/9/2012 at 11:11 AM
    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-Moderator07 [Feedback Moderator] on 5/9/2012 at 2:24 AM
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 MS-Moderator01 on 5/8/2012 at 10:43 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.