Fixed #2475 (False positive in structure initialisation: The scope of the variable bits can be reduced)
This commit is contained in:
parent
bd5e9e5309
commit
965c1a94fd
|
@ -2008,7 +2008,17 @@ void CheckOther::lookupVar(const Token *tok1, const std::string &varname)
|
|||
{
|
||||
if (tok->str() == "{")
|
||||
{
|
||||
++indentlevel;
|
||||
if (tok->strAt(-1) == "=")
|
||||
{
|
||||
if (Token::findmatch(tok, varname.c_str(), tok->link()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tok = tok->link();
|
||||
}
|
||||
else
|
||||
++indentlevel;
|
||||
}
|
||||
|
||||
else if (tok->str() == "}")
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
TEST_CASE(varScope8);
|
||||
TEST_CASE(varScope9); // classes may have extra side-effects
|
||||
TEST_CASE(varScope10); // Undefined macro FOR
|
||||
TEST_CASE(varScope11); // #2475 - struct initialization is not inner scope
|
||||
|
||||
TEST_CASE(oldStylePointerCast);
|
||||
|
||||
|
@ -576,6 +577,29 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void varScope11()
|
||||
{
|
||||
varScope("int f() {\n"
|
||||
" int x = 0;\n"
|
||||
" AB ab = { x, 0 };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
varScope("int f() {\n"
|
||||
" int x = 0;\n"
|
||||
" if (a == 0) { ++x; }\n"
|
||||
" AB ab = { x, 0 };\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
varScope("int f() {\n"
|
||||
" int x = 0;\n"
|
||||
" if (a == 0) { ++x; }\n"
|
||||
" if (a == 1) { AB ab = { x, 0 }; }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void checkOldStylePointerCast(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue