File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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() {
You can’t perform that action at this time.
0 commit comments