Variable usage : Fixed false positives for struct/union member variables
This commit is contained in:
parent
dcc15d7f22
commit
dcd64a7ce6
|
@ -838,7 +838,8 @@ void CheckOther::functionVariableUsage()
|
||||||
if ( indentlevel <= 0 )
|
if ( indentlevel <= 0 )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if ( Token::Match(tok, "struct|union|class {") )
|
else if ( Token::Match(tok, "struct|union|class {") ||
|
||||||
|
Token::Match(tok, "struct|union|class %type% {") )
|
||||||
{
|
{
|
||||||
while ( tok && tok->str() != "}" )
|
while ( tok && tok->str() != "}" )
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
|
@ -62,7 +62,10 @@ private:
|
||||||
TEST_CASE( localvar3 );
|
TEST_CASE( localvar3 );
|
||||||
TEST_CASE( localvar4 );
|
TEST_CASE( localvar4 );
|
||||||
TEST_CASE( localvar5 );
|
TEST_CASE( localvar5 );
|
||||||
TEST_CASE( localvar6 );
|
|
||||||
|
// Don't give false positives for variables in structs/unions
|
||||||
|
TEST_CASE( localvarStruct1 );
|
||||||
|
TEST_CASE( localvarStruct2 );
|
||||||
|
|
||||||
TEST_CASE( localvarMod ); // Usage with modulo
|
TEST_CASE( localvarMod ); // Usage with modulo
|
||||||
TEST_CASE( localvarInvert ); // Usage with inverted variable
|
TEST_CASE( localvarInvert ); // Usage with inverted variable
|
||||||
|
@ -193,7 +196,9 @@ private:
|
||||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvar6()
|
|
||||||
|
|
||||||
|
void localvarStruct1()
|
||||||
{
|
{
|
||||||
functionVariableUsage( "void foo()\n"
|
functionVariableUsage( "void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -203,6 +208,18 @@ private:
|
||||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void localvarStruct2()
|
||||||
|
{
|
||||||
|
functionVariableUsage( "void foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct ABC { int a, b, c; };\n"
|
||||||
|
" struct ABC abc = { 1, 2, 3 };\n"
|
||||||
|
"}\n" );
|
||||||
|
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void localvarMod()
|
void localvarMod()
|
||||||
{
|
{
|
||||||
functionVariableUsage( "int main()\n"
|
functionVariableUsage( "int main()\n"
|
||||||
|
|
Loading…
Reference in New Issue