diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 6ab7972f8..2c01884c9 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2735,8 +2735,13 @@ bool isExpressionChanged(const Token* expr, const Token* start, const Token* end if (tok->exprId() > 0) { for (const Token* tok2 = start; tok2 != end; tok2 = tok2->next()) { - if (isExpressionChangedAt( - tok, tok2, tok->valueType() ? tok->valueType()->pointer : 0, global, settings, cpp, depth)) + int indirect = 0; + if (const ValueType* vt = tok->valueType()) { + indirect = vt->pointer; + if (vt->type == ValueType::ITERATOR) + ++indirect; + } + if (isExpressionChangedAt(tok, tok2, indirect, global, settings, cpp, depth)) return true; } } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e61ab45c0..85f900854 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2440,8 +2440,11 @@ struct ValueFlowAnalyzer : Analyzer { // TODO: Check if modified in the lambda function return Action::Invalid; int indirect = 0; - if (tok->valueType()) - indirect = tok->valueType()->pointer; + if (const ValueType* vt = tok->valueType()) { + indirect = vt->pointer; + if (vt->type == ValueType::ITERATOR) + ++indirect; + } if (isVariableChanged(tok, indirect, getSettings(), isCPP())) return Action::Invalid; return Action::None; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 3157e68dc..fea1faebc 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4628,6 +4628,18 @@ private: " if (!std::isalnum(c)) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S {\n" // #11404 + " int f() const;\n" + " void g();\n" + "};\n" + "void h(std::vector::iterator it) {\n" + " auto i = (*it)->f();\n" + " (*it)->g();\n" + " auto j = (*it)->f();\n" + " if (i == j) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {