diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1247d97365e..74f198ca21f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1857,10 +1857,13 @@ void CheckOther::checkConstPointer() if (!var->isLocal() && !var->isArgument()) continue; const Token* const nameTok = var->nameToken(); - if (tok == nameTok) { + if (tok == nameTok && var->isLocal() && !astIsRangeBasedForDecl(nameTok)) { + if (var->isReference() && var->isPointer()) { + nonConstPointers.emplace(var); + continue; + } // declarations of (static) pointers are (not) split up, array declarations are never split up - if (var->isLocal() && (!var->isStatic() || Token::simpleMatch(nameTok->next(), "[")) && - !astIsRangeBasedForDecl(nameTok)) + if ((!var->isStatic() || Token::simpleMatch(nameTok->next(), "["))) continue; } // Skip function pointers diff --git a/test/testother.cpp b/test/testother.cpp index 7a3f0a176cf..202b8d97ed5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3996,6 +3996,12 @@ class TestOther : public TestFixture { " return static_cast(b).i;\n" "}\n"); ASSERT_EQUALS("[test.cpp:9:10]: (style) Parameter 'b' can be declared as reference to const [constParameterReference]\n", errout_str()); + + check("void f(int *p) {\n" // #14409 + " int*& pp{ p };\n" + " if (*pp) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void constParameterCallback() {