Fix #11915 Assert failure in getTemplateNamePosition() (#5403)

This commit is contained in:
chrchr-github 2023-09-05 00:35:33 +02:00 committed by GitHub
parent ce780177b2
commit 03026c7304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -454,8 +454,9 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
if (level == 1)
return numberOfParameters;
level -= 2;
} else if (tok->str() == "," && level == 0) {
++numberOfParameters;
} else if (tok->str() == ",") {
if (level == 0)
++numberOfParameters;
tok = tok->next();
continue;
}

View File

@ -5318,6 +5318,7 @@ private:
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() {}"));
ASSERT_EQUALS(1U, templateParameters("S<4 < sizeof(uintptr_t)> x;"));
ASSERT_EQUALS(2U, templateParameters("template <typename... Ts, typename = std::enable_if_t<std::is_same<Ts..., int>::value>> void g() {}")); // #11915
}
// Helper function to unit test TemplateSimplifier::getTemplateNamePosition