From 2e3f26ba58086749d9ab38867609b400ddd94345 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Mon, 16 Jun 2014 21:36:31 +0200 Subject: [PATCH] Patch from Dmitry-Me: reorder checks so that cheaper ones go first, reuse previously computed values, return early on edge condition --- lib/tokenize.cpp | 14 ++++++++------ test/teststl.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 18f357e34..8484d6015 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7316,8 +7316,9 @@ void Tokenizer::simplifyEnum() tok = tok->previous(); } - if (Token::Match(tok, "class|struct|namespace") && tok->next() && - (!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) { + if (tok && tok->next() && + (!tok->previous() || (tok->previous()->str() != "enum")) && + Token::Match(tok, "class|struct|namespace")) { className = tok->next()->str(); classLevel = 0; } else if (tok->str() == "}") { @@ -7347,8 +7348,8 @@ void Tokenizer::simplifyEnum() // check for name if (tok->next()->isName()) { - enumType = tok->next(); tok = tok->next(); + enumType = tok; } // check for C++0x typed enumeration @@ -7360,8 +7361,8 @@ void Tokenizer::simplifyEnum() return; // can't recover } - typeTokenStart = tok->next(); tok = tok->next(); + typeTokenStart = tok; typeTokenEnd = typeTokenStart; while (typeTokenEnd->next() && (typeTokenEnd->next()->str() == "::" || @@ -7504,6 +7505,9 @@ void Tokenizer::simplifyEnum() // Substitute enum values { + if (!tok1) + return; + if (_settings->terminated()) return; @@ -7520,8 +7524,6 @@ void Tokenizer::simplifyEnum() bool simplify = false; EnumValue *ev = nullptr; - if (!tok1) - return; for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) { if (tok2->str() == "}") { --level; diff --git a/test/teststl.cpp b/test/teststl.cpp index 6382af406..23720ee42 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1323,10 +1323,10 @@ private: ASSERT_EQUALS("", errout.str()); } - template - size_t getArraylength( const T(&)[n]) { - return n; - } + template + size_t getArraylength(const T(&)[n]) { + return n; + } void stlBoundaries1() { const std::string stlCont[] = { @@ -1351,8 +1351,8 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str()); - // #5926 no FP Dangerous iterator comparison using operator< on 'std::deque'. - check("void f() {\n" + // #5926 no FP Dangerous iterator comparison using operator< on 'std::deque'. + check("void f() {\n" " std::deque::iterator it;\n" " for (it = ab.begin(); ab.end() > it; ++it) {}\n" "}");