File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1688,7 +1688,7 @@ void CheckOther::checkConstPointer()
16881688 else if (Token::simpleMatch (parent, " [" ) && parent->astOperand1 () == tok && tok != nameTok)
16891689 deref = DEREF;
16901690 else if (Token::Match (parent, " %op%" ) && Token::simpleMatch (parent->astParent (), " ." ))
1691- deref = DEREF ;
1691+ deref = MEMBER ;
16921692 else if (Token::simpleMatch (parent, " ." ))
16931693 deref = MEMBER;
16941694 else if (astIsRangeBasedForDecl (tok))
@@ -1707,12 +1707,12 @@ void CheckOther::checkConstPointer()
17071707 continue ;
17081708 }
17091709 }
1710- if (Token::Match (gparent, " %cop%" ) && !gparent->isUnaryOp (" &" ) && !gparent->isUnaryOp (" *" ))
1711- continue ;
17121710 if (hasIncDecPlus) {
17131711 parent = gparent;
17141712 gparent = gparent ? gparent->astParent () : nullptr ;
17151713 }
1714+ if (Token::Match (gparent, " %cop%" ) && !gparent->isUnaryOp (" &" ) && !gparent->isUnaryOp (" *" ))
1715+ continue ;
17161716 int argn = -1 ;
17171717 if (Token::simpleMatch (gparent, " return" )) {
17181718 const Function* function = gparent->scope ()->function ;
@@ -1744,6 +1744,8 @@ void CheckOther::checkConstPointer()
17441744 int argn = -1 ;
17451745 if (Token::Match (parent, " %oror%|%comp%|&&|?|!|-|<<" ))
17461746 continue ;
1747+ if (hasIncDecPlus && !parent->astParent ())
1748+ continue ;
17471749 if (Token::simpleMatch (parent, " (" ) && Token::Match (parent->astOperand1 (), " if|while" ))
17481750 continue ;
17491751 if (Token::simpleMatch (parent, " =" ) && parent->astOperand1 () == tok)
Original file line number Diff line number Diff line change @@ -4313,6 +4313,18 @@ class TestOther : public TestFixture {
43134313 " }\n " );
43144314 ASSERT_EQUALS (" [test.cpp:1]: (style) Parameter 'b' can be declared as pointer to const\n " ,
43154315 errout_str ());
4316+
4317+ check (" struct S { int a; };\n " // #13286
4318+ " void f(struct S* s) {\n "
4319+ " if ((--s)->a >= 0) {}\n "
4320+ " }\n "
4321+ " void g(struct S* s) {\n "
4322+ " --s;\n "
4323+ " if (s->a >= 0) {}\n "
4324+ " }\n " );
4325+ ASSERT_EQUALS (" [test.cpp:2]: (style) Parameter 's' can be declared as pointer to const\n "
4326+ " [test.cpp:5]: (style) Parameter 's' can be declared as pointer to const\n " ,
4327+ errout_str ());
43164328 }
43174329
43184330 void constArray () {
You can’t perform that action at this time.
0 commit comments