Fix 11308: FP accessMoved with virtual function (#4478)

* Fix 11308: FP accessMoved with virtual function

* Format
This commit is contained in:
Paul Fultz II 2022-09-18 01:30:06 -05:00 committed by GitHub
parent d34de745c0
commit de7d02293f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -4838,10 +4838,7 @@ static void valueFlowAfterMove(TokenList* tokenlist, SymbolDatabase* symboldatab
continue;
if (parent && parent->astOperand1() && parent->astOperand1()->varId() == varId)
continue;
const Variable *var = varTok->variable();
if (!var)
continue;
const Token * const endOfVarScope = var->scope()->bodyEnd;
const Token* const endOfVarScope = getEndOfExprScope(varTok);
const Token * openParentesisOfMove = findOpenParentesisOfMove(varTok);
const Token * endOfFunctionCall = findEndOfFunctionCallForParameter(openParentesisOfMove);

View File

@ -259,6 +259,7 @@ private:
TEST_CASE(moveAndLambda);
TEST_CASE(moveInLoop);
TEST_CASE(moveCallback);
TEST_CASE(moveClassVariable);
TEST_CASE(forwardAndUsed);
TEST_CASE(funcArgNamesDifferent);
@ -9976,6 +9977,21 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'callback'.\n", errout.str());
}
void moveClassVariable()
{
check("struct B {\n"
" virtual void f();\n"
"};\n"
"struct D : B {\n"
" void f() override {\n"
" auto p = std::unique_ptr<D>(new D(std::move(m)));\n"
" }\n"
" D(std::unique_ptr<int> c) : m(std::move(c)) {}\n"
" std::unique_ptr<int> m;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void forwardAndUsed() {
Settings keepTemplates;
keepTemplates.checkUnusedTemplates = true;