diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 532579a51..26c40db09 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3364,12 +3364,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Combine tokens.. combineOperators(); - // simplify simple calculations - for (Token *tok = list.front() ? list.front()->next() : nullptr; tok; tok = tok->next()) { - if (tok->isNumber()) - TemplateSimplifier::simplifyNumericCalculations(tok->previous()); - } - // remove extern "C" and extern "C" {} if (isCPP()) simplifyExternC(); @@ -3405,6 +3399,25 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // Remove "volatile", "inline", "register", and "restrict" simplifyKeyword(); + // simplify simple calculations inside <..> + if (isCPP()) { + Token *lt = nullptr; + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "[;{}]")) + lt = nullptr; + else if (Token::Match(tok, "%type <")) + lt = tok->next(); + else if (lt && Token::Match(tok, ">|>> %name%|::|(")) { + const Token * const end = tok; + for (tok = lt; tok != end; tok = tok->next()) { + if (tok->isNumber()) + TemplateSimplifier::simplifyNumericCalculations(tok->previous()); + } + lt = tok->next(); + } + } + } + // Convert K&R function declarations to modern C simplifyVarDecl(true); simplifyFunctionParameters(); diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 7d4c9c903..a0cf3330a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -765,6 +765,9 @@ static void valueFlowBitAnd(TokenList *tokenlist) if (tok->str() != "&") continue; + if (tok->values.size() == 1U && tok->values.front().isKnown()) + continue; + if (!tok->astOperand1() || !tok->astOperand2()) continue;