| Issue |
160650
|
| Summary |
[clang-tidy] false-negative in bugprone-return-const-ref-from-parameter when overload for rvalues exists with different constness
|
| Labels |
clang-tidy,
false-negative
|
| Assignees |
|
| Reporter |
xuhdev
|
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 <string>
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 <string>
struct Foo {
const std::string &f(const std::string &a) const {
return a;
}
void f(std::string&&) const = delete;
};
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs