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