@@ -791,7 +791,7 @@ void CheckOtherImpl::redundantAssignmentSameValueError(const Token *tok, const V
791791// ---------------------------------------------------------------------------
792792static inline bool isFunctionOrBreakPattern (const Token *tok)
793793{
794- return Token::Match (tok, " %name% (" ) || Token::Match (tok, " break|continue|return|exit| goto|throw" );
794+ return Token::Match (tok, " %name% (" ) || (tok-> isKeyword () && Token::Match (tok, " break|continue|return|goto|throw" ) );
795795}
796796
797797void CheckOtherImpl::redundantBitwiseOperationInSwitchError ()
@@ -2323,18 +2323,12 @@ static bool isConstStatement(const Token *tok, const Library& library, bool plat
23232323
23242324static bool isVoidStmt (const Token *tok)
23252325{
2326- if (Token::simpleMatch (tok, " ( void" ))
2326+ if (Token::simpleMatch (tok, " ( void" ) && !(tok-> astOperand1 () && (tok-> astOperand1 ()-> isLiteral () || isNullOperand (tok-> astOperand1 ()))) )
23272327 return true ;
2328- if (isCPPCast (tok) && tok->astOperand1 () && Token::Match (tok->astOperand1 ()->next (), " < void *| >" ))
2328+ if (isCPPCast (tok) && tok->astOperand1 () && Token::Match (tok->astOperand1 ()->next (), " < void *| >" ) &&
2329+ !(tok->astOperand2 () && (tok->astOperand2 ()->isLiteral () || isNullOperand (tok->astOperand2 ()))))
23292330 return true ;
2330- const Token *tok2 = tok;
2331- while (tok2->astOperand1 ())
2332- tok2 = tok2->astOperand1 ();
2333- if (Token::simpleMatch (tok2->previous (), " )" ) && Token::simpleMatch (tok2->linkAt (-1 ), " ( void" ))
2334- return true ;
2335- if (Token::simpleMatch (tok2, " ( void" ))
2336- return true ;
2337- return Token::Match (tok2->previous (), " delete|throw|return" );
2331+ return false ;
23382332}
23392333
23402334static bool isConstTop (const Token *tok)
@@ -2425,37 +2419,31 @@ void CheckOtherImpl::checkIncompleteStatement()
24252419
24262420void CheckOtherImpl::constStatementError (const Token *tok, const std::string &type, bool inconclusive)
24272421{
2428- const Token *valueTok = tok;
2429- while (valueTok && valueTok->isCast ())
2430- valueTok = valueTok->astOperand2 () ? valueTok->astOperand2 () : valueTok->astOperand1 ();
2431-
24322422 std::string msg;
24332423 if (Token::simpleMatch (tok, " ==" ))
24342424 msg = " Found suspicious equality comparison. Did you intend to assign a value instead?" ;
24352425 else if (Token::Match (tok, " ,|!|~|%cop%" ))
24362426 msg = " Found suspicious operator '" + tok->str () + " ', result is not used." ;
24372427 else if (Token::Match (tok, " %var%" ))
24382428 msg = " Unused variable value '" + tok->str () + " '" ;
2439- else if (isConstant (valueTok )) {
2429+ else if (isConstant (tok )) {
24402430 std::string typeStr (" string" );
2441- if (valueTok ->isNumber ())
2431+ if (tok ->isNumber ())
24422432 typeStr = " numeric" ;
2443- else if (valueTok ->isBoolean ())
2433+ else if (tok ->isBoolean ())
24442434 typeStr = " bool" ;
2445- else if (valueTok ->tokType () == Token::eChar)
2435+ else if (tok ->tokType () == Token::eChar)
24462436 typeStr = " character" ;
2447- else if (isNullOperand (valueTok ))
2448- typeStr = " NULL " ;
2449- else if (valueTok ->isEnumerator ())
2437+ else if (isNullOperand (tok ))
2438+ typeStr = " null " ;
2439+ else if (tok ->isEnumerator ())
24502440 typeStr = " enumerator" ;
24512441 msg = " Redundant code: Found a statement that begins with " + typeStr + " constant." ;
24522442 }
24532443 else if (!tok)
24542444 msg = " Redundant code: Found a statement that begins with " + type + " constant." ;
2455- else if (tok->isCast () && tok->tokType () == Token::Type::eExtendedOp) {
2456- msg = " Redundant code: Found unused cast " ;
2457- msg += valueTok ? " of expression '" + valueTok->expressionString () + " '." : " expression." ;
2458- }
2445+ else if (tok->isCast () && tok->tokType () == Token::Type::eExtendedOp)
2446+ msg = " Redundant code: Found unused cast in expression '" + tok->expressionString () + " '." ;
24592447 else if (tok->str () == " ?" && tok->tokType () == Token::Type::eExtendedOp)
24602448 msg = " Redundant code: Found unused result of ternary operator." ;
24612449 else if (tok->str () == " ." && tok->tokType () == Token::Type::eOther)
@@ -4153,7 +4141,8 @@ static const Token *findShadowed(const Scope *scope, const Variable& var, int li
41534141 return v.nameToken ();
41544142 }
41554143 auto it = std::find_if (scope->functionList .cbegin (), scope->functionList .cend (), [&](const Function& f) {
4156- return f.type == FunctionType::eFunction && f.name () == var.name () && precedes (f.tokenDef , var.nameToken ());
4144+ return f.type == FunctionType::eFunction && f.name () == var.name ()
4145+ && (scope->isClassOrStructOrUnion () || precedes (f.tokenDef , var.nameToken ()));
41574146 });
41584147 if (it != scope->functionList .end ())
41594148 return it->tokenDef ;
0 commit comments