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:
Slava Semushin 2009-11-21 01:38:30 +06:00
parent 91f7c15c24
commit 41b2a52915
2 changed files with 25 additions and 0 deletions

View File

@ -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() == "(")

View File

@ -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()
{
{