#11351 follow-up: Handle more variadic template arguments (#4554)

* Update templatesimplifier.cpp

* Add tests
This commit is contained in:
chrchr-github 2022-10-22 00:28:33 +02:00 committed by GitHub
parent ae16aab997
commit 13d81cdd58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -438,7 +438,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
// Skip variadic types (Ticket #5774, #6059, #6172)
if (Token::simpleMatch(tok, "...")) {
if ((tok->previous()->isName() && !Token::Match(tok->tokAt(-2), "<|,|::")) ||
(!tok->previous()->isName() && !Token::Match(tok->previous(), ">|&")))
(!tok->previous()->isName() && !Token::Match(tok->previous(), ">|&|&&|*")))
return 0; // syntax error
tok = tok->next();
if (!tok)

View File

@ -5298,6 +5298,8 @@ private:
ASSERT_EQUALS(2U, templateParameters("template<typename S, enable_if_t<(is_compile_string<S>::value), int>> void i(S s);"));
ASSERT_EQUALS(2U, templateParameters("template<typename c, b<(c::d), int>> void e();"));
ASSERT_EQUALS(3U, templateParameters("template <class T, class... Args, class Tup = std::tuple<Args&...>> constexpr void f() {}")); // #11351
ASSERT_EQUALS(3U, templateParameters("template <class T, class... Args, class Tup = std::tuple<Args&&...>> void f() {}"));
ASSERT_EQUALS(3U, templateParameters("template <class T, class... Args, class Tup = std::tuple<Args*...>> void f() {}"));
}
// Helper function to unit test TemplateSimplifier::getTemplateNamePosition