diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index be9bbc91f..391908b26 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -551,4 +551,22 @@ bool TemplateSimplifier::simplifyTemplatesInstantiateMatch(const Token *instance return true; } +int TemplateSimplifier::simplifyTemplatesGetTemplateNamePosition(const Token *tok) +{ + // get the position of the template name + int namepos = 0; + if (Token::Match(tok, "> class|struct %type% {|:")) + namepos = 2; + else if (Token::Match(tok, "> %type% *|&| %type% (")) + namepos = 2; + else if (Token::Match(tok, "> %type% %type% *|&| %type% (")) + namepos = 3; + else { + // Name not found + return -1; + } + if ((tok->strAt(namepos) == "*" || tok->strAt(namepos) == "&")) + ++namepos; + return namepos; +} diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 8871ca980..ebc7729f3 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -101,6 +101,13 @@ public: */ static bool simplifyTemplatesInstantiateMatch(const Token *instance, const std::string &name, size_t numberOfArguments, const char patternAfter[]); + /** + * Match template declaration/instantiation + * @param tok The ">" token e.g. before "class" + * @return -1 to bail out or positive integer to identity the position + * of the template name. + */ + static int simplifyTemplatesGetTemplateNamePosition(const Token *tok); }; /// @} diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2de987f15..8b240d15c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2677,44 +2677,6 @@ void Tokenizer::simplifyLabelsCaseDefault() } } -int Tokenizer::simplifyTemplatesGetTemplateNamePosition(const Token *tok) -{ - // get the position of the template name - int namepos = 0; - if (Token::Match(tok, "> class|struct %type% {|:")) - namepos = 2; - else if (Token::Match(tok, "> %type% *|&| %type% (")) - namepos = 2; - else if (Token::Match(tok, "> %type% %type% *|&| %type% (")) - namepos = 3; - else { - // debug message that we bail out.. - if (_settings->debugwarnings) { - std::list locationList; - ErrorLogger::ErrorMessage::FileLocation loc; - loc.line = tok->linenr(); - loc.setfile(file(tok)); - locationList.push_back(loc); - - const ErrorLogger::ErrorMessage errmsg(locationList, - Severity::debug, - "simplifyTemplates: bailing out", - "debug", - false); - - if (_errorLogger) - _errorLogger->reportErr(errmsg); - else - Check::reportError(errmsg); - } - return -1; - } - if ((tok->strAt(namepos) == "*" || tok->strAt(namepos) == "&")) - ++namepos; - - return namepos; -} - void Tokenizer::simplifyTemplatesExpandTemplate(const Token *tok, const std::string &name, std::vector &typeParametersInDeclaration, @@ -2845,9 +2807,29 @@ void Tokenizer::simplifyTemplateInstantions(const Token *tok, return; // get the position of the template name - int namepos = simplifyTemplatesGetTemplateNamePosition(tok); - if (namepos == -1) + int namepos = TemplateSimplifier::simplifyTemplatesGetTemplateNamePosition(tok); + if (namepos == -1) { + // debug message that we bail out.. + if (_settings->debugwarnings) { + std::list locationList; + ErrorLogger::ErrorMessage::FileLocation loc; + loc.line = tok->linenr(); + loc.setfile(file(tok)); + locationList.push_back(loc); + + const ErrorLogger::ErrorMessage errmsg(locationList, + Severity::debug, + "simplifyTemplates: bailing out", + "debug", + false); + + if (_errorLogger) + _errorLogger->reportErr(errmsg); + else + Check::reportError(errmsg); + } return; + } // name of template function/class.. const std::string name(tok->strAt(namepos)); diff --git a/lib/tokenize.h b/lib/tokenize.h index e2a673ac6..06300c85b 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -509,14 +509,6 @@ public: std::vector &typesUsedInTemplateInstantion, std::list &templateInstantiations); - /** - * Match template declaration/instantiation - * @param tok The ">" token e.g. before "class" - * @return -1 to bail out or positive integer to identity the position - * of the template name. - */ - int simplifyTemplatesGetTemplateNamePosition(const Token *tok); - /** * Simplify e.g. 'atol("0")' into '0' */