Skip to content

Commit

Permalink
Fix #11915 Assert failure in getTemplateNamePosition() (#5403)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 4, 2023
1 parent ce78017 commit 03026c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5318,6 +5318,7 @@ class TestSimplifyTemplate : public TestFixture {
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
Expand Down

0 comments on commit 03026c7

Please sign in to comment.