From ccef1d6eb554fbde4b6f34b98961c4c2d1086a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 20 Feb 2010 13:24:50 +0100 Subject: [PATCH] Fixed #1424 (false positive: unintialized variable) --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 16e59334e..652a62e07 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3196,6 +3196,9 @@ void Tokenizer::simplifyIfAddBraces() bool innerIf = Token::simpleMatch(tempToken->next(), "if"); + if (Token::simpleMatch(tempToken->next(), "do {")) + tempToken = tempToken->tokAt(2)->link(); + // insert close brace.. // In most cases it would work to just search for the next ';' and insert a closing brace after it. // But here are special cases.. diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5a96adf65..db5718c5b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -72,6 +72,7 @@ private: TEST_CASE(ifAddBraces9); TEST_CASE(ifAddBraces10); TEST_CASE(ifAddBraces11); + TEST_CASE(ifAddBraces12); TEST_CASE(whileAddBraces); TEST_CASE(doWhileAddBraces); @@ -636,12 +637,19 @@ private: void ifAddBraces11() { - // ticket #1361 const char code[] = "{ if (x) if (y) ; else ; }"; const char expected[] = "{ if ( x ) { if ( y ) { ; } else { ; } } }"; 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() { {