Skip to content

Commit de7d022

Browse files
authored
Fix 11308: FP accessMoved with virtual function (#4478)
* Fix 11308: FP accessMoved with virtual function * Format
1 parent d34de74 commit de7d022

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4838,10 +4838,7 @@ static void valueFlowAfterMove(TokenList* tokenlist, SymbolDatabase* symboldatab
48384838
continue;
48394839
if (parent && parent->astOperand1() && parent->astOperand1()->varId() == varId)
48404840
continue;
4841-
const Variable *var = varTok->variable();
4842-
if (!var)
4843-
continue;
4844-
const Token * const endOfVarScope = var->scope()->bodyEnd;
4841+
const Token* const endOfVarScope = getEndOfExprScope(varTok);
48454842

48464843
const Token * openParentesisOfMove = findOpenParentesisOfMove(varTok);
48474844
const Token * endOfFunctionCall = findEndOfFunctionCallForParameter(openParentesisOfMove);

test/testother.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class TestOther : public TestFixture {
259259
TEST_CASE(moveAndLambda);
260260
TEST_CASE(moveInLoop);
261261
TEST_CASE(moveCallback);
262+
TEST_CASE(moveClassVariable);
262263
TEST_CASE(forwardAndUsed);
263264

264265
TEST_CASE(funcArgNamesDifferent);
@@ -9976,6 +9977,21 @@ class TestOther : public TestFixture {
99769977
ASSERT_EQUALS("[test.cpp:4]: (warning) Access of moved variable 'callback'.\n", errout.str());
99779978
}
99789979

9980+
void moveClassVariable()
9981+
{
9982+
check("struct B {\n"
9983+
" virtual void f();\n"
9984+
"};\n"
9985+
"struct D : B {\n"
9986+
" void f() override {\n"
9987+
" auto p = std::unique_ptr<D>(new D(std::move(m)));\n"
9988+
" }\n"
9989+
" D(std::unique_ptr<int> c) : m(std::move(c)) {}\n"
9990+
" std::unique_ptr<int> m;\n"
9991+
"};\n");
9992+
ASSERT_EQUALS("", errout.str());
9993+
}
9994+
99799995
void forwardAndUsed() {
99809996
Settings keepTemplates;
99819997
keepTemplates.checkUnusedTemplates = true;

0 commit comments

Comments
 (0)