diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e2e19b6bd91..0f253930248 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2794,7 +2794,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings &settings, const Token * ptok = tok2; while (Token::Match(ptok->astParent(), ".|::")) ptok = ptok->astParent(); - int pindirect = indirect; + int pindirect = indirect - derefs; if (indirect == 0 && astIsLHS(tok2) && Token::Match(ptok, ". %var%") && astIsPointer(ptok->next())) pindirect = 1; bool inconclusive = false; diff --git a/test/testother.cpp b/test/testother.cpp index adfc2ff0f2a..c58aef2650e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5086,6 +5086,11 @@ class TestOther : public TestFixture { "void g(__attribute__((unused)) int *p) {}\n" "void h(int *p) {}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("void f(std::vector& v, int* p) {\n" // #15203 + " v.push_back(*p);\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:1:34]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); } void constArray() {