Skip to content

Commit f52e504

Browse files
committed
Fix
1 parent 9d0880c commit f52e504

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎lib/valueflow.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5739,10 +5739,10 @@ static void valueFlowSubFunction(const TokenList& tokenlist,
57395739
std::list<ValueFlow::Value> argvalues(getFunctionArgumentValues(argtok));
57405740

57415741
// Remove non-local lifetimes and moved values
5742-
argvalues.remove_if([](const ValueFlow::Value& v) {
5742+
argvalues.remove_if([argvar](const ValueFlow::Value& v) {
57435743
if (v.isLifetimeValue())
57445744
return !v.isLocalLifetimeValue() && !v.isSubFunctionLifetimeValue();
5745-
return v.isMovedValue();
5745+
return v.isMovedValue() && !argvar->isReference();
57465746
});
57475747
// Remove uninit values if argument is passed by value
57485748
if (argtok->variable() && !argtok->variable()->isPointer() && argvalues.size() == 1 &&

‎test/testother.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13355,6 +13355,16 @@ class TestOther : public TestFixture {
1335513355
" t.set(s);\n"
1335613356
"}\n");
1335713357
ASSERT_EQUALS("[test.cpp:8:11]: (warning) Access of moved variable 's'. [accessMoved]\n", errout_str());
13358+
13359+
check("void g(const std::string& s) {}\n"
13360+
"void h(std::string& r) { x = std::move(r); }\n"
13361+
"void f(std::string s1, std::string s2) {\n"
13362+
" t1 = std::move(s1);\n"
13363+
" t2 = std::move(s2);\n"
13364+
" g(s1);\n"
13365+
" h(s2);\n"
13366+
"}\n");
13367+
ASSERT_EQUALS("[test.cpp:2:40]: (warning) Access of moved variable 'r'. [accessMoved]\n", errout_str());
1335813368
}
1335913369

1336013370
void funcArgNamesDifferent() {

0 commit comments

Comments
 (0)