diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index 315f4a40129..aab64170890 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -384,7 +384,7 @@ namespace ValueFlow setTokenValueCast(parent, valueType, std::move(value), settings); } - else if (parent->str() == ":") { + else if (parent->str() == ":" && Token::simpleMatch(parent->astParent(), "?")) { setTokenValue(parent,std::move(value),settings); } diff --git a/test/testother.cpp b/test/testother.cpp index 92fefb72fd3..c2367ed04b0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -12903,6 +12903,13 @@ class TestOther : public TestFixture { " cif::condition mWhere;\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + check("void g(std::string);\n" // #14928 + "void f(std::string s) {\n" + " g(std::move(s));\n" + " for (char c : s) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4:19]: (warning) Access of moved variable 's'. [accessMoved]\n", errout_str()); } void moveTernary()