From bda73600e08cedd451192b6a152da66c8783f3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Apr 2020 20:48:22 +0200 Subject: [PATCH] Tokenizer: Improved removal of unused template (#9588) --- lib/settings.h | 2 +- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/settings.h b/lib/settings.h index ed357958f..21e2f37db 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -96,7 +96,7 @@ public: * be turned off to save CPU */ bool checkHeaders; - /** Check unused templates */ + /** Check unused/uninstantiated templates */ bool checkUnusedTemplates; /** Use Clang */ diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ca5761251..a378b78b8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5072,8 +5072,8 @@ void Tokenizer::simplifyHeaders() if (removeUnusedTemplates || (isIncluded && removeUnusedIncludedTemplates)) { if (Token::Match(tok->next(), "template < %name%")) { const Token *tok2 = tok->tokAt(3); - while (Token::Match(tok2, "%name% %name% [,=>]") || Token::Match(tok2, "typename ... %name% [,>]")) { - if (Token::simpleMatch(tok2, "typename ...")) + while (Token::Match(tok2, "%name% %name% [,=>]") || Token::Match(tok2, "typename|class ... %name% [,>]")) { + if (Token::Match(tok2, "typename|class ...")) tok2 = tok2->tokAt(3); else tok2 = tok2->tokAt(2); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1d0f1828c..544557681 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -994,6 +994,12 @@ private: " std::tuple c{std::move(d)};\n" " return std::get<0>(c);\n" "}", s)); + ASSERT_EQUALS("int g ( int ) ;", + tokenizeAndStringify("int g(int);\n" + "template auto h(F f, Ts... xs) {\n" + " auto e = f(g(xs)...);\n" + " return e;\n" + "}", s)); }