Fix #11440 FN Moved value when using {} to initialize (#5479)

This commit is contained in:
chrchr-github 2023-09-26 10:04:22 +02:00 committed by GitHub
parent 9f96803f62
commit f037edf586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -5085,7 +5085,7 @@ static const Token * findEndOfFunctionCallForParameter(const Token * parameterTo
if (!parameterToken) if (!parameterToken)
return nullptr; return nullptr;
const Token * parent = parameterToken->astParent(); const Token * parent = parameterToken->astParent();
while (parent && !parent->isOp() && parent->str() != "(") while (parent && !parent->isOp() && !Token::Match(parent, "[({]"))
parent = parent->astParent(); parent = parent->astParent();
if (!parent) if (!parent)
return nullptr; return nullptr;

View File

@ -248,6 +248,7 @@ private:
TEST_CASE(doubleMoveMemberInitialization1); TEST_CASE(doubleMoveMemberInitialization1);
TEST_CASE(doubleMoveMemberInitialization2); TEST_CASE(doubleMoveMemberInitialization2);
TEST_CASE(doubleMoveMemberInitialization3); // #9974 TEST_CASE(doubleMoveMemberInitialization3); // #9974
TEST_CASE(doubleMoveMemberInitialization4);
TEST_CASE(moveAndAssign1); TEST_CASE(moveAndAssign1);
TEST_CASE(moveAndAssign2); TEST_CASE(moveAndAssign2);
TEST_CASE(moveAssignMoveAssign); TEST_CASE(moveAssignMoveAssign);
@ -10503,6 +10504,16 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void doubleMoveMemberInitialization4() { // #11440
check("struct S { void f(int); };\n"
"struct T {\n"
" T(int c, S&& d) : c{ c }, d{ std::move(d) } { d.f(c); }\n"
" int c;\n"
" S d;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) Access of moved variable 'd'.\n", errout.str());
}
void moveAndAssign1() { void moveAndAssign1() {
check("A g(A a);\n" check("A g(A a);\n"
"void f() {\n" "void f() {\n"