Fixed ticket #3176 (cppcheck reports wrong unused variable)

Label simplification didn't take count of the '(' parenthesis or the '&' and '*' operators inside or outside the parenthesis after the colon.
This commit is contained in:
Edoardo Prezioso 2011-10-07 00:54:44 +02:00
parent fe4ce594ce
commit 80df7ea839
2 changed files with 4 additions and 1 deletions

View File

@ -2834,7 +2834,7 @@ void Tokenizer::labels()
}
// simplify label..
if (Token::Match(tok, "[;{}] %var% : %var%"))
if (Token::Match(tok, "[;{}] %var% : (| *|&| %var%"))
{
if (!Token::Match(tok->next(), "public|protected|private"))
tok->tokAt(2)->insertToken(";");

View File

@ -5085,6 +5085,9 @@ private:
void labels()
{
ASSERT_EQUALS(" void f(){ ab:; a=0;}", labels_("void f() { ab: a=0; }"));
ASSERT_EQUALS(" void f(){ ab:;* b=0;}", labels_("void f() { ab: *b=0; }"));
ASSERT_EQUALS(" void f(){ ab:;& b=0;}", labels_("void f() { ab: &b=0; }"));
ASSERT_EQUALS(" void f(){ ab:;(* func)();}", labels_("void f() { ab: (*func)(); }"));
}
// Check simplifyInitVar