Fixed #2160 (#2160 (Invalid unused variable report (style)))

This commit is contained in:
Daniel Marjamäki 2010-11-03 19:30:00 +01:00
parent 14803643ca
commit 1323cbdb6d
2 changed files with 24 additions and 1 deletions

View File

@ -2908,7 +2908,7 @@ void Tokenizer::setVarId()
unsigned int _varId = 0;
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (tok != _tokens && !Token::Match(tok, "[,;{}(] %type%"))
if (tok != _tokens && !Token::Match(tok, "[;{}(,] %type%"))
continue;
if (_errorLogger)
@ -2927,7 +2927,15 @@ void Tokenizer::setVarId()
}
if (Token::Match(tok, "[,;{}(] %type%"))
{
// not function declaration?
// TODO: Better checking
if (Token::Match(tok->tokAt(-2), "= %var% ("))
{
continue;
}
tok = tok->next();
}
if (tok->str() == "new")
continue;

View File

@ -150,6 +150,7 @@ private:
TEST_CASE(varid24);
TEST_CASE(varid25);
TEST_CASE(varid26); // ticket #1967 (list of function pointers)
TEST_CASE(varid27);
TEST_CASE(varidStl);
TEST_CASE(varid_delete);
TEST_CASE(varid_functions);
@ -2393,6 +2394,20 @@ private:
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
}
void varid27()
{
const std::string code("void f() {\n"
" int x;\n"
" x = a(y*x,10);\n"
"}");
const std::string expected("\n\n##file 0\n"
"1: void f ( ) {\n"
"2: int x@1 ;\n"
"3: x@1 = a ( y * x@1 , 10 ) ;\n"
"4: }\n");
ASSERT_EQUALS(expected, tokenizeDebugListing(code));
}
void varidStl()
{