[llvm-bugs] [Bug 38285] New: clang-cl does not automatically convert a non-capturing lambda to a function pointer with a specific calling convention

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 24 02:15:38 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38285

            Bug ID: 38285
           Summary: clang-cl does not automatically convert a
                    non-capturing lambda to a function pointer with a
                    specific calling convention
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jeroen.ketema at philips.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20594
  --> https://bugs.llvm.org/attachment.cgi?id=20594&action=edit
Source file with de code from the description

cl.exe allows for a non-capturing lambda to be converted to a function pointer
with any calling convention. For example, the following compiles with cl.exe.

```
> type foo.cpp
typedef int (__stdcall * FuncType)(int p);

FuncType func;

int main() {
  func = [](int p) { return p + 1; };
  return 0;
}
```

```
> cl.exe foo.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

foo.cpp
Microsoft (R) Incremental Linker Version 14.00.24215.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:foo.exe
foo.obj
```

clang-cl does not allow this:

```
> clang-cl.exe -m32 foo.cpp
foo.cpp(6,10):  error: assigning to 'FuncType' (aka 'int (*)(int)
      __attribute__((stdcall))') from incompatible type
      '(lambda at foo.cpp:6:10)'
  func = [](int p) { return p + 1; };
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```

For the official documentation see near the bottom of
https://msdn.microsoft.com/en-us/library/dd293608.aspx: "Stateless lambdas,
which are omni-convertible to function pointers that use arbitrary calling
conventions."

Some more informal context here:
https://blogs.msdn.microsoft.com/oldnewthing/20150220-00/?p=44623

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180724/3aeafd33/attachment-0001.html>


More information about the llvm-bugs mailing list