Skip to content

Commit 1ef5ef3

Browse files
Fix #14928 Duplicate accessMoved in range-based for (#8746)
1 parent 807ce9f commit 1ef5ef3

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/vf_settokenvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ namespace ValueFlow
384384
setTokenValueCast(parent, valueType, std::move(value), settings);
385385
}
386386

387-
else if (parent->str() == ":") {
387+
else if (parent->str() == ":" && Token::simpleMatch(parent->astParent(), "?")) {
388388
setTokenValue(parent,std::move(value),settings);
389389
}
390390

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12945,6 +12945,13 @@ class TestOther : public TestFixture {
1294512945
" cif::condition mWhere;\n"
1294612946
"};\n");
1294712947
ASSERT_EQUALS("", errout_str());
12948+
12949+
check("void g(std::string);\n" // #14928
12950+
"void f(std::string s) {\n"
12951+
" g(std::move(s));\n"
12952+
" for (char c : s) {}\n"
12953+
"}\n");
12954+
ASSERT_EQUALS("[test.cpp:4:19]: (warning) Access of moved variable 's'. [accessMoved]\n", errout_str());
1294812955
}
1294912956

1295012957
void moveTernary()

0 commit comments

Comments
 (0)