diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a08d86a2f86..9f4e97df827 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2642,7 +2642,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, if (!tok->isMutableExpr()) return false; - if (isConstVarExpression(tok)) + if (indirect == 0 && isConstVarExpression(tok)) return false; const Token *tok2 = tok; diff --git a/test/testother.cpp b/test/testother.cpp index 085b39cfffb..88ae900225c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4300,6 +4300,11 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:3:7]: (style) Variable 'a' can be declared as const array [constVariable]\n", errout_str()); + + check("void f(V& v) {\n" + " std::sort(&v(1), &v(10));\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {