Skip to content
Merged
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
8 changes: 5 additions & 3 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ void CheckOther::checkConstPointer()
else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok)
deref = DEREF;
else if (Token::Match(parent, "%op%") && Token::simpleMatch(parent->astParent(), "."))
deref = DEREF;
deref = MEMBER;
else if (Token::simpleMatch(parent, "."))
deref = MEMBER;
else if (astIsRangeBasedForDecl(tok))
Expand All @@ -1707,12 +1707,12 @@ void CheckOther::checkConstPointer()
continue;
}
}
if (Token::Match(gparent, "%cop%") && !gparent->isUnaryOp("&") && !gparent->isUnaryOp("*"))
continue;
if (hasIncDecPlus) {
parent = gparent;
gparent = gparent ? gparent->astParent() : nullptr;
}
if (Token::Match(gparent, "%cop%") && !gparent->isUnaryOp("&") && !gparent->isUnaryOp("*"))
continue;
int argn = -1;
if (Token::simpleMatch(gparent, "return")) {
const Function* function = gparent->scope()->function;
Expand Down Expand Up @@ -1744,6 +1744,8 @@ void CheckOther::checkConstPointer()
int argn = -1;
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<"))
continue;
if (hasIncDecPlus && !parent->astParent())
continue;
if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
continue;
if (Token::simpleMatch(parent, "=") && parent->astOperand1() == tok)
Expand Down
12 changes: 12 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4313,6 +4313,18 @@ class TestOther : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n",
errout_str());

check("struct S { int a; };\n" // #13286
"void f(struct S* s) {\n"
" if ((--s)->a >= 0) {}\n"
"}\n"
"void g(struct S* s) {\n"
" --s;\n"
" if (s->a >= 0) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n"
"[test.cpp:5]: (style) Parameter 's' can be declared as pointer to const\n",
errout_str());
}

void constArray() {
Expand Down
Loading