Fixed #1097 (Internal error: When macro is not expanded 'ABC(for (i=0;i<10;i++) ..);')

This commit is contained in:
Daniel Marjamäki 2009-12-12 19:58:19 +01:00
parent 1002457b17
commit bc808710a0
2 changed files with 20 additions and 0 deletions

View File

@ -2347,6 +2347,9 @@ void Tokenizer::simplifyIfAddBraces()
{ {
for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL)
{ {
if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|else|)|:"))
continue;
if (Token::Match(tok, "if|for|while (")) if (Token::Match(tok, "if|for|while ("))
{ {
// don't add "{}" around ";" in "do {} while();" (#609) // don't add "{}" around ";" in "do {} while();" (#609)

View File

@ -41,6 +41,7 @@ private:
{ {
TEST_CASE(tokenize1); TEST_CASE(tokenize1);
TEST_CASE(tokenize2); TEST_CASE(tokenize2);
TEST_CASE(tokenize3);
TEST_CASE(minus); TEST_CASE(minus);
@ -234,6 +235,22 @@ private:
ASSERT_EQUALS("{ sizeof a , sizeof b }", tokenizeAndStringify(code.c_str())); ASSERT_EQUALS("{ sizeof a , sizeof b }", tokenizeAndStringify(code.c_str()));
} }
void tokenize3()
{
errout.str("");
const std::string code("void foo()\n"
"{\n"
" int i;\n"
" ABC(for(i=0;i<10;i++) x());\n"
"}");
ASSERT_EQUALS("void foo ( )\n"
"{\n"
"int i ;\n"
"ABC ( for ( i = 0 ; i < 10 ; i ++ ) x ( ) ) ;\n"
"}", tokenizeAndStringify(code.c_str()));
ASSERT_EQUALS("", errout.str());
}
void minus() void minus()
{ {
ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12")); ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));