<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 doesn't require references to be listed in lambda capture"
href="https://bugs.llvm.org/show_bug.cgi?id=34865">34865</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang doesn't require references to be listed in lambda capture
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>redbeard0531@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Clang will compile this faulty code without an error:
int var = 0;
int main() {
int& varRef = var;
return []{return varRef;}();
}
This also leads to an incorrect warning if varRef is correctly captured (which
is how we noticed this issue in the first place):
<span class="quote">> clang++ test2.cpp --std=c++17 -Wall </span >
test2.cpp:4:14: warning: lambda capture 'varRef' is not required to be captured
for this use [-Wunused-lambda-capture]
return [&varRef]{return varRef;}();
^
This is a reduced example from this real-world code:
<a href="https://github.com/mongodb/mongo/blob/r3.5.13/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp#L383-L402">https://github.com/mongodb/mongo/blob/r3.5.13/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp#L383-L402</a>
(clang++-5.0 -Wall warns that kRsOplogNamespace is unused even though it is
used on line 402)</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>