diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1888dfbe8..9f2d27d6f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1257,6 +1257,12 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s // Handle templates.. simplifyTemplates(); + // Simplify templates.. sometimes the "simplifyTemplates" fail and + // then unsimplified function calls etc remain. These have the + // "wrong" syntax. So this function will just fix so that the + // syntax is corrected. + simplifyTemplates2(); + // Simplify the operator "?:" simplifyConditionOperator(); @@ -1910,6 +1916,25 @@ void Tokenizer::simplifyTemplates() } //--------------------------------------------------------------------------- +void Tokenizer::simplifyTemplates2() +{ + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (tok->str() == "(") + tok = tok->link(); + + else if (Token::Match(tok, "; %type% < %type% > (")) + { + tok = tok->next(); + tok->str(tok->str() + "<" + tok->strAt(2) + ">"); + tok->deleteNext(); + tok->deleteNext(); + tok->deleteNext(); + } + } +} +//--------------------------------------------------------------------------- + std::string Tokenizer::getNameForFunctionParams(const Token *start) { if (start->next() == start->link()) diff --git a/lib/tokenize.h b/lib/tokenize.h index 5de25436b..743808341 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -324,6 +324,13 @@ private: */ void simplifyTemplates(); + /** + * Used after simplifyTemplates to perform a little cleanup. + * Sometimes the simplifyTemplates isn't fully successful and then + * there are function calls etc with "wrong" syntax. + */ + void simplifyTemplates2(); + /** * Simplify e.g. 'atol("0")' into '0' */ diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index eed9dcf69..e479d702c 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(template17); TEST_CASE(template18); TEST_CASE(template19); + TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); TEST_CASE(template_typename); @@ -1539,6 +1540,12 @@ private: ASSERT_EQUALS(expected, sizeof_(code)); } + void template_unhandled() + { + // An unhandled template usage should be simplified.. + ASSERT_EQUALS("; x ( ) ;", sizeof_(";x();")); + } + void template_default_parameter() { {