Fixed false negative #4663
This commit is contained in:
parent
72d37f4c2c
commit
d9f7042992
|
@ -2104,10 +2104,17 @@ void CheckOther::checkVariableScope()
|
||||||
bool used = false; // Don't warn about unused variables
|
bool used = false; // Don't warn about unused variables
|
||||||
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() == "{" && tok->strAt(-1) != "=") {
|
if (tok->str() == "{" && tok->strAt(-1) != "=") {
|
||||||
if (used || !checkInnerScope(tok, var, used)) {
|
if (used) {
|
||||||
|
bool used2 = false;
|
||||||
|
if (!checkInnerScope(tok, var, used2) || used2) {
|
||||||
reduce = false;
|
reduce = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (!checkInnerScope(tok, var, used)) {
|
||||||
|
reduce = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
} else if (tok->varId() == var->varId() || tok->str() == "goto") {
|
} else if (tok->varId() == var->varId() || tok->str() == "goto") {
|
||||||
reduce = false;
|
reduce = false;
|
||||||
|
@ -2127,7 +2134,6 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
||||||
bool noContinue = true;
|
bool noContinue = true;
|
||||||
const Token* forHeadEnd = 0;
|
const Token* forHeadEnd = 0;
|
||||||
const Token* end = tok->link();
|
const Token* end = tok->link();
|
||||||
|
|
||||||
if (scope->type == Scope::eUnconditional && (tok->strAt(-1) == ")" || tok->previous()->isName())) // Might be an unknown macro like BOOST_FOREACH
|
if (scope->type == Scope::eUnconditional && (tok->strAt(-1) == ")" || tok->previous()->isName())) // Might be an unknown macro like BOOST_FOREACH
|
||||||
loopVariable = true;
|
loopVariable = true;
|
||||||
|
|
||||||
|
|
|
@ -915,6 +915,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout.str());
|
||||||
|
|
||||||
|
varScope("void f() {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" if (a) {\n"
|
||||||
|
" x = stuff(x);\n"
|
||||||
|
" morestuff(x);\n"
|
||||||
|
" }\n"
|
||||||
|
" if (b) {}\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[]) {
|
||||||
|
|
Loading…
Reference in New Issue