Fixed #1581 (False positives 'The scope of the variable x can be reduced')
This commit is contained in:
parent
f6a526c8c8
commit
38a28e28ec
|
@ -667,7 +667,7 @@ void CheckOther::checkVariableScope()
|
|||
lookupVar(tok1->tokAt(6), tok1->strAt(1));
|
||||
}
|
||||
}
|
||||
else if (Token::Match(tok1, "%type% %var% [;=]"))
|
||||
else if (tok1->isStandardType() && Token::Match(tok1, "%type% %var% [;=]"))
|
||||
{
|
||||
lookupVar(tok1, tok1->strAt(1));
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ private:
|
|||
TEST_CASE(varScope6);
|
||||
TEST_CASE(varScope7);
|
||||
TEST_CASE(varScope8);
|
||||
TEST_CASE(varScope9); // classes may have extra side-effects
|
||||
|
||||
TEST_CASE(nullpointer1);
|
||||
TEST_CASE(nullpointer2);
|
||||
|
@ -633,6 +634,22 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable edgeResistance can be reduced\n", errout.str());
|
||||
}
|
||||
|
||||
void varScope9()
|
||||
{
|
||||
// classes may have extra side effects
|
||||
varScope("class fred {\n"
|
||||
"public:\n"
|
||||
" void x();\n"
|
||||
"};\n"
|
||||
"void test(int a) {\n"
|
||||
" fred f;\n"
|
||||
" if (a == 2) {\n"
|
||||
" f.x();\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void checkNullPointer(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue