Function usage : Fixed false positives for inline structs

This commit is contained in:
Daniel Marjamäki 2009-01-04 08:16:07 +00:00
parent 68d08b73b6
commit dd914c0089
2 changed files with 20 additions and 0 deletions

View File

@ -842,6 +842,14 @@ void CheckOther::functionVariableUsage()
if ( indentlevel <= 0 )
break;
}
else if ( Token::simpleMatch(tok, "struct {") )
{
while ( tok && tok->str() != "}" )
tok = tok->next();
if ( tok )
continue;
break;
}
if ( Token::Match(tok, "[;{}] bool|char|short|int|long|float|double %var% ;|=") )
varUsage[ tok->strAt(2) ] = USAGE_DECLARE;

View File

@ -62,6 +62,7 @@ private:
TEST_CASE( localvar3 );
TEST_CASE( localvar4 );
TEST_CASE( localvar5 );
TEST_CASE( localvar6 );
}
void structmember1()
@ -186,6 +187,17 @@ private:
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void localvar6()
{
functionVariableUsage( "void foo()\n"
"{\n"
" static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\n"
" return bounds.x + bounds.y + bounds.w + bounds.h;\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
};
REGISTER_TEST( TestUnusedVar )