Fixed false negative #4657
This commit is contained in:
parent
c600479c20
commit
1e66e0b931
|
@ -2149,7 +2149,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
||||||
if (tok == forHeadEnd)
|
if (tok == forHeadEnd)
|
||||||
forHeadEnd = 0;
|
forHeadEnd = 0;
|
||||||
|
|
||||||
if (noContinue && tok->scope() == scope && !forHeadEnd && scope->type != Scope::eSwitch && Token::Match(tok, "%varid% =", var->varId())) { // Assigned in outer scope.
|
if (loopVariable && noContinue && tok->scope() == scope && !forHeadEnd && scope->type != Scope::eSwitch && Token::Match(tok, "%varid% =", var->varId())) { // Assigned in outer scope.
|
||||||
loopVariable = false;
|
loopVariable = false;
|
||||||
unsigned int indent = 0;
|
unsigned int indent = 0;
|
||||||
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) { // Ensure that variable isn't used on right side of =, too
|
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) { // Ensure that variable isn't used on right side of =, too
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
TEST_CASE(varScope14);
|
TEST_CASE(varScope14);
|
||||||
TEST_CASE(varScope15); // #4573 if-else-if
|
TEST_CASE(varScope15); // #4573 if-else-if
|
||||||
TEST_CASE(varScope16);
|
TEST_CASE(varScope16);
|
||||||
|
TEST_CASE(varScope17);
|
||||||
|
|
||||||
TEST_CASE(oldStylePointerCast);
|
TEST_CASE(oldStylePointerCast);
|
||||||
TEST_CASE(invalidPointerCast);
|
TEST_CASE(invalidPointerCast);
|
||||||
|
@ -905,6 +906,17 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'a' can be reduced.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'a' can be reduced.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void varScope17() {
|
||||||
|
varScope("void f() {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" if (a) {\n"
|
||||||
|
" x = stuff(x);\n"
|
||||||
|
" morestuff(x);\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void checkOldStylePointerCast(const char code[]) {
|
void checkOldStylePointerCast(const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue