Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,12 @@ class TestOther : public TestFixture {
" return static_cast<const D&>(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() {
Expand Down
Loading