diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e77d35ed6..ee84dec44 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1525,8 +1525,13 @@ void CheckOther::checkConstPointer() if (!p->scope() || !p->scope()->function || p->scope()->function->isImplicitlyVirtual(true) || p->scope()->function->hasVirtualSpecifier()) continue; } - if (nonConstPointers.find(p) == nonConstPointers.end()) + if (nonConstPointers.find(p) == nonConstPointers.end()) { + const Token *start = (p->isArgument()) ? p->scope()->bodyStart : p->nameToken()->next(); + const int indirect = p->isArray() ? p->dimensions().size() : 1; + if (isVariableChanged(start, p->scope()->bodyEnd, indirect, p->declarationId(), false, mSettings, mTokenizer->isCPP())) + continue; constVariableError(p, nullptr); + } } } void CheckOther::constVariableError(const Variable *var, const Function *function) diff --git a/test/testother.cpp b/test/testother.cpp index df55ca7b4..1d8e4e1b3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2764,6 +2764,13 @@ private: " memcpy(data.buf, &a, sizeof(a));\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #10547 + check("void foo(std::istream &istr) {\n" + " unsigned char x[2];\n" + " istr >> x[0];\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void switchRedundantAssignmentTest() {