Variable usage : Fixed a false positive for ("b = (int)a;" => a is read)
This commit is contained in:
parent
f79b06b5a0
commit
68d08b73b6
|
@ -816,14 +816,14 @@ static bool isOp(const Token *tok)
|
|||
tok->str() == ">" ||
|
||||
tok->str() == ">=" ||
|
||||
tok->str() == "<<" ||
|
||||
Token::Match(tok, "[+-*/&|,[]]")));
|
||||
Token::Match(tok, "[+-*/&|,[])]")));
|
||||
}
|
||||
|
||||
void CheckOther::functionVariableUsage()
|
||||
{
|
||||
// Parse all executing scopes..
|
||||
const Token *tok1 = Token::findmatch( _tokenizer->tokens(), ") const| {" );
|
||||
while ( tok1 )
|
||||
const Token *tok1 = _tokenizer->tokens();
|
||||
while ((tok1 = Token::findmatch( tok1->next(), ") const| {" )) != NULL)
|
||||
{
|
||||
// Varname, usage {1=declare, 2=read, 4=write}
|
||||
std::map<std::string, unsigned int> varUsage;
|
||||
|
@ -907,8 +907,5 @@ void CheckOther::functionVariableUsage()
|
|||
_errorLogger->reportErr(errmsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Goto next executing scope..
|
||||
tok1 = Token::findmatch( tok1->next(), ") const| {" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ private:
|
|||
TEST_CASE( localvar2 );
|
||||
TEST_CASE( localvar3 );
|
||||
TEST_CASE( localvar4 );
|
||||
TEST_CASE( localvar5 );
|
||||
}
|
||||
|
||||
void structmember1()
|
||||
|
@ -176,7 +177,15 @@ private:
|
|||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
|
||||
|
||||
void localvar5()
|
||||
{
|
||||
functionVariableUsage( "void foo()\n"
|
||||
"{\n"
|
||||
" int a = 0;\n"
|
||||
" b = (char)a;\n"
|
||||
"}\n" );
|
||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST( TestUnusedVar )
|
||||
|
|
Loading…
Reference in New Issue