From f037edf586cd8ef3066f25e33dedaa7cf5b4e599 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 26 Sep 2023 10:04:22 +0200 Subject: [PATCH] Fix #11440 FN Moved value when using {} to initialize (#5479) --- lib/valueflow.cpp | 2 +- test/testother.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b8cde1f38..6ac247684 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5085,7 +5085,7 @@ static const Token * findEndOfFunctionCallForParameter(const Token * parameterTo if (!parameterToken) return nullptr; const Token * parent = parameterToken->astParent(); - while (parent && !parent->isOp() && parent->str() != "(") + while (parent && !parent->isOp() && !Token::Match(parent, "[({]")) parent = parent->astParent(); if (!parent) return nullptr; diff --git a/test/testother.cpp b/test/testother.cpp index aa09d83ad..074fecc87 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -248,6 +248,7 @@ private: TEST_CASE(doubleMoveMemberInitialization1); TEST_CASE(doubleMoveMemberInitialization2); TEST_CASE(doubleMoveMemberInitialization3); // #9974 + TEST_CASE(doubleMoveMemberInitialization4); TEST_CASE(moveAndAssign1); TEST_CASE(moveAndAssign2); TEST_CASE(moveAssignMoveAssign); @@ -10503,6 +10504,16 @@ private: 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() { check("A g(A a);\n" "void f() {\n"