Tokenizer: Improved removal of unused template (#9588)

This commit is contained in:
Daniel Marjamäki 2020-04-20 20:48:22 +02:00
parent 7921aa891a
commit bda73600e0
3 changed files with 9 additions and 3 deletions

View File

@ -96,7 +96,7 @@ public:
* be turned off to save CPU */
bool checkHeaders;
/** Check unused templates */
/** Check unused/uninstantiated templates */
bool checkUnusedTemplates;
/** Use Clang */

View File

@ -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);

View File

@ -994,6 +994,12 @@ private:
" std::tuple<a...> c{std::move(d)};\n"
" return std::get<0>(c);\n"
"}", s));
ASSERT_EQUALS("int g ( int ) ;",
tokenizeAndStringify("int g(int);\n"
"template <class F, class... Ts> auto h(F f, Ts... xs) {\n"
" auto e = f(g(xs)...);\n"
" return e;\n"
"}", s));
}