Fixed #3785 (false positive: (style) Variable 'dinv' is assigned a value that is never used)

This commit is contained in:
Daniel Marjamäki 2012-05-08 12:04:54 -07:00
parent dad2fb6db1
commit 8236cd4d50
2 changed files with 11 additions and 2 deletions

View File

@ -2637,11 +2637,12 @@ void Tokenizer::setVarId()
for (Token *tok = list.front(); tok; tok = tok->next()) {
// scope info to handle shadow variables..
if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) {
if (tok->str() == "(" &&
(Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {"))) {
scopeInfo.push(variableId);
} else if (tok->str() == "{") {
scopestartvarid.push(_varId);
if (Token::simpleMatch(tok->previous(), ")")) {
if (Token::simpleMatch(tok->previous(), ")") || Token::Match(tok->tokAt(-2), ") %type%")) {
executableScope.push(true);
} else {
executableScope.push(executableScope.top());

View File

@ -213,6 +213,7 @@ private:
TEST_CASE(varid45); // #3466
TEST_CASE(varid46); // struct varname
TEST_CASE(varid47); // function parameters
TEST_CASE(varid48); // #3785 - return (a*b)
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
@ -3241,6 +3242,13 @@ private:
tokenizeDebugListing(code, false, "test.cpp"));
}
void varid48() { // #3785 - return (a*b)
const std::string code("int X::f(int b) const { return(a*b); }");
ASSERT_EQUALS("\n\n##file 0\n"
"1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n",
tokenizeDebugListing(code, false, "test.c"));
}
void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n"
" delete d;\n"