<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang-cl does not automatically convert a non-capturing lambda to a function pointer with a specific calling convention"
   href="https://bugs.llvm.org/show_bug.cgi?id=38285">38285</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl does not automatically convert a non-capturing lambda to a function pointer with a specific calling convention
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jeroen.ketema@philips.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20594" name="attach_20594" title="Source file with de code from the description">attachment 20594</a> <a href="attachment.cgi?id=20594&action=edit" title="Source file with de code from the description">[details]</a></span>
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.

```
<span class="quote">> type foo.cpp</span >
typedef int (__stdcall * FuncType)(int p);

FuncType func;

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

```
<span class="quote">> cl.exe foo.cpp</span >
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:

```
<span class="quote">> clang-cl.exe -m32 foo.cpp</span >
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
<a href="https://msdn.microsoft.com/en-us/library/dd293608.aspx">https://msdn.microsoft.com/en-us/library/dd293608.aspx</a>: "Stateless lambdas,
which are omni-convertible to function pointers that use arbitrary calling
conventions."

Some more informal context here:
<a href="https://blogs.msdn.microsoft.com/oldnewthing/20150220-00/?p=44623">https://blogs.msdn.microsoft.com/oldnewthing/20150220-00/?p=44623</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>