diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 311e6ed00..1bb3c395f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -7188,7 +7188,7 @@ struct IteratorConditionHandler : SimpleConditionHandler { if (!values.empty()) { cond.vartok = tok->astOperand2(); } else { - values = getIteratorValues(tok->astOperand2()->values()); + values = getIteratorValues(tok->astOperand2()->values(), &kind); if (!values.empty()) cond.vartok = tok->astOperand1(); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 37c34c0bd..74c66fa5d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4201,6 +4201,20 @@ private: "[test.cpp:4] -> [test.cpp:4]: (warning) Either the condition 'i==v.end()' is redundant or there is possible dereference of an invalid iterator: i+1.\n", errout.str()); + // #10657 + check("std::list mValues;\n" + "typedef std::list::iterator ValueIterator;\n" + "void foo(ValueIterator beginValue, ValueIterator endValue) {\n" + " ValueIterator prevValue = beginValue;\n" + " ValueIterator curValue = beginValue;\n" + " for (++curValue; prevValue != endValue && curValue != mValues.end(); ++curValue) {\n" + " a = bar(*curValue);\n" + " prevValue = curValue;\n" + " }\n" + " if (endValue == mValues.end()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // #10642 check("int f(std::vector v) {\n" " return *(v.begin() + v.size() - 1);\n"