fix false positive for unused local class/struct variable
This commit is contained in:
parent
18e6509c5d
commit
301e59cea0
|
@ -1753,7 +1753,7 @@ void CheckOther::functionVariableUsage()
|
||||||
// standard type declaration with possible initialization
|
// standard type declaration with possible initialization
|
||||||
// int i; int j = 0; static int k;
|
// int i; int j = 0; static int k;
|
||||||
if (Token::Match(tok, "[;{}] static| %type% %var% ;|=") &&
|
if (Token::Match(tok, "[;{}] static| %type% %var% ;|=") &&
|
||||||
(nextIsStandardType(tok) || isRecordTypeWithoutSideEffects(tok->strAt(1) == "static" ? tok->tokAt(3) : tok->tokAt(2))))
|
!Token::Match(tok->next(), "return|throw"))
|
||||||
{
|
{
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
@ -1761,8 +1761,11 @@ void CheckOther::functionVariableUsage()
|
||||||
if (isStatic)
|
if (isStatic)
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
if (tok->isStandardType() || isRecordTypeWithoutSideEffects(tok->next()))
|
||||||
|
{
|
||||||
variables.addVar(tok->next(), Variables::standard, info,
|
variables.addVar(tok->next(), Variables::standard, info,
|
||||||
tok->tokAt(2)->str() == "=" || isStatic);
|
tok->tokAt(2)->str() == "=" || isStatic);
|
||||||
|
}
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ private:
|
||||||
TEST_CASE(localvarStruct3);
|
TEST_CASE(localvarStruct3);
|
||||||
TEST_CASE(localvarStruct4); // Ticket #31: sigsegv on incomplete struct
|
TEST_CASE(localvarStruct4); // Ticket #31: sigsegv on incomplete struct
|
||||||
TEST_CASE(localvarStruct5);
|
TEST_CASE(localvarStruct5);
|
||||||
|
TEST_CASE(localvarStruct6);
|
||||||
|
|
||||||
TEST_CASE(localvarOp); // Usage with arithmetic operators
|
TEST_CASE(localvarOp); // Usage with arithmetic operators
|
||||||
TEST_CASE(localvarInvert); // Usage with inverted variable
|
TEST_CASE(localvarInvert); // Usage with inverted variable
|
||||||
|
@ -2451,6 +2452,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarStruct6()
|
||||||
|
{
|
||||||
|
functionVariableUsage("class Type { };\n"
|
||||||
|
"class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" Type & get() { return t; }\n"
|
||||||
|
"private:\n"
|
||||||
|
" Type t;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void localvarOp()
|
void localvarOp()
|
||||||
{
|
{
|
||||||
const char op[] = "+-*/%&|^";
|
const char op[] = "+-*/%&|^";
|
||||||
|
|
Loading…
Reference in New Issue