| Issue |
176873
|
| Summary |
[clang-tidy] False positive for cppcoreguidelines-missing-std-forward when forwarding in doubly-nested lambda
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
lukas-lang
|
Note: Heavily related to #68105
It seems that the `cppcoreguidelines-missing-std-forward` check does not account for doubly-nested immediately-invoked lambda expressions ([Godbolt Link](https://godbolt.org/z/aeW8P33E9)):
```cpp
#include <utility>
template <typename T>
void foo(T &&arg);
template <typename T>
void foo2(T &&arg)
{
foo(arg); // Incorrect: Not forwarded
}
template <typename T>
void foo3(T &&arg)
{
foo(std::forward<T>(arg)); // Correct: Properly forwarded
}
template <typename T>
void foo4(T &&arg)
{
[&]()
{
foo(std::forward<T>(arg)); // Correct: Properly forwarded inside IIFE
}();
}
template <typename T>
void foo5(T &&arg)
{
[&]()
{
[&]()
{ foo(std::forward<T>(arg)); }(); // Should be correct: Properly forwarded inside nested IIFE
}();
}
```
This gives two warnings, only the first of which is expected:
```
<source>:7:15: warning: forwarding reference parameter 'arg' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]
7 | void foo2(T &&arg)
| ^
<source>:28:15: warning: forwarding reference parameter 'arg' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]
28 | void foo5(T &&arg)
| ^
2 warnings generated.
```
The `foo5` definition should not emit anything, similar to the `foo4` example above it.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs