Fixed #8148 (Tokenizer: Braces are not added properly in do while)
This commit is contained in:
parent
2a4f68ccf8
commit
92e9744020
|
@ -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()=="}")
|
||||
tokPossibleDo=tokPossibleDo->link();
|
||||
if (!tokPossibleDo ||
|
||||
tokPossibleDo->strAt(-1) != "do")
|
||||
if (Token::simpleMatch(tok->previous(), "{"))
|
||||
tokPossibleDo = nullptr;
|
||||
else if (Token::simpleMatch(tokPossibleDo,"}"))
|
||||
tokPossibleDo = tokPossibleDo->link();
|
||||
if (!tokPossibleDo || tokPossibleDo->strAt(-1) != "do")
|
||||
tokEnd=simplifyAddBracesPair(tok,true);
|
||||
} else if (tok->str()=="do") {
|
||||
tokEnd=simplifyAddBracesPair(tok,false);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue