Fix for ticket 337 ('scope can be limited' false positive with variables referenced by pointers)

This commit is contained in:
Daniel Marjamäki 2009-05-27 19:38:26 +02:00
parent ea4232fb06
commit 650d58e3de
2 changed files with 21 additions and 0 deletions

View File

@ -580,6 +580,11 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn
--parlevel; --parlevel;
} }
// Bail out if references are used
else if (Token::simpleMatch(tok, (std::string("& ") + varname).c_str()))
{
return;
}
else if (tok->str() == varname) else if (tok->str() == varname)
{ {

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(varScope1); TEST_CASE(varScope1);
TEST_CASE(varScope2); TEST_CASE(varScope2);
TEST_CASE(varScope3);
TEST_CASE(nullpointer1); TEST_CASE(nullpointer1);
TEST_CASE(nullpointer2); TEST_CASE(nullpointer2);
@ -395,6 +396,21 @@ private:
ASSERT_EQUALS(std::string(""), errout.str()); ASSERT_EQUALS(std::string(""), errout.str());
} }
void varScope3()
{
varScope("void foo()\n"
"{\n"
" int i;\n"
" int *p = 0;\n"
" if (abc)\n"
" {\n"
" p = &i;\n"
" }\n"
" *p = 1;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}