File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1370,10 +1370,23 @@ static bool isForLoopCondition(const Token * const tok)
13701370 parent->astParent ()->astParent ()->astOperand1 ()->str () == " for" ;
13711371}
13721372
1373+ static bool isForLoopIncrement (const Token* const tok)
1374+ {
1375+ if (!tok)
1376+ return false ;
1377+ const Token *const parent = tok->astParent ();
1378+ return Token::simpleMatch (parent, " ;" ) && parent->astOperand2 () == tok &&
1379+ Token::simpleMatch (parent->astParent (), " ;" ) &&
1380+ Token::simpleMatch (parent->astParent ()->astParent (), " (" ) &&
1381+ parent->astParent ()->astParent ()->astOperand1 ()->str () == " for" ;
1382+ }
1383+
13731384bool isUsedAsBool (const Token* const tok)
13741385{
13751386 if (!tok)
13761387 return false ;
1388+ if (isForLoopIncrement (tok))
1389+ return false ;
13771390 if (astIsBool (tok))
13781391 return true ;
13791392 if (Token::Match (tok, " !|&&|%oror%|%comp%" ))
Original file line number Diff line number Diff line change @@ -4973,6 +4973,13 @@ class TestCondition : public TestFixture {
49734973 " }\n "
49744974 " }\n " );
49754975 ASSERT_EQUALS (" " , errout.str ());
4976+
4977+ check (" void f() {\n " // #11434
4978+ " const int N = 5;\n "
4979+ " bool a[N];\n "
4980+ " for (int i = 0; i < N; a[i++] = false);\n "
4981+ " }\n " );
4982+ ASSERT_EQUALS (" " , errout.str ());
49764983 }
49774984
49784985 void alwaysTrueTryCatch ()
You can’t perform that action at this time.
0 commit comments