Fixed false positive #3941.

This commit is contained in:
PKEuS 2012-07-29 06:39:43 -07:00
parent 1ec3c9f634
commit 26a2379f9f
2 changed files with 13 additions and 1 deletions

View File

@ -1595,7 +1595,7 @@ void CheckOther::checkVariableScope()
tok = tok->tokAt(3);
if (!tok->isNumber() && tok->type() != Token::eString && tok->type() != Token::eChar && !tok->isBoolean())
continue;
} else if (tok->str() == "=" &&
} else if ((tok->str() == "=") &&
((!tok->next()->isNumber() && tok->next()->type() != Token::eString && tok->next()->type() != Token::eChar && !tok->next()->isBoolean()) || tok->strAt(2) != ";"))
continue;
lookupVar(tok, var);

View File

@ -64,6 +64,7 @@ private:
TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope
TEST_CASE(varScope12);
TEST_CASE(varScope13); // variable usage in inner loop
TEST_CASE(varScope14);
TEST_CASE(oldStylePointerCast);
TEST_CASE(invalidPointerCast);
@ -754,6 +755,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void varScope14() {
// #3941
varScope("void f() {\n"
" const int i( foo());\n"
" if(a) {\n"
" for ( ; i < 10; ++i) ;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkOldStylePointerCast(const char code[]) {
// Clear the error buffer..
errout.str("");