Skip to content

Commit 93bc251

Browse files
Fix #13628 FP: accessMoved with ternary (#8645)
When std::move(x) is only in the true branch of a ternary operator, endOfFunctionCall was left pointing at the first token of the false branch, causing valueFlowForward to tag it as always-moved and report a spurious warning on the ? token. Fix by advancing past the entire false-branch subtree using nextAfterAstRightmostLeaf before starting propagation. --------- Signed-off-by: Francois Berder <fberder@outlook.fr>
1 parent 2538dcd commit 93bc251

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,8 +3296,11 @@ static void valueFlowAfterMove(const TokenList& tokenlist, const SymbolDatabase&
32963296
ternaryColon = ternaryColon->astParent();
32973297
if (Token::simpleMatch(ternaryColon, ":")) {
32983298
endOfFunctionCall = ternaryColon->astOperand2();
3299-
if (Token::simpleMatch(endOfFunctionCall, "("))
3300-
endOfFunctionCall = endOfFunctionCall->link();
3299+
Token* next = nextAfterAstRightmostLeaf(endOfFunctionCall);
3300+
if (next)
3301+
endOfFunctionCall = next;
3302+
else
3303+
endOfFunctionCall = endOfFunctionCall->next();
33013304
}
33023305
}
33033306
ValueFlow::Value value;

test/testother.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12866,6 +12866,18 @@ class TestOther : public TestFixture {
1286612866
" h(b ? h(gA(5, std::move(s))) : h(gB(7, std::move(s))));\n"
1286712867
"}\n");
1286812868
ASSERT_EQUALS("", errout_str());
12869+
12870+
check("int cb(std::string);\n" // #13628
12871+
"void f(bool b, std::string s1) {\n"
12872+
" std::string s2 = b ? cb(std::move(s1)) : s1;\n"
12873+
"}\n");
12874+
ASSERT_EQUALS("", errout_str());
12875+
12876+
check("int cb(std::string);\n"
12877+
"void f(bool b, std::string s1) {\n"
12878+
" std::string s2 = b ? cb(std::move(s1)) : s1 + s1;\n"
12879+
"}\n");
12880+
ASSERT_EQUALS("", errout_str());
1286912881
}
1287012882

1287112883
void movePointerAlias()

0 commit comments

Comments
 (0)