@@ -5861,7 +5861,10 @@ bool Scope::hasInlineOrLambdaFunction(const Token** tokStart, bool onlyInline) c
58615861 });
58625862}
58635863
5864- void Scope::findFunctionInBase (const Token* tok, size_t args, std::vector<const Function *> & matches) const
5864+ void Scope::findFunctionInBase (const std::string& name,
5865+ const Token* tok,
5866+ size_t args,
5867+ std::vector<const Function*>& matches) const
58655868{
58665869 if (isClassOrStruct () && definedType && !definedType->derivedFrom .empty ()) {
58675870 const std::vector<Type::BaseInfo> &derivedFrom = definedType->derivedFrom ;
@@ -5871,7 +5874,7 @@ void Scope::findFunctionInBase(const Token* tok, size_t args, std::vector<const
58715874 if (base->classScope == this ) // Ticket #5120, #5125: Recursive class; tok should have been found already
58725875 continue ;
58735876
5874- auto range = base->classScope ->functionMap .equal_range (tok-> str () );
5877+ auto range = base->classScope ->functionMap .equal_range (name );
58755878 for (auto it = range.first ; it != range.second ; ++it) {
58765879 const Function *func = it->second ;
58775880 if (func->isDestructor () && !Token::simpleMatch (tok->tokAt (-1 ), " ~" ))
@@ -5882,7 +5885,7 @@ void Scope::findFunctionInBase(const Token* tok, size_t args, std::vector<const
58825885 }
58835886 }
58845887
5885- base->classScope ->findFunctionInBase (tok, args, matches);
5888+ base->classScope ->findFunctionInBase (name, tok, args, matches);
58865889 }
58875890 }
58885891 }
@@ -6021,8 +6024,10 @@ static bool hasMatchingConstructor(const Scope* classScope, const ValueType* arg
60216024 });
60226025}
60236026
6024- const Function* Scope::findFunction (const Token * tok, bool requireConst, Reference ref) const
6027+ const Function* Scope::findFunction (const Token* tok, bool requireConst, Reference ref, const std::string& funcName ) const
60256028{
6029+ const std::string& name = funcName.empty () ? tok->str () : funcName;
6030+
60266031 const bool isCall = Token::Match (tok->next (), " (|{" );
60276032
60286033 const std::vector<const Token *> arguments = getArguments (tok);
@@ -6032,8 +6037,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
60326037 // find all the possible functions that could match
60336038 const std::size_t args = arguments.size ();
60346039
6035- auto addMatchingFunctions = [&](const Scope * scope) {
6036- auto range = scope->functionMap .equal_range (tok-> str () );
6040+ auto addMatchingFunctions = [&](const Scope* scope) {
6041+ auto range = scope->functionMap .equal_range (name );
60376042 for (auto it = range.first ; it != range.second ; ++it) {
60386043 const Function *func = it->second ;
60396044 if (ref == Reference::LValue && func->hasRvalRefQualifier ())
@@ -6068,7 +6073,7 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
60686073 const std::size_t numberOfMatchesNonBase = matches.size ();
60696074
60706075 // check in base classes
6071- findFunctionInBase (tok, args, matches);
6076+ findFunctionInBase (name, tok, args, matches);
60726077
60736078 // Non-call => Do not match parameters
60746079 if (!isCall) {
@@ -6298,8 +6303,8 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
62986303 matches.erase (itPure);
62996304
63006305 // Only one candidate left
6301- if (matches.size () == 1 && std::none_of (functionList.begin (), functionList.end (), [tok ](const Function& f) {
6302- return startsWith (f.name (), tok-> str () + " <" );
6306+ if (matches.size () == 1 && std::none_of (functionList.begin (), functionList.end (), [&name ](const Function& f) {
6307+ return startsWith (f.name (), name + " <" );
63036308 }))
63046309 return matches[0 ];
63056310
@@ -7792,6 +7797,13 @@ static const Function* getFunction(const Token* tok) {
77927797 lambda = lvar->nameToken ()->tokAt (2 )->function ();
77937798 if (lambda && lambda->retDef )
77947799 return lambda;
7800+ // calling an object of a class that overloads operator()
7801+ if (tok != lvar->nameToken () && !lvar->isPointer () && !lvar->isArray () && lvar->typeScope ()) {
7802+ const Function* callOp =
7803+ lvar->typeScope ()->findFunction (tok, lvar->isConst (), Reference::LValue, " operator()" );
7804+ if (callOp && callOp->retDef )
7805+ return callOp;
7806+ }
77957807 }
77967808 return nullptr ;
77977809}
0 commit comments