Fixed #1424 (false positive: unintialized variable)

This commit is contained in:
Daniel Marjamäki 2010-02-20 13:24:50 +01:00
parent 084b21494a
commit ccef1d6eb5
2 changed files with 12 additions and 1 deletions

View File

@ -3196,6 +3196,9 @@ void Tokenizer::simplifyIfAddBraces()
bool innerIf = Token::simpleMatch(tempToken->next(), "if"); bool innerIf = Token::simpleMatch(tempToken->next(), "if");
if (Token::simpleMatch(tempToken->next(), "do {"))
tempToken = tempToken->tokAt(2)->link();
// insert close brace.. // insert close brace..
// In most cases it would work to just search for the next ';' and insert a closing brace after it. // In most cases it would work to just search for the next ';' and insert a closing brace after it.
// But here are special cases.. // But here are special cases..

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(ifAddBraces9); TEST_CASE(ifAddBraces9);
TEST_CASE(ifAddBraces10); TEST_CASE(ifAddBraces10);
TEST_CASE(ifAddBraces11); TEST_CASE(ifAddBraces11);
TEST_CASE(ifAddBraces12);
TEST_CASE(whileAddBraces); TEST_CASE(whileAddBraces);
TEST_CASE(doWhileAddBraces); TEST_CASE(doWhileAddBraces);
@ -636,12 +637,19 @@ private:
void ifAddBraces11() void ifAddBraces11()
{ {
// ticket #1361
const char code[] = "{ if (x) if (y) ; else ; }"; const char code[] = "{ if (x) if (y) ; else ; }";
const char expected[] = "{ if ( x ) { if ( y ) { ; } else { ; } } }"; const char expected[] = "{ if ( x ) { if ( y ) { ; } else { ; } } }";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
} }
void ifAddBraces12()
{
// ticket #1424
const char code[] = "{ if (x) do { } while(x); }";
const char expected[] = "{ if ( x ) { do { } while ( x ) ; } }";
ASSERT_EQUALS(expected, tokenizeAndStringify(code, true));
}
void whileAddBraces() void whileAddBraces()
{ {
{ {