Open JonasToth opened 7 years ago
Reduced test case:
#include <utility>
void a() {
int x;
std::move(x);
x;
}
void b() {
int x;
std::forward<int>(x);
x;
}
void c() {
int x;
static_cast<int &&>(x);
x;
}
when checked with
clang-tidy -checks=bugprone-use-after-move,-clang-diagnostic-unused-value use-after-move.cpp --
the only output is
5 warnings generated.
/home/david/test/use-after-move.cpp:6:5: warning: 'x' used after it was moved [bugprone-use-after-move]
x;
^
/home/david/test/use-after-move.cpp:5:5: note: move occurred here
std::move(x);
^
Suppressed 4 warnings (4 with check filters).
I agree that this check should catch both b
and c
, as both of them use x
after moving from it.
Extended Description
This bugreport is result of a short discussion on the mailing list.
std::forward
is a utitlity similar tostd::move
, which moves the argument conditionally. It is possible to initiate a move by manual casting as well.An example that shows all of these possibility is added with the output, that only diagnoses
std::move