diff --git a/lib/checkother.cpp b/lib/checkother.cpp index dbd4e5686..d9ac6dfc8 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2519,24 +2519,6 @@ void CheckOther::checkMathFunctions() } } - -bool CheckOther::isIdentifierObjectType(const Token * const tok) -{ - const std::string identifier = tok->tokAt(1)->str(); - - const std::map::const_iterator found = isClassResults.find(identifier); - if (found != isClassResults.end()) - { - return found->second; - } - - const std::string classDefnOrDecl = std::string("class|struct ") + identifier + " [{:;]"; - const bool result = Token::findmatch(_tokenizer->tokens(), classDefnOrDecl.c_str()) != NULL; - isClassResults.insert(std::make_pair(identifier, result)); - return result; -} - - void CheckOther::checkMisusedScopedObject() { // Skip this check for .c files @@ -2551,6 +2533,14 @@ void CheckOther::checkMisusedScopedObject() std::list::iterator i; + // list of classes / structs + std::set identifiers; + for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) + { + if (Token::Match(tok, "class|struct %var% [:{]")) + identifiers.insert(tok->next()->str()); + } + for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i) { SymbolDatabase::SpaceInfo *info = *i; @@ -2576,7 +2566,7 @@ void CheckOther::checkMisusedScopedObject() if (Token::Match(tok, "[;{}] %var% (") && Token::Match(tok->tokAt(2)->link(), ") ;") - && isIdentifierObjectType(tok) + && identifiers.find(tok->next()->str()) != identifiers.end() ) { tok = tok->next(); diff --git a/lib/checkother.h b/lib/checkother.h index a26dc2ae9..9e49d8dce 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -293,16 +293,6 @@ private: return varname; } - - /** - * @brief query type of identifier - * @param tok Token of the identifier - * @return true if the identifier is of type 'class' or 'struct', - * false otherwise. - */ - bool isIdentifierObjectType(const Token* const tok); - - std::map isClassResults; }; /// @} //---------------------------------------------------------------------------