diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 30b9bc3c5..816dffb7f 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1834,7 +1834,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) const // use; if| use; => use; while (Token::Match(tok2, "[;{}] use ; if| use ;")) { Token *t = tok2->tokAt(2); - t->deleteNext(2+(t->str()=="if")); + t->deleteNext(2+(t->str()=="if" ? 1 : 0)); done = false; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c243b138d..9b2aec1d5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4040,16 +4040,11 @@ void Tokenizer::simplifyCompoundAssignment() // Simplify compound assignments: // "a+=b" => "a = a + b" for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "[;{}] (") || Token::Match(tok, "[;{}:] *| (| %var%")) { - if (tok->str() == ":") { - if (tok->strAt(-2) != "case") - continue; - } - + if (Token::Match(tok, "[;{}] (| *| (| %var%")) { // backup current token.. Token * const tok1 = tok; - if (tok->next() && tok->next()->str() == "*") + if (tok->next()->str() == "*") tok = tok->next(); if (tok->next() && tok->next()->str() == "(") { @@ -4177,10 +4172,9 @@ void Tokenizer::simplifyConditionOperator() } } - if (tok->str() == "(") + if (tok->str() == "(" || tok->str() == "[" || + (tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) tok = tok->link(); - else if (tok->str() == ")") - break; if (Token::Match(tok, "[{};] *| %var% = %any% ? %any% : %any% ;") || Token::Match(tok, "[{};] return %any% ? %any% : %any% ;")) { @@ -4429,14 +4423,10 @@ bool Tokenizer::simplifyQuestionMark() if (tok->str() != "?") continue; - if (!tok->tokAt(-2)) + if (!Token::Match(tok->tokAt(-2), "=|,|(|[|{|}|;|case|return")) continue; - if (!Token::Match(tok->tokAt(-2), "=|,|(|case")) - continue; - - if (!tok->previous()->isBoolean() && - !tok->previous()->isNumber()) + if (!tok->previous()->isBoolean() && !tok->previous()->isNumber()) continue; // Find the ":" token.. @@ -8649,7 +8639,7 @@ void Tokenizer::simplifyBitfields() } } else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") && tok->next()->str() != "default") { - bool offset = (tok->next()->str() == "const"); + const bool offset = (tok->next()->str() == "const"); if (tok->strAt(3 + (offset ? 1 : 0)) != "{") { tok->deleteNext(4 + (offset ? 1 : 0)); diff --git a/test/redirect.h b/test/redirect.h index 159c0f8c4..aec7d05b6 100644 --- a/test/redirect.h +++ b/test/redirect.h @@ -64,7 +64,7 @@ public: private: std::ostringstream _out; std::ostringstream _err; - std::streambuf* _oldCout; + std::streambuf *_oldCout; std::streambuf *_oldCerr; }; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d1b25a7ed..9923b7514 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6797,7 +6797,7 @@ private: ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tokenizeAndStringify("; (*p) += y;")); ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;")); - ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;")); + ASSERT_EQUALS("void foo ( ) { switch ( n ) { case 0 : ; x = x + y ; break ; } }", tokenizeAndStringify("void foo() { switch (n) { case 0: x += y; break; } }")); ASSERT_EQUALS("; x . y = x . y + 1 ;", tokenizeAndStringify("; x.y += 1;"));