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);
|
tokEnd=simplifyAddBracesPair(tok,true);
|
||||||
} else if (tok->str()=="while") {
|
} else if (tok->str()=="while") {
|
||||||
Token *tokPossibleDo=tok->previous();
|
Token *tokPossibleDo=tok->previous();
|
||||||
if (tokPossibleDo &&
|
if (Token::simpleMatch(tok->previous(), "{"))
|
||||||
tokPossibleDo->str()=="}")
|
tokPossibleDo = nullptr;
|
||||||
|
else if (Token::simpleMatch(tokPossibleDo,"}"))
|
||||||
tokPossibleDo = tokPossibleDo->link();
|
tokPossibleDo = tokPossibleDo->link();
|
||||||
if (!tokPossibleDo ||
|
if (!tokPossibleDo || tokPossibleDo->strAt(-1) != "do")
|
||||||
tokPossibleDo->strAt(-1) != "do")
|
|
||||||
tokEnd=simplifyAddBracesPair(tok,true);
|
tokEnd=simplifyAddBracesPair(tok,true);
|
||||||
} else if (tok->str()=="do") {
|
} else if (tok->str()=="do") {
|
||||||
tokEnd=simplifyAddBracesPair(tok,false);
|
tokEnd=simplifyAddBracesPair(tok,false);
|
||||||
|
|
|
@ -1343,6 +1343,17 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(result, tokenizeAndStringify(code, true));
|
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() {
|
void forAddBraces1() {
|
||||||
|
|
Loading…
Reference in New Issue