False positve bugprone-use-after-move when object is modified in lambda
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
~~~c++
#include
#include
void h(std::string x) { std::cout << x << '\n'; }
int main() {
std::string s;
char c = 'A';
auto g = [&]() {
if (c <= 'Z') {
s = std::string(100, c);
++c;
return true;
}
return false;
};
while (g()) {
if (!s.empty()) {
h(std::move(s));
}
}
}
~~~
~~~
:18:14: warning: 's' used after it was moved [bugprone-use-after-move]
18 | if (!s.empty()) {
| ^
:19:15: note: move occurred here
19 | h(std::move(s));
| ^
:18:14: note: the use happens in a later loop iteration than the move
18 | if (!s.empty()) {
| ^
1 warning generated.
~~~
https://godbolt.org/z/YhYjvKP6z
Contributor guide
Assessment
This issue has not been assessed yet.