<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - ObjC++ attempts to copy lambdas, preventing capture of move-only types"
href="http://llvm.org/bugs/show_bug.cgi?id=20534">20534</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ObjC++ attempts to copy lambdas, preventing capture of move-only types
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>C++1y
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vlovich@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>ObjC++ supports capturing move-only types as x-values if they are in __block
storage. However, if C++14 lambdas are used, it is not possible to capture
move-only types, even though there would be a strong motivation for such.
I'm not sure about the internals of how the conversion of C++ lambda to ObjC
block is done, but perhaps lambdas can also be treated as x-values as well when
being converted?
GCD Example:
Preferred syntax:
void logMessage(std::unique_ptr<LogData> logData)
{
dispatch_async([logData = logData] {
// process logData
});
}
fails due to attempt to copy lambda (presumably into ObjC block).
Workaround syntax:
void logMessage(std::unique_ptr<LogData> logDataArg)
{
__block auto logData = std::move(logDataArg);
dispatch_async(^{
// process logData
});
}
Of course this has several properties that are not ideal given the desired
syntax:
1: More verbose
2: All argument variables have to be copied into a local __block storage
variable manually (typos are easy).
3: Explicit capture semantics of C++ lambas are unavailable.</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>