[clang-tidy] false-negative in bugprone-return-const-ref-from-parameter when overload for rvalues exists with different constness
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This is a followup bug of #90274.
The following code snippet should generate `bugprone-return-const-ref-from-parameter` error but clang-tidy doesn't:
```cpp
#include
struct Foo {
const std::string &f(const std::string &a) const {
return a;
}
void f(std::string&&) = delete;
};
```
The following bug-prone usage compiles:
```cpp
int main() {
const Foo foo;
auto& a = foo.f(std::string("12"));
// use a...
return 0;
}
```
The proper way to avoid this clang-tidy warning is to overload with the same constness:
```cpp
#include
struct Foo {
const std::string &f(const std::string &a) const {
return a;
}
void f(std::string&&) const = delete;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.