<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115740>115740</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Regression, false-positive on `std::forward` in capture groups.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Jhuighuy
</td>
</tr>
</table>
<pre>
Hi everyone,
Consider the following snippet of code:
```cpp
#include <ranges>
#include <utility>
template<std::ranges::random_access_range Range,
std::ranges::random_access_range Perm>
requires std::ranges::viewable_range<Range> &&
std::ranges::viewable_range<Perm>
constexpr auto permuted_view(Range&& range, Perm&& perm) {
return std::ranges::transform_view{
std::forward<Perm>(perm),
[range_view = std::views::all(std::forward<Range>(range))](
size_t index) -> decltype(auto) { return range_view[index]; }};
}
```
When I ran the latest released `clang-tidy` (19.1.3) over it with a check `cppcoreguidelines-missing-std-forward`, it produces a false-positive warning:
```
$ clang-tidy --version
Homebrew LLVM version 19.1.3
Optimized build.
$ clang-tidy b.cpp "--checks=cppcoreguidelines-missing-std-forward" -- -std=c++23
94 warnings generated.
.../b.cpp:8:38: warning: forwarding reference parameter 'range' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]
8 | constexpr auto permuted_view(Range&& range, Perm&& perm) {
| ^
Suppressed 93 warnings (93 in non-user code).
```
`clang-tidy` (18.1.8) works as expected.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVUGv4yYQ_jXkMrLlgO3Yhxxeko221VattlJ7fMIwcehioICTzf76Csd5yXaj6h1qIYIg8818wzcDD0H1BnFNqg2pdgs-xqP165-Po-qP42XRWXlZf1SAJ_QXa5DQLSl2pHi5zltrgpLoIR4RDlZre1amh2CUcxjBHkBYiYTNfyd1cR3CuXmHMmWEHiUCYVvPTY-BsA_PDseotIqX--k0Rxyc5hEJ24Yokyf2coOZ19IOr1wID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