variable usage: fix false positives when __attribute__ is used. Ticket: #1792

This commit is contained in:
Robert Reif 2010-06-16 18:04:31 +02:00 committed by Daniel Marjamäki
parent 7dba21858a
commit ee7ad272d6
3 changed files with 17 additions and 0 deletions

View File

@ -104,6 +104,7 @@ void Token::deleteThis()
_isName = _next->_isName;
_isNumber = _next->_isNumber;
_isBoolean = _next->_isBoolean;
_isUnused = _next->_isUnused;
_varId = _next->_varId;
_fileIndex = _next->_fileIndex;
_linenr = _next->_linenr;

View File

@ -7688,6 +7688,10 @@ void Tokenizer::simplifyAttribute()
if (Token::Match(tok->previous(), "%type%"))
tok->previous()->isUnused(true);
}
// check if before variable name
else if (Token::Match(tok->next()->link()->next(), "%type%"))
tok->next()->link()->next()->isUnused(true);
}
Token::eraseTokens(tok, tok->next()->link()->next());

View File

@ -1935,6 +1935,18 @@ private:
" bool test __attribute__((unused)) = true;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
functionVariableUsage("int foo()\n"
"{\n"
" bool __attribute__((unused)) test;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
functionVariableUsage("int foo()\n"
"{\n"
" bool __attribute__((unused)) test = true;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};