Closed
Description
Consider the following code
#include <cassert>
#include <vector>
struct test {
test& foo(std::vector<int> const& v) { assert(v.size() == 1); return *this; }
int bar(std::vector<int> v ) { return v.size(); }
};
int main() {
std::vector<int> v = { 42 };
return test{}.foo(v).bar(std::move(v));
}
clang-tidy 14.0.6 reports the following error:
tidy14-bug/main.cpp:11:23: error: 'v' used after it was moved [bugprone-use-after-move,-warnings-as-errors]
return test{}.foo(v).bar(std::move(v));
^
tidy14-bug/main.cpp:11:30: note: move occurred here
return test{}.foo(v).bar(std::move(v));
^
tidy14-bug/main.cpp:11:23: note: the use and move are unsequenced, i.e. there is no guarantee about the order in which they are evaluated
return test{}.foo(v).bar(std::move(v));
^
The standard, however, clearly defines the behavior for the case.
This false-positive breaks a lot of code in our codebase.