Fix #11095 FP constParameter with decremented pointer (#4131)

This commit is contained in:
chrchr-github 2022-05-28 08:32:58 +02:00 committed by GitHub
parent 16a4449901
commit e1c51940a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -1567,6 +1567,8 @@ void CheckOther::checkConstPointer()
deref = true; deref = true;
else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok) else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok)
deref = true; deref = true;
else if (Token::Match(parent, "%op%") && Token::simpleMatch(parent->astParent(), "."))
deref = true;
if (deref) { if (deref) {
const Token* const gparent = parent->astParent(); const Token* const gparent = parent->astParent();
if (Token::Match(gparent, "%cop%") && !gparent->isUnaryOp("&") && !gparent->isUnaryOp("*")) if (Token::Match(gparent, "%cop%") && !gparent->isUnaryOp("&") && !gparent->isUnaryOp("*"))

View File

@ -3105,6 +3105,12 @@ private:
" if (x == nullptr) {}\n" " if (x == nullptr) {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (style) Parameter 'x' can be declared as pointer to const\n", errout.str());
check("struct S { void v(); };\n" // #11095
"void f(S* s) {\n"
" (s - 1)->v();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void switchRedundantAssignmentTest() { void switchRedundantAssignmentTest() {