Tokenizer::setVarIdNew: handle special case when there is an unknown macro. Ticket #2638

This commit is contained in:
Daniel Marjamäki 2012-04-21 17:57:20 +02:00
parent b86295fbcd
commit bd60dd46d0
2 changed files with 12 additions and 1 deletions

View File

@ -2845,6 +2845,17 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
}
}
// Check if array declaration is valid (#2638)
// invalid declaration: AAA a[4] = 0;
if (typeCount >= 2 && tok2 && tok2->str() == "[") {
const Token *tok3 = tok2;
while (tok3 && tok3->str() == "[") {
tok3 = tok3->link()->next();
}
if (Token::Match(tok3, "= %num%"))
return false;
}
return bool(typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%"));
}

View File

@ -3607,7 +3607,7 @@ private:
"3: AAA\n"
"4: a@1 [ 0 ] = 0 ;\n"
"5: }\n";
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
ASSERT_EQUALS(expected, tokenizeDebugListing(code, false, "test.c"));
}
void varid_using() {