Search

Lambda-to-function-pointer conversion fails in nested lambdas. by Dr Pizza

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 734303
Opened: 3/29/2012 1:30:54 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
VC++11 implements conversion from no-capture lambdas to function pointers, in accordance to the C++ specification. As an extension, it allows the conversion to use any calling convention, so that we can easily use lambdas with existing Win32 APIs.

However, there seem to be some problems with this. Nested lambdas do not appear to pick the calling convention correctly. They pick __cdecl even when I need __stdcall. My motivating example looked something like this:

CreateThread(nullptr, 0, [] (void*) -> DWORD {
    CreateThread(nullptr, 0, [] (void*) -> DWORD {
        return 0;
    }, nullptr, 0, nullptr);
    return 0;
}, nullptr, 0, nullptr);

The outer lambda converted correctly. The inner one did not.
Details (expand)

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

Visual Studio 11 Beta

Steps to reproduce

// Simple standalone example:
int main() {
    typedef void (__stdcall*FP)();
    FP x = []{}; // this converts correctly
    []{ FP y = []{}; }; // error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(void)' to 'FP'
}

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results

error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(void)' to 'FP'
         This conversion requires a reinterpret_cast, a C-style cast or function-style cast

Expected results

Successful compilation.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 4/20/2012 at 4:37 PM
Hello,

Thank you for reporting this bug. We've fixed it for current in-development compiler, which will be availabe in the next major release of VS, soon.

Thanks,
Ulzii Luvsanbat
Visual C++ Team
Posted by MS-Moderator08 [Feedback Moderator] on 3/29/2012 at 10:49 PM
Thank you for submitting feedback on Visual Studio 11 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 3/29/2012 at 1:54 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.