From 32f7a789df7c0c25e8a0deb03aceb20e0e659b0c Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Wed, 17 Sep 2014 10:54:53 +0400 Subject: [PATCH] Merge overlapping patterns, move declarations --- lib/checkunusedvar.cpp | 4 +--- lib/templatesimplifier.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 35daefd9c..eb47d7f1c 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1232,9 +1232,7 @@ void CheckUnusedVar::checkStructMemberUsage() if (Token::Match(tok->next(), "%type% %var% [;[]")) varname = tok->strAt(2); - else if (Token::Match(tok->next(), "%type% %type% %var% [;[]")) - varname = tok->strAt(3); - else if (Token::Match(tok->next(), "%type% * %var% [;[]")) + else if (Token::Match(tok->next(), "%type% %type%|* %var% [;[]")) varname = tok->strAt(3); else if (Token::Match(tok->next(), "%type% %type% * %var% [;[]")) varname = tok->strAt(4); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 72f3cc705..4b19253fa 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -862,13 +862,14 @@ static std::string ShiftInt(const char cop, const Token* left, const Token* righ const MathLib::bigint leftInt = MathLib::toLongNumber(left->str()); const MathLib::bigint rightInt = MathLib::toLongNumber(right->str()); const bool rightIntIsPositive = rightInt >= 0; - const bool leftIntIsPositive = leftInt >= 0; - const bool leftOperationIsNotLeftShift = left->previous()->str() != "<<"; - const bool operandIsLeftShift = right->previous()->str() == "<<"; if (cop == '<') { + const bool leftOperationIsNotLeftShift = left->previous()->str() != "<<"; + const bool operandIsLeftShift = right->previous()->str() == "<<"; + // Ensure that its not a shift operator as used for streams if (leftOperationIsNotLeftShift && operandIsLeftShift && rightIntIsPositive) { + const bool leftIntIsPositive = leftInt >= 0; if (!leftIntIsPositive) { // In case the left integer is negative, e.g. -1000 << 16. Do not simplify. return left->str() + " << " + right->str(); }