Fix 11578: FP accessMoved with range-based for loop (#4931)

* Fix 11578: FP accessMoved with range-based for loop

* Format
This commit is contained in:
Paul Fultz II 2023-04-03 12:44:47 -05:00 committed by GitHub
parent 86efca28a3
commit d5e2ee411e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -413,7 +413,7 @@ struct ForwardTraversal {
return Break();
if (stepTok && updateRecursive(stepTok) == Progress::Break)
return Break();
if (condTok && updateRecursive(condTok) == Progress::Break)
if (condTok && !Token::simpleMatch(condTok, ":") && updateRecursive(condTok) == Progress::Break)
return Break();
return Progress::Continue;
}

View File

@ -266,6 +266,7 @@ private:
TEST_CASE(moveClassVariable);
TEST_CASE(forwardAndUsed);
TEST_CASE(moveAndReference);
TEST_CASE(moveForRange);
TEST_CASE(funcArgNamesDifferent);
TEST_CASE(funcArgOrderDifferent);
@ -10342,6 +10343,18 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (warning) Access of moved variable 'r'.\n", errout.str());
}
void moveForRange()
{
check("struct C {\n"
" void f() {\n"
" for (auto r : mCategory.find(std::move(mWhere))) {}\n"
" }\n"
" cif::category mCategory;\n"
" cif::condition mWhere;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void funcArgNamesDifferent() {
check("void func1(int a, int b, int c);\n"
"void func1(int a, int b, int c) { }\n"