<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 - -Wunused-lambda-capture: false positive on `if constexpr`"
href="https://bugs.llvm.org/show_bug.cgi?id=45398">45398</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wunused-lambda-capture: false positive on `if constexpr`
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gribozavr@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>-Wunused-lambda-capture produces a false positive on lambdas that use captured
variables within inactive branches of `if constexpr`.
$ ./bin/clang++ --version
clang version 11.0.0 (<a href="mailto:git@github.com">git@github.com</a>:llvm/llvm-project.git
cdce2fe561eb6e63d77d1d589e521a8e2afb1eef)
...
$ cat /tmp/unused-lambda-capture-false-positive.cc
template <int>
struct A {};
struct B {
template <typename T, bool flag>
void Top(T t, int n) {
auto lambda = [t, n, this](auto arg) {
if constexpr (flag) {
UndefinedFunction(t, n);
} else {
TopImpl<A<arg>>();
}
};
}
template <typename U>
void TopImpl() {}
};
void Test(B* b) {
b->Top<int, false>(0, 0);
}
$ ./bin/clang++ -c -std=gnu++17 -Wunused-lambda-capture
/tmp/unused-lambda-capture-false-positive.cc
/tmp/unused-lambda-capture-false-positive.cc:6:20: warning: lambda capture 't'
is not used [-Wunused-lambda-capture]
auto lambda = [t, n, this](auto arg) {
^
/tmp/unused-lambda-capture-false-positive.cc:18:6: note: in instantiation of
function template specialization 'B::Top<int, false>' requested here
b->Top<int, false>(0, 0);
^
/tmp/unused-lambda-capture-false-positive.cc:6:23: warning: lambda capture 'n'
is not used [-Wunused-lambda-capture]
auto lambda = [t, n, this](auto arg) {
^
/tmp/unused-lambda-capture-false-positive.cc:6:26: warning: lambda capture
'this' is not used [-Wunused-lambda-capture]
auto lambda = [t, n, this](auto arg) {
^
3 warnings generated.
ANALYSIS
The false positive on `this` might be a dup of
<a class="bz_bug_link
bz_status_CONFIRMED "
title="CONFIRMED - Incorrect -Wunused-lambda-capture warning for this capture"
href="show_bug.cgi?id=36880">https://bugs.llvm.org/show_bug.cgi?id=36880</a>, however false positives on `t` and
`n` seem diffirent.</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>