<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 --- - Returning lambdas with dangling references produces no warning"
href="http://llvm.org/bugs/show_bug.cgi?id=19231">19231</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Returning lambdas with dangling references produces no warning
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gonzalobg88@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In C++14 you can return lambdas from functions directly as well as stored in an
std::function. In both cases, the compiler never warns about dangling
references even in trivial situations (same is true when returning any other
function object with a dangling reference).
This mistake is easy to make and hard to debug. It would be nice if it could be
prevented by Wall.
Example:
#include <iostream>
auto f(const int a) {
const int b = a;
return [&](){ return b; }; // returns dangling ref inside the lambda
}
int main() {
auto i = f(0);
std::cout << "i: " << i() << "\n";
return 0;
}
flags used: -O0 -std=c++1y -Wall -Wextra</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>