Fixed #990 (Tokenizer::simplifyIfAddBraces() handle case where statement after if doesn't end by semicolon)
http://sourceforge.net/apps/trac/cppcheck/ticket/990
This commit is contained in:
parent
91f7c15c24
commit
41b2a52915
|
@ -2339,6 +2339,13 @@ void Tokenizer::simplifyIfAddBraces()
|
|||
--indentlevel;
|
||||
if (indentlevel == 0 && parlevel == 0)
|
||||
break;
|
||||
|
||||
else if (indentlevel < 0 && parlevel == 0)
|
||||
{
|
||||
// insert closing brace before this
|
||||
tempToken = tempToken->previous();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (tempToken->str() == "(")
|
||||
|
|
|
@ -64,6 +64,7 @@ private:
|
|||
TEST_CASE(ifAddBraces6);
|
||||
TEST_CASE(ifAddBraces7);
|
||||
TEST_CASE(ifAddBraces8);
|
||||
TEST_CASE(ifAddBraces9);
|
||||
|
||||
TEST_CASE(whileAddBraces);
|
||||
TEST_CASE(doWhileAddBraces);
|
||||
|
@ -554,6 +555,23 @@ private:
|
|||
ASSERT_EQUALS("do { ; } while ( false ) ;", tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
void ifAddBraces9()
|
||||
{
|
||||
// ticket #990
|
||||
const char code[] =
|
||||
"{"
|
||||
" for (int k=0; k<VectorSize; k++)"
|
||||
" LOG_OUT(ID_Vector[k])"
|
||||
"}";
|
||||
const char expected[] =
|
||||
"{ "
|
||||
"for ( int k = 0 ; k < VectorSize ; k ++ ) { "
|
||||
"LOG_OUT ( ID_Vector [ k ] ) "
|
||||
"} "
|
||||
"}";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
void whileAddBraces()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue