@@ -792,7 +792,7 @@ void CheckOtherImpl::redundantAssignmentSameValueError(const Token *tok, const V
792792// ---------------------------------------------------------------------------
793793static inline bool isFunctionOrBreakPattern (const Token *tok)
794794{
795- return Token::Match (tok, " %name% (" ) || Token::Match (tok, " break|continue|return|exit| goto|throw" );
795+ return Token::Match (tok, " %name% (" ) || (tok-> isKeyword () && Token::Match (tok, " break|continue|return|goto|throw" ) );
796796}
797797
798798void CheckOtherImpl::redundantBitwiseOperationInSwitchError ()
@@ -2324,18 +2324,12 @@ static bool isConstStatement(const Token *tok, const Library& library, bool plat
23242324
23252325static bool isVoidStmt (const Token *tok)
23262326{
2327- if (Token::simpleMatch (tok, " ( void" ))
2327+ if (Token::simpleMatch (tok, " ( void" ) && !(tok-> astOperand1 () && (tok-> astOperand1 ()-> isLiteral () || isNullOperand (tok-> astOperand1 ()))) )
23282328 return true ;
2329- if (isCPPCast (tok) && tok->astOperand1 () && Token::Match (tok->astOperand1 ()->next (), " < void *| >" ))
2329+ if (isCPPCast (tok) && tok->astOperand1 () && Token::Match (tok->astOperand1 ()->next (), " < void *| >" ) &&
2330+ !(tok->astOperand2 () && (tok->astOperand2 ()->isLiteral () || isNullOperand (tok->astOperand2 ()))))
23302331 return true ;
2331- const Token *tok2 = tok;
2332- while (tok2->astOperand1 ())
2333- tok2 = tok2->astOperand1 ();
2334- if (Token::simpleMatch (tok2->previous (), " )" ) && Token::simpleMatch (tok2->linkAt (-1 ), " ( void" ))
2335- return true ;
2336- if (Token::simpleMatch (tok2, " ( void" ))
2337- return true ;
2338- return Token::Match (tok2->previous (), " delete|throw|return" );
2332+ return false ;
23392333}
23402334
23412335static bool isConstTop (const Token *tok)
@@ -2426,37 +2420,31 @@ void CheckOtherImpl::checkIncompleteStatement()
24262420
24272421void CheckOtherImpl::constStatementError (const Token *tok, const std::string &type, bool inconclusive)
24282422{
2429- const Token *valueTok = tok;
2430- while (valueTok && valueTok->isCast ())
2431- valueTok = valueTok->astOperand2 () ? valueTok->astOperand2 () : valueTok->astOperand1 ();
2432-
24332423 std::string msg;
24342424 if (Token::simpleMatch (tok, " ==" ))
24352425 msg = " Found suspicious equality comparison. Did you intend to assign a value instead?" ;
24362426 else if (Token::Match (tok, " ,|!|~|%cop%" ))
24372427 msg = " Found suspicious operator '" + tok->str () + " ', result is not used." ;
24382428 else if (Token::Match (tok, " %var%" ))
24392429 msg = " Unused variable value '" + tok->str () + " '" ;
2440- else if (isConstant (valueTok )) {
2430+ else if (isConstant (tok )) {
24412431 std::string typeStr (" string" );
2442- if (valueTok ->isNumber ())
2432+ if (tok ->isNumber ())
24432433 typeStr = " numeric" ;
2444- else if (valueTok ->isBoolean ())
2434+ else if (tok ->isBoolean ())
24452435 typeStr = " bool" ;
2446- else if (valueTok ->tokType () == Token::eChar)
2436+ else if (tok ->tokType () == Token::eChar)
24472437 typeStr = " character" ;
2448- else if (isNullOperand (valueTok ))
2449- typeStr = " NULL " ;
2450- else if (valueTok ->isEnumerator ())
2438+ else if (isNullOperand (tok ))
2439+ typeStr = " null " ;
2440+ else if (tok ->isEnumerator ())
24512441 typeStr = " enumerator" ;
24522442 msg = " Redundant code: Found a statement that begins with " + typeStr + " constant." ;
24532443 }
24542444 else if (!tok)
24552445 msg = " Redundant code: Found a statement that begins with " + type + " constant." ;
2456- else if (tok->isCast () && tok->tokType () == Token::Type::eExtendedOp) {
2457- msg = " Redundant code: Found unused cast " ;
2458- msg += valueTok ? " of expression '" + valueTok->expressionString () + " '." : " expression." ;
2459- }
2446+ else if (tok->isCast () && tok->tokType () == Token::Type::eExtendedOp)
2447+ msg = " Redundant code: Found unused cast in expression '" + tok->expressionString () + " '." ;
24602448 else if (tok->str () == " ?" && tok->tokType () == Token::Type::eExtendedOp)
24612449 msg = " Redundant code: Found unused result of ternary operator." ;
24622450 else if (tok->str () == " ." && tok->tokType () == Token::Type::eOther)
@@ -4154,7 +4142,8 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li
41544142 return v.nameToken ();
41554143 }
41564144 auto it = std::find_if (scope->functionList .cbegin (), scope->functionList .cend (), [&](const Function& f) {
4157- return f.type == FunctionType::eFunction && f.name () == var.name () && precedes (f.tokenDef , var.nameToken ());
4145+ return f.type == FunctionType::eFunction && f.name () == var.name ()
4146+ && (scope->isClassOrStructOrUnion () || precedes (f.tokenDef , var.nameToken ()));
41584147 });
41594148 if (it != scope->functionList .end ())
41604149 return it->tokenDef ;
0 commit comments