Skip to content

Commit f833907

Browse files
committed
Partial fix for #14148
1 parent 70c7ca6 commit f833907

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ void CheckOther::checkConstPointer()
19121912
int argn = -1;
19131913
if (Token::Match(parent, "%oror%|%comp%|&&|?|!|-|<<|;"))
19141914
continue;
1915-
if (hasIncDecPlus && !parent->astParent())
1915+
if (hasIncDecPlus && (!parent->astParent() || parent->astParent()->str() == ";"))
19161916
continue;
19171917
if (Token::simpleMatch(parent, "(") && Token::Match(parent->astOperand1(), "if|while"))
19181918
continue;

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4511,6 +4511,16 @@ class TestOther : public TestFixture {
45114511
"}\n");
45124512
ASSERT_EQUALS("[test.cpp:2:15]: (style) Variable 'q' can be declared as pointer to const [constVariablePointer]\n",
45134513
errout_str());
4514+
4515+
check("void g(const int*);\n" // #14148
4516+
"void f() {\n"
4517+
" int a[] = {1, 2, 3};\n"
4518+
" for (int* p = a; *p != 3; p++) {\n"
4519+
" g(p);\n"
4520+
" }\n"
4521+
"}\n");
4522+
ASSERT_EQUALS("[test.cpp:4:15]: (style) Variable 'p' can be declared as pointer to const [constVariablePointer]\n",
4523+
errout_str());
45144524
}
45154525

45164526
void constArray() {

0 commit comments

Comments
 (0)