diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 0f18b17e0..89d6a4b3f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -413,26 +413,26 @@ bool CheckClass::canNotMove(const Scope *scope) return constructor && !(publicAssign || publicCopy || publicMove); } -void CheckClass::assignVar(const std::string &varname, const Scope *scope, std::vector &usage) +void CheckClass::assignVar(unsigned int varid, const Scope *scope, std::vector &usage) { std::list::const_iterator var; unsigned int count = 0; for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) { - if (var->name() == varname) { + if (var->declarationId() == varid) { usage[count].assign = true; return; } } } -void CheckClass::initVar(const std::string &varname, const Scope *scope, std::vector &usage) +void CheckClass::initVar(unsigned int varid, const Scope *scope, std::vector &usage) { std::list::const_iterator var; unsigned int count = 0; for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var, ++count) { - if (var->name() == varname) { + if (var->declarationId() == varid) { usage[count].init = true; return; } @@ -491,7 +491,7 @@ void CheckClass::initializeVarList(const Function &func, std::listlinkAt(1), "}|) ,|{")) { if (ftok->str() != func.name()) { - initVar(ftok->str(), scope, usage); + initVar(ftok->varId(), scope, usage); } else { // c++11 delegate constructor const Function *member = ftok->function(); // member function found @@ -519,7 +519,7 @@ void CheckClass::initializeVarList(const Function &func, std::list> %name%")) { - assignVar(ftok->strAt(1), scope, usage); + assignVar(ftok->next()->varId(), scope, usage); } // Before a new statement there is "[{};()=[]" @@ -567,7 +567,7 @@ void CheckClass::initializeVarList(const Function &func, std::listvarlist.begin(); var != scope->varlist.end(); ++var) { if (var->declarationId() == ftok->next()->varId()) { /** @todo false negative: we assume function changes variable state */ - assignVar(ftok->next()->str(), scope, usage); + assignVar(ftok->next()->varId(), scope, usage); break; } } @@ -613,7 +613,7 @@ void CheckClass::initializeVarList(const Function &func, std::liststr() == "::") ftok = ftok->next(); - assignVar(ftok->strAt(2), scope, usage); + assignVar(ftok->tokAt(2)->varId(), scope, usage); ftok = ftok->linkAt(1); continue; } @@ -688,7 +688,7 @@ void CheckClass::initializeVarList(const Function &func, std::listnext(); if (tok2->str() == "&") tok2 = tok2->next(); - assignVar(tok2->str(), scope, usage); + assignVar(tok2->varId(), scope, usage); } } } @@ -718,7 +718,7 @@ void CheckClass::initializeVarList(const Function &func, std::listtokAt(2); tok && tok != ftok->next()->link(); tok = tok->next()) { if (tok->isName()) { - assignVar(tok->str(), scope, usage); + assignVar(tok->varId(), scope, usage); } } } @@ -727,7 +727,7 @@ void CheckClass::initializeVarList(const Function &func, std::listvariable() && (bailout || tok2->variable()->isArray()) && tok2->strAt(1) != "[") - assignVar(tok2->str(), scope, usage); + assignVar(tok2->varId(), scope, usage); } // Assignment of array item of member variable? @@ -750,19 +750,19 @@ void CheckClass::initializeVarList(const Function &func, std::liststrAt(1) == "=") - assignVar(ftok->str(), scope, usage); + assignVar(ftok->varId(), scope, usage); } // Assignment of array item of member variable? else if (Token::Match(ftok, "* %name% =")) { - assignVar(ftok->next()->str(), scope, usage); + assignVar(ftok->next()->varId(), scope, usage); } else if (Token::Match(ftok, "* this . %name% =")) { - assignVar(ftok->strAt(3), scope, usage); + assignVar(ftok->tokAt(3)->varId(), scope, usage); } // The functions 'clear' and 'Clear' are supposed to initialize variable. if (Token::Match(ftok, "%name% . clear|Clear (")) { - assignVar(ftok->str(), scope, usage); + assignVar(ftok->varId(), scope, usage); } } } diff --git a/lib/checkclass.h b/lib/checkclass.h index 389047e7e..ffc533aa8 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -258,7 +258,7 @@ private: * @param scope pointer to variable Scope * @param usage reference to usage vector */ - static void assignVar(const std::string &varname, const Scope *scope, std::vector &usage); + static void assignVar(unsigned int varid, const Scope *scope, std::vector &usage); /** * @brief initialize a variable in the varlist @@ -266,7 +266,7 @@ private: * @param scope pointer to variable Scope * @param usage reference to usage vector */ - static void initVar(const std::string &varname, const Scope *scope, std::vector &usage); + static void initVar(unsigned int varid, const Scope *scope, std::vector &usage); /** * @brief set all variables in list assigned