Skip to content

Commit

Permalink
Merge pull request #575 from andreasfertig/fixIssue506
Browse files Browse the repository at this point in the history
Fixed #506: Show suffixes for `ParmVarDecl` if it is a parameter pack.
  • Loading branch information
andreasfertig authored Sep 26, 2023
2 parents 5dd07c0 + ab64f72 commit 726de68
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 5 deletions.
18 changes: 15 additions & 3 deletions InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,21 @@ static std::string GetTemplateParameterPackArgumentName(std::string_view name, c
{
if(const auto* parmVarDecl = dyn_cast_or_null<ParmVarDecl>(decl)) {
if(const auto& originalType = parmVarDecl->getOriginalType(); not originalType.isNull()) {
if(const auto* substTemplateTypeParmType = GetSubstTemplateTypeParmType(originalType.getTypePtrOrNull())) {
if(substTemplateTypeParmType->getReplacedParameter()->isParameterPack()) {
return StrCat(BuildInternalVarName(name), parmVarDecl->getFunctionScopeIndex());
if(const auto* substTemplateTypeParmType = GetSubstTemplateTypeParmType(originalType.getTypePtrOrNull());
substTemplateTypeParmType and substTemplateTypeParmType->getReplacedParameter()->isParameterPack()) {
return StrCat(BuildInternalVarName(name), parmVarDecl->getFunctionScopeIndex());

} else if(const auto* fd = parmVarDecl->getParentFunctionOrMethod()) {
// Get the primary template, if possible and check whether its parameters contain a parameter pack
if(const auto* primTmpl = dyn_cast_or_null<FunctionDecl>(fd)->getPrimaryTemplate();
primTmpl and primTmpl->getTemplateParameters()->hasParameterPack()) {
// if so, then search for the matching parameter name.
for(const auto* pa : primTmpl->getTemplatedDecl()->parameters()) {
// if one is found we suffix it with its function scope index
if(pa->isParameterPack() and (parmVarDecl->getNameAsString() == pa->getNameAsString())) {
return StrCat(BuildInternalVarName(name), parmVarDecl->getFunctionScopeIndex());
}
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Issue506.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <cstdio>
#include <iostream>
#include <cctype>

template<class...Match>
bool search(char ch, Match&&...matchers) {
return (matchers(ch) || ...);
}

int main()
{
std::cout << search('A', ::isalpha, ::isdigit, [](char ch) { return ch == '_'; });
}

52 changes: 52 additions & 0 deletions tests/Issue506.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <cstdio>
#include <iostream>
#include <cctype>

template<class ... Match>
bool search(char ch, Match &&... matchers)
{
return (matchers(ch) || ...);
}


/* First instantiated from: Issue506.cpp:12 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
bool search<int (&)(int), int (&)(int), __lambda_12_50>(char ch, int (&__matchers1)(int), int (&__matchers2)(int), __lambda_12_50 && __matchers3)
{
return static_cast<bool>(__matchers1(static_cast<int>(ch))) || (static_cast<bool>(__matchers2(static_cast<int>(ch))) || __matchers3.operator()(ch));
}
#endif


int main()
{

class __lambda_12_50
{
public:
inline /*constexpr */ bool operator()(char ch) const
{
return static_cast<int>(ch) == static_cast<int>('_');
}

using retType_12_50 = bool (*)(char);
inline constexpr operator retType_12_50 () const noexcept
{
return __invoke;
};

private:
static inline /*constexpr */ bool __invoke(char ch)
{
return __lambda_12_50{}.operator()(ch);
}


};

std::cout.operator<<(search('A', ::isalpha, ::isdigit, __lambda_12_50{}));
return 0;
}


16 changes: 16 additions & 0 deletions tests/Issue506_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bool Fun(char)
{
return false;
}

template<class...Match>
bool search(char ch, Match&&...matchers) {
return (matchers(ch) || ...);
}

int main()
{
// std::cout << search('A', ::isalpha, ::isdigit, [](char ch) { return ch == '_'; });
// return search('A', Fun, Fun, [](char ch) { return ch == '_'; });
return search('A', Fun);
}
28 changes: 28 additions & 0 deletions tests/Issue506_2.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
bool Fun(char)
{
return false;
}


template<class ... Match>
bool search(char ch, Match &&... matchers)
{
return (matchers(ch) || ...);
}


/* First instantiated from: Issue506_2.cpp:15 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
bool search<bool (&)(char)>(char ch, bool (&__matchers1)(char))
{
return __matchers1(ch);
}
#endif


int main()
{
return static_cast<int>(search('A', Fun));
}

4 changes: 2 additions & 2 deletions tests/NonTypeTemplateParameterPackTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class Test
/* First instantiated from: NonTypeTemplateParameterPackTest.cpp:18 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
inline int summ<int &, int &>(int & i, int & rest)
inline int summ<int &, int &>(int & i, int & __rest1)
{
if constexpr(true) {
return i + this->summ<int &>(rest);
return i + this->summ<int &>(__rest1);
}

}
Expand Down

0 comments on commit 726de68

Please sign in to comment.