diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index 411c22205..c7f144c14 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -296,7 +296,7 @@ void CheckSizeof::sizeofCalculation() if (tok->isExpandedMacro() && tok->previous()) { const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok; if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") || - Token::simpleMatch(cast_end->previous(), "static_cast")) { + Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) { continue; } } @@ -337,7 +337,7 @@ void CheckSizeof::sizeofFunction() if (tok->isExpandedMacro() && tok->previous()) { const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok; if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") || - Token::simpleMatch(cast_end->previous(), "static_cast")) { + Token::simpleMatch(cast_end->tokAt(-4), "static_cast < void >")) { continue; } } diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 02ffbb134..87dc5272e 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -245,58 +245,6 @@ TemplateSimplifier::~TemplateSimplifier() { } -void TemplateSimplifier::cleanupAfterSimplify() -{ - bool goback = false; - for (Token *tok = mTokenList.front(); tok; tok = tok->next()) { - if (goback) { - tok = tok->previous(); - goback = false; - } - if (tok->str() == "(") - tok = tok->link(); - - else if (Token::Match(tok, "template < > %name%")) { - const Token *end = tok; - while (end) { - if (end->str() == ";") - break; - if (end->str() == "{") { - end = end->link()->next(); - break; - } - if (!Token::Match(end, "%name%|::|<|>|,")) { - end = nullptr; - break; - } - end = end->next(); - } - if (end) { - Token::eraseTokens(tok,end); - tok->deleteThis(); - } - } - - else if (Token::Match(tok, "%type% <") && - (!tok->previous() || tok->previous()->str() == ";")) { - const Token *tok2 = tok->tokAt(2); - std::string type; - while (Token::Match(tok2, "%type%|%num% ,")) { - type += tok2->str() + ","; - tok2 = tok2->tokAt(2); - } - if (Token::Match(tok2, "%type%|%num% > (")) { - type += tok2->str(); - tok->str(tok->str() + "<" + type + ">"); - Token::eraseTokens(tok, tok2->tokAt(2)); - if (tok == mTokenList.front()) - goback = true; - } - } - } -} - - void TemplateSimplifier::checkComplicatedSyntaxErrorsInTemplates() { // check for more complicated syntax errors when using templates.. diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index 9b8c9f63c..65ab648aa 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -47,13 +47,6 @@ public: explicit TemplateSimplifier(Tokenizer *tokenizer); ~TemplateSimplifier(); - /** - * 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 cleanupAfterSimplify(); - /** */ void checkComplicatedSyntaxErrorsInTemplates(); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e0ae1dc36..c54c6e8b1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4747,11 +4747,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) if (Settings::terminated()) return false; - // 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. validate(); // #6847 - invalid code - mTemplateSimplifier->cleanupAfterSimplify(); } // Simplify pointer to standard types (C only) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 722eacd6b..6a85f3a93 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -997,8 +997,8 @@ private: } void template_unhandled() { - // An unhandled template usage should be simplified.. - ASSERT_EQUALS("x ( ) ;", tok("x();")); + // An unhandled template usage should not be simplified.. + ASSERT_EQUALS("x < int > ( ) ;", tok("x();")); } void template38() { // #4832 - Crash on C++11 right angle brackets diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 72eba3804..346b59a1d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4315,13 +4315,13 @@ private: void unsigned3() { { const char code[] = "; foo();"; - const char expected[] = "; foo ( ) ;"; + const char expected[] = "; foo < unsigned int > ( ) ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } { const char code[] = "; foo();"; - const char expected[] = "; foo ( ) ;"; + const char expected[] = "; foo < unsigned int > ( ) ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } }