From 67385cfc4be238cae423c1cd805e0d88403b766e Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 13 Nov 2014 06:29:51 +0100 Subject: [PATCH] Symboldatabase: improved look up of delegate constructors --- lib/checkclass.cpp | 2 +- lib/symboldatabase.cpp | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 79fe49b2d..e2efc7f79 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -444,7 +444,7 @@ void CheckClass::initializeVarList(const Function &func, std::liststr() != func.name()) { initVar(ftok->str(), scope, usage); } else { // c++11 delegate constructor - const Function *member = scope->findFunction(ftok); + const Function *member = ftok->function(); // member function found if (member) { // recursive call diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 59d577ce2..8ac931b1b 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1125,6 +1125,27 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } + // Set C++ 11 delegate constructor function call pointers + for (std::list::iterator it = scopeList.begin(); it != scopeList.end(); ++it) { + for (std::list::const_iterator func = it->functionList.begin(); func != it->functionList.end(); ++func) { + // look for initializer list + if (func->type == Function::eConstructor && func->functionScope && + func->functionScope->functionOf && func->arg && func->arg->link()->strAt(1) == ":") { + const Token * tok = func->arg->link()->tokAt(2); + while (tok && tok != func->functionScope->classStart) { + if (Token::Match(tok, "%var% {")) { + if (tok->str() == func->tokenDef->str()) { + const_cast(tok)->function(func->functionScope->functionOf->findFunction(tok)); + break; + } + tok = tok->linkAt(1); + } + tok = tok->next(); + } + } + } + } + // Set variable pointers for (const Token* tok = _tokenizer->list.front(); tok != _tokenizer->list.back(); tok = tok->next()) { if (tok->varId()) @@ -2926,12 +2947,12 @@ const Function* Scope::findFunction(const Token *tok) const for (it = functionList.begin(); it != functionList.end(); ++it) { if (it->tokenDef->str() == tok->str()) { const Function *func = &*it; - if ((tok->strAt(1) == "(" || (func->name() == tok->str() && tok->strAt(1) == "{" && func->type == Function::eConstructor)) && tok->tokAt(2)) { - std::string end(tok->strAt(1) == "{" ? "}" : ")"); + const Token *end = tok->linkAt(1); + if (end) { // check the arguments unsigned int args = 0; const Token *arg = tok->tokAt(2); - while (arg && arg->str() != end) { + while (arg && arg != end) { /** @todo check argument type for match */ // mismatch parameter: passing parameter by address to function, argument is reference