From 80df7ea839afb580c200d8002d0b70f87aff7f4a Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Fri, 7 Oct 2011 00:54:44 +0200 Subject: [PATCH] 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. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c61f7fe3a..9dffa72e7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(";"); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7b9ae1475..af842c37f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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