From 7fdd497c449d126a6151990147d8def9fdd5cc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 25 May 2009 08:26:11 +0200 Subject: [PATCH] Fix ticket #317 (pre-increment causes style false positive) --- src/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 5f9846bdb..45f47bb1d 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2255,7 +2255,7 @@ bool Tokenizer::simplifyKnownVariables() if (Token::Match(tok3->next(), "%varid% ++|--", varid)) { const std::string op(tok3->strAt(2)); - if (Token::Match(tok3, "; %any% %any% ;")) + if (Token::Match(tok3, "[{};] %any% %any% ;")) { tok3->deleteNext(); tok3->deleteNext(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 622eee2b0..1ce68068d 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -67,6 +67,8 @@ private: TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )" TEST_CASE(declareVar); + TEST_CASE(removePostIncrement); + TEST_CASE(elseif1); TEST_CASE(sizeof1); @@ -378,6 +380,20 @@ private: ASSERT_EQUALS(code, tok(code)); } + + void removePostIncrement() + { + const char code[] = "void f()\n" + "{\n" + " unsigned int c = 0;\n" + " c++;\n" + " if (c>0) { c++; }\n" + " c++;\n" + "}\n"; + ASSERT_EQUALS(std::string("void f ( ) { int c ; c = 3 ; ; { ; } ; } "), tok(code)); + } + + std::string elseif(const char code[]) { std::istringstream istr(code);