Fixed #8148 (Tokenizer: Braces are not added properly in do while)

This commit is contained in:
Daniel Marjamäki 2017-08-16 18:55:34 +02:00
parent 2a4f68ccf8
commit 92e9744020
2 changed files with 16 additions and 5 deletions

View File

@ -4473,11 +4473,11 @@ Token *Tokenizer::simplifyAddBracesToCommand(Token *tok)
tokEnd=simplifyAddBracesPair(tok,true);
} else if (tok->str()=="while") {
Token *tokPossibleDo=tok->previous();
if (tokPossibleDo &&
tokPossibleDo->str()=="}")
if (Token::simpleMatch(tok->previous(), "{"))
tokPossibleDo = nullptr;
else if (Token::simpleMatch(tokPossibleDo,"}"))
tokPossibleDo = tokPossibleDo->link();
if (!tokPossibleDo ||
tokPossibleDo->strAt(-1) != "do")
if (!tokPossibleDo || tokPossibleDo->strAt(-1) != "do")
tokEnd=simplifyAddBracesPair(tok,true);
} else if (tok->str()=="do") {
tokEnd=simplifyAddBracesPair(tok,false);

View File

@ -1343,6 +1343,17 @@ private:
"}";
ASSERT_EQUALS(result, tokenizeAndStringify(code, true));
}
{
// #8148 - while inside the do-while body
const char code[] = "void foo() {\n"
" do { while (x) f(); } while (y);\n"
"}";
const char result[] = "void foo ( ) {\n"
"do { while ( x ) { f ( ) ; } } while ( y ) ;\n"
"}";
ASSERT_EQUALS(result, tokenizeAndStringify(code, true));
}
}
void forAddBraces1() {