| Issue |
115743
|
| Summary |
[clang-tidy] False-positive with returning a constant reference parameter.
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
Jhuighuy
|
Hi everyone,
Consider the following snippet of code:
```cpp
#include <array>
template<class T>
void f(const T& t) {
const auto get = [&t] -> const T& { return t; };
return std::array{get(), get(), get()};
}
```
When I run the latest released `clang-tidy` (19.1.3) over it with a check `bugprone-return-const-ref-from-parameter`, it produces a false-positive warning:
```
$ clang-tidy --version
Homebrew LLVM version 19.1.3
Optimized build.
$ clang-tidy b.cpp "--checks=bugprone-return-const-ref-from-parameter" -- -std=c++23
1 warning generated.
.../b.cpp:5:45: warning: returning a constant reference parameter may cause use-after-free when the parameter is constructed from a temporary [bugprone-return-const-ref-from-parameter]
5 | const auto get = [&t] -> const T& { return t; };
|
```
Clearly, `t` is not returned from the function `f`, and it not a parameter of a lambda.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs