diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 924775baf..6d2f565f3 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -640,13 +640,13 @@ static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm) if (rhs.isIntValue()) { std::vector result = infer(makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {rhs}); - if (result.empty()) + if (result.empty() || !result.front().isKnown()) return unknown; return result.front(); } else if (lhs.isIntValue()) { std::vector result = infer(makeIntegralInferModel(), expr->str(), {lhs}, expr->astOperand2()->values()); - if (result.empty()) + if (result.empty() || !result.front().isKnown()) return unknown; return result.front(); } diff --git a/test/teststl.cpp b/test/teststl.cpp index c3f922029..f489ea76d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2472,7 +2472,7 @@ private: check("void func(std::list strlist) {\n" " for (std::list::iterator str = strlist.begin(); str != strlist.end(); str++) {\n" " if (func2(*str)) {\n" - " strlist.erase(str);\n" + " strlist.erase(str);\n" " if (strlist.empty())\n" " return;\n" " }\n" @@ -5387,6 +5387,18 @@ private: "}\n", true); ASSERT_EQUALS("", errout.str()); + + check("void f(const std::vector& v, int e) {\n" + " if (!v.empty()) {\n" + " if (e < 0 || true) {\n" + " if (e < 0)\n" + " return;\n" + " }\n" + " }\n" + " for (auto i : v) {}\n" + "}\n", + true); + ASSERT_EQUALS("", errout.str()); } void checkMutexes() {