Fixed #1361 (### Internal error in Cppcheck. Please report it)

This commit is contained in:
Daniel Marjamäki 2010-02-07 15:00:19 +01:00
parent fb09b2fd37
commit cd5b95849d
2 changed files with 17 additions and 0 deletions

View File

@ -3102,7 +3102,15 @@ void Tokenizer::simplifyIfAddBraces()
++parlevel;
else if (tempToken->str() == ")")
{
if (parlevel == 0)
{
tok->deleteThis();
tempToken = 0;
break;
}
--parlevel;
}
else if (indentlevel == 0 && parlevel == 0 && tempToken->str() == ";")
break;

View File

@ -70,6 +70,7 @@ private:
TEST_CASE(ifAddBraces6);
TEST_CASE(ifAddBraces7);
TEST_CASE(ifAddBraces9);
TEST_CASE(ifAddBraces10);
TEST_CASE(whileAddBraces);
TEST_CASE(doWhileAddBraces);
@ -623,6 +624,14 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void ifAddBraces10()
{
// ticket #1361
const char code[] = "{ DEBUG(if (x) y; else z); }";
const char expected[] = "{ DEBUG ( if ( x ) y ; else z ) ; }";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void whileAddBraces()
{
{