Fixed #609 (Tokenizer: don't add {} after do-while();)

http://sourceforge.net/apps/trac/cppcheck/ticket/609
This commit is contained in:
Slava Semushin 2009-08-22 14:49:45 +07:00
parent 7b3fdec5cf
commit cbeb45566b
2 changed files with 17 additions and 0 deletions

View File

@ -1805,6 +1805,16 @@ bool Tokenizer::simplifyIfAddBraces()
{
if (Token::Match(tok, "if|for|while ("))
{
// don't add "{}" around ";" in "do {} while();" (#609)
const Token *prev = tok->previous();
if (Token::simpleMatch(prev, "} while") &&
prev->link() &&
prev->link()->previous() &&
prev->link()->previous()->str() == "do")
{
continue;
}
// Goto the ending ')'
int parlevel = 1;
tok = tok->next();

View File

@ -59,6 +59,7 @@ private:
TEST_CASE(ifAddBraces5);
TEST_CASE(ifAddBraces6);
TEST_CASE(ifAddBraces7);
TEST_CASE(ifAddBraces8);
TEST_CASE(whileAddBraces);
@ -505,6 +506,12 @@ private:
"}", tokenizeAndStringify(code, true));
}
void ifAddBraces8()
{
const char code[] = "do { ; } while(0);";
ASSERT_EQUALS("do { ; } while ( false ) ;", tokenizeAndStringify(code, true));
}
void whileAddBraces()
{
{