parent
36af9b6450
commit
055489df5a
|
@ -1049,8 +1049,11 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
||||||
if (Token::Match(tok, "& %varid%", var->declarationId())) // Taking address of variable
|
if (Token::Match(tok, "& %varid%", var->declarationId())) // Taking address of variable
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Token::Match(tok, "%varid% =", var->declarationId()))
|
if (Token::Match(tok, "%varid% =", var->declarationId())) {
|
||||||
|
if (!bFirstAssignment && var->isInit() && Token::findmatch(tok->tokAt(2), "%varid%", Token::findsimplematch(tok->tokAt(3), ";"), var->declarationId()))
|
||||||
|
return false;
|
||||||
bFirstAssignment = true;
|
bFirstAssignment = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!bFirstAssignment && Token::Match(tok, "* %varid%", var->declarationId())) // dereferencing means access to previous content
|
if (!bFirstAssignment && Token::Match(tok, "* %varid%", var->declarationId())) // dereferencing means access to previous content
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -105,6 +105,7 @@ private:
|
||||||
TEST_CASE(varScope31); // #11099
|
TEST_CASE(varScope31); // #11099
|
||||||
TEST_CASE(varScope32); // #11441
|
TEST_CASE(varScope32); // #11441
|
||||||
TEST_CASE(varScope33);
|
TEST_CASE(varScope33);
|
||||||
|
TEST_CASE(varScope34);
|
||||||
|
|
||||||
TEST_CASE(oldStylePointerCast);
|
TEST_CASE(oldStylePointerCast);
|
||||||
TEST_CASE(invalidPointerCast);
|
TEST_CASE(invalidPointerCast);
|
||||||
|
@ -1614,6 +1615,19 @@ private:
|
||||||
errout.str());
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void varScope34() { // #11742
|
||||||
|
check("void f() {\n"
|
||||||
|
" bool b = false;\n"
|
||||||
|
" int i = 1;\n"
|
||||||
|
" for (int k = 0; k < 20; ++k) {\n"
|
||||||
|
" b = !b;\n"
|
||||||
|
" if (b)\n"
|
||||||
|
" i++;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
#define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__)
|
#define checkOldStylePointerCast(code) checkOldStylePointerCast_(code, __FILE__, __LINE__)
|
||||||
void checkOldStylePointerCast_(const char code[], const char* file, int line) {
|
void checkOldStylePointerCast_(const char code[], const char* file, int line) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
|
|
Loading…
Reference in New Issue