Fix #797 (false positive: variable scope when using function call)

This commit is contained in:
Daniel Marjamäki 2009-10-06 17:45:28 +02:00
parent d598bed1c6
commit c3d56c1d13
3 changed files with 18 additions and 21 deletions

View File

@ -387,23 +387,7 @@ void CheckOther::checkVariableScope()
{ {
if (tok2->str() == "{") if (tok2->str() == "{")
{ {
int indentlevel2 = 0; tok = tok2->link();
for (tok = tok2; tok; tok = tok->next())
{
if (tok->str() == "{")
{
++indentlevel2;
}
if (tok->str() == "}")
{
--indentlevel2;
if (indentlevel2 <= 0)
{
tok = tok->next();
break;
}
}
}
break; break;
} }
if (Token::Match(tok2, "[,);]")) if (Token::Match(tok2, "[,);]"))
@ -415,11 +399,11 @@ void CheckOther::checkVariableScope()
break; break;
} }
if (tok->str() == "{") else if (tok->str() == "{")
{ {
++indentlevel; ++indentlevel;
} }
if (tok->str() == "}") else if (tok->str() == "}")
{ {
--indentlevel; --indentlevel;
if (indentlevel == 0) if (indentlevel == 0)

View File

@ -53,6 +53,7 @@ public:
checkOther.warningOldStylePointerCast(); checkOther.warningOldStylePointerCast();
checkOther.checkUnsignedDivision(); checkOther.checkUnsignedDivision();
checkOther.checkCharVariable(); checkOther.checkCharVariable();
checkOther.checkVariableScope();
} }
} }
@ -63,7 +64,6 @@ public:
if (settings->_checkCodingStyle) if (settings->_checkCodingStyle)
{ {
checkOther.warningRedundantCode(); checkOther.warningRedundantCode();
checkOther.checkVariableScope();
checkOther.checkConstantFunctionParameter(); checkOther.checkConstantFunctionParameter();
checkOther.checkStructMemberUsage(); checkOther.checkStructMemberUsage();
checkOther.checkIncompleteStatement(); checkOther.checkIncompleteStatement();

View File

@ -59,6 +59,7 @@ private:
TEST_CASE(varScope4); TEST_CASE(varScope4);
TEST_CASE(varScope5); TEST_CASE(varScope5);
TEST_CASE(varScope6); TEST_CASE(varScope6);
TEST_CASE(varScope7);
TEST_CASE(nullpointer1); TEST_CASE(nullpointer1);
TEST_CASE(nullpointer2); TEST_CASE(nullpointer2);
@ -441,7 +442,6 @@ private:
Tokenizer tokenizer; Tokenizer tokenizer;
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -582,6 +582,19 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void varScope7()
{
varScope("void f(int x)\n"
"{\n"
" int y = 0;\n"
" b(y);\n"
" if (x) {\n"
" y++;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkNullPointer(const char code[]) void checkNullPointer(const char code[])
{ {
// Tokenize.. // Tokenize..