Fixed #3776 (Tokenizer::setVarId: No varid set when unknown macro is used before variable declaration)

This commit is contained in:
Daniel Marjamäki 2012-05-15 07:17:31 +02:00
parent 42fd19fb37
commit a0e5fad6a9
2 changed files with 18 additions and 1 deletions

View File

@ -2677,7 +2677,8 @@ void Tokenizer::setVarId()
}
if (tok == list.front() || Token::Match(tok, "[;{}]") ||
(Token::Match(tok,"[(,]") && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {")))) {
(Token::Match(tok,"[(,]") && (!executableScope.top() || Token::simpleMatch(tok->link(), ") {"))) ||
(tok->isName() && tok->str().at(tok->str().length()-1U) == ':')) {
// locate the variable name..
const Token *tok2 = (tok->isName()) ? tok : tok->next();

View File

@ -231,6 +231,7 @@ private:
TEST_CASE(varid_in_class5); // #3584 - std::vector<::FOO::B> b;
TEST_CASE(varid_in_class6); // #3755
TEST_CASE(varid_in_class7); // set variable id for struct members
TEST_CASE(varid_in_class8); // unknown macro in class
TEST_CASE(varid_operator);
TEST_CASE(varid_throw);
TEST_CASE(varid_unknown_macro); // #2638 - unknown macro is not type
@ -3618,6 +3619,21 @@ private:
tokenizeDebugListing(code));
}
void varid_in_class8() { // #3776 - unknown macro
const char code[] = "class A {\n"
" UNKNOWN_MACRO(A)\n"
"private:\n"
" int x;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: UNKNOWN_MACRO ( A )\n"
"3: private:\n"
"4: int x@1 ;\n"
"5: } ;\n",
tokenizeDebugListing(code));
}
void varid_operator() {
{
const std::string actual = tokenizeDebugListing(