From 69bacde479d28a589fc47dc3e5f23fd24635fe6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 9 Dec 2010 19:35:52 +0100 Subject: [PATCH] Tokenizer: Cleanup redundant statement '; x = x + 0;'. Ticket: #2283 --- lib/tokenize.cpp | 8 ++++++++ test/testsimplifytokens.cpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5ff2983e3..772738628 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6566,6 +6566,14 @@ bool Tokenizer::simplifyCalculations() if (Token::Match(tok->previous(), "[+-] 0")) { tok = tok->previous(); + if (Token::Match(tok->tokAt(-4), "[;{}] %var% = %var% [+-] 0 ;") && + tok->strAt(-3) == tok->strAt(-1)) + { + tok = tok->previous()->previous()->previous(); + tok->deleteThis(); + tok->deleteThis(); + tok->deleteThis(); + } tok->deleteThis(); tok->deleteThis(); ret = true; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 061110fc2..e2b6e5f5b 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2563,6 +2563,8 @@ private: const char code[] = "void * operator new[](size_t);"; ASSERT_EQUALS("void * operator new [ ] ( size_t ) ;", tok(code)); } + + ASSERT_EQUALS(";", tok("; x = x + 0;")); }