| Issue |
173923
|
| Summary |
`cppcoreguidelines-rvalue-reference-param-not-moved` false positive when moving member
|
| Labels |
false-positive
|
| Assignees |
|
| Reporter |
eisenwave
|
https://godbolt.org/z/qEPM6e58h
```cpp
#include <utility>
struct T { T(T&&); };
struct Wrapper { T t; };
T awoo(Wrapper&& w) {
return std::move(w.t);
}
```
```
<source>:7:18: warning: rvalue reference parameter 'w' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
7 | T awoo(Wrapper&& w) {
| ^
```
While the diagnostic is correct in a sense, `w` is "spiritually moved" because there is no semantic difference between `std::move(w).t` and `std::move(w.t)`, and it's up to subjective preference which of these write.
It could be argued that `std::move(w.t)` is superior if `T` is something like `std::string` because it reduces the total amount of template instantiations of `std::move`. After all, it's almost certain that `std::string` is going to be moved somewhere else.
The example is artificial, but it's not inconceivable that you would take an rvalue reference to some aggregate type and then move its members. I ran into this false positive in real code.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs