Skip to content

Commit 242afc3

Browse files
Fix #11148 Regression: Parameter \'ptr\' can be declared as pointer to const (#4233)
1 parent d204c5f commit 242afc3

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,8 @@ void CheckOther::checkConstPointer()
15561556
deref = true;
15571557
else if (Token::simpleMatch(parent, "[") && parent->astOperand1() == tok && tok != nameTok)
15581558
deref = true;
1559+
else if (Token::Match(parent, "%op%") && Token::simpleMatch(parent->astParent(), "."))
1560+
deref = true;
15591561
else if (astIsRangeBasedForDecl(tok))
15601562
continue;
15611563
if (deref) {
@@ -1577,7 +1579,7 @@ void CheckOther::checkConstPointer()
15771579
} else if (Token::simpleMatch(gparent, "[") && gparent->astOperand2() == parent)
15781580
continue;
15791581
} else {
1580-
if (Token::Match(parent, "%oror%|%comp%|&&|?|!"))
1582+
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-"))
15811583
continue;
15821584
else if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
15831585
continue;

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,13 @@ class TestOther : public TestFixture {
32503250
" **b = 0;\n"
32513251
"}\n");
32523252
ASSERT_EQUALS("", errout.str());
3253+
3254+
check("ptrdiff_t f(int *p0, int *p1) {\n" // #11148
3255+
" return p0 - p1;\n"
3256+
"}\n");
3257+
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'p0' can be declared as pointer to const\n"
3258+
"[test.cpp:1]: (style) Parameter 'p1' can be declared as pointer to const\n",
3259+
errout.str());
32533260
}
32543261

32553262
void switchRedundantAssignmentTest() {

0 commit comments

Comments
 (0)