Fix #11148 Regression: Parameter \'ptr\' can be declared as pointer to const (#4233)

This commit is contained in:
chrchr-github 2022-06-25 21:42:55 +02:00 committed by GitHub
parent d204c5f894
commit 242afc389d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1556,6 +1556,8 @@ void CheckOther::checkConstPointer()
deref = true;
else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok)
deref = true;
else if (Token::Match(parent, "%op%") && Token::simpleMatch(parent->astParent(), "."))
deref = true;
else if (astIsRangeBasedForDecl(tok))
continue;
if (deref) {
@ -1577,7 +1579,7 @@ void CheckOther::checkConstPointer()
} else if (Token::simpleMatch(gparent, "[") && gparent->astOperand2() == parent)
continue;
} else {
if (Token::Match(parent, "%oror%|%comp%|&&|?|!"))
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-"))
continue;
else if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
continue;

View File

@ -3250,6 +3250,13 @@ private:
" **b = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("ptrdiff_t f(int *p0, int *p1) {\n" // #11148
" return p0 - p1;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p0' can be declared as pointer to const\n"
"[test.cpp:1]: (style) Parameter 'p1' can be declared as pointer to const\n",
errout.str());
}
void switchRedundantAssignmentTest() {