Variable usage : Fixed false positives for struct/union member variables

This commit is contained in:
Daniel Marjamäki 2009-01-04 17:35:19 +00:00
parent dcc15d7f22
commit dcd64a7ce6
2 changed files with 21 additions and 3 deletions

View File

@ -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();

View File

@ -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"