Fix for ticket 337 ('scope can be limited' false positive with variables referenced by pointers)
This commit is contained in:
parent
ea4232fb06
commit
650d58e3de
|
@ -580,6 +580,11 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn
|
|||
--parlevel;
|
||||
}
|
||||
|
||||
// Bail out if references are used
|
||||
else if (Token::simpleMatch(tok, (std::string("& ") + varname).c_str()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
else if (tok->str() == varname)
|
||||
{
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
|
||||
TEST_CASE(varScope1);
|
||||
TEST_CASE(varScope2);
|
||||
TEST_CASE(varScope3);
|
||||
|
||||
TEST_CASE(nullpointer1);
|
||||
TEST_CASE(nullpointer2);
|
||||
|
@ -395,6 +396,21 @@ private:
|
|||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue