diff --git a/InsightsHelpers.cpp b/InsightsHelpers.cpp index e16ead62..759d3d3c 100644 --- a/InsightsHelpers.cpp +++ b/InsightsHelpers.cpp @@ -997,9 +997,21 @@ static std::string GetTemplateParameterPackArgumentName(std::string_view name, c { if(const auto* parmVarDecl = dyn_cast_or_null(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(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()); + } + } } } } diff --git a/tests/Issue506.cpp b/tests/Issue506.cpp new file mode 100644 index 00000000..d91074ca --- /dev/null +++ b/tests/Issue506.cpp @@ -0,0 +1,14 @@ +#include +#include +#include + +template +bool search(char ch, Match&&...matchers) { + return (matchers(ch) || ...); +} + +int main() +{ + std::cout << search('A', ::isalpha, ::isdigit, [](char ch) { return ch == '_'; }); +} + diff --git a/tests/Issue506.expect b/tests/Issue506.expect new file mode 100644 index 00000000..b0628951 --- /dev/null +++ b/tests/Issue506.expect @@ -0,0 +1,52 @@ +#include +#include +#include + +template +bool search(char ch, Match &&... matchers) +{ + return (matchers(ch) || ...); +} + + +/* First instantiated from: Issue506.cpp:12 */ +#ifdef INSIGHTS_USE_TEMPLATE +template<> +bool search(char ch, int (&__matchers1)(int), int (&__matchers2)(int), __lambda_12_50 && __matchers3) +{ + return static_cast(__matchers1(static_cast(ch))) || (static_cast(__matchers2(static_cast(ch))) || __matchers3.operator()(ch)); +} +#endif + + +int main() +{ + + class __lambda_12_50 + { + public: + inline /*constexpr */ bool operator()(char ch) const + { + return static_cast(ch) == static_cast('_'); + } + + 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; +} + + diff --git a/tests/Issue506_2.cpp b/tests/Issue506_2.cpp new file mode 100644 index 00000000..716c5b03 --- /dev/null +++ b/tests/Issue506_2.cpp @@ -0,0 +1,16 @@ +bool Fun(char) +{ + return false; +} + +template +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); +} diff --git a/tests/Issue506_2.expect b/tests/Issue506_2.expect new file mode 100644 index 00000000..96c21595 --- /dev/null +++ b/tests/Issue506_2.expect @@ -0,0 +1,28 @@ +bool Fun(char) +{ + return false; +} + + +template +bool search(char ch, Match &&... matchers) +{ + return (matchers(ch) || ...); +} + + +/* First instantiated from: Issue506_2.cpp:15 */ +#ifdef INSIGHTS_USE_TEMPLATE +template<> +bool search(char ch, bool (&__matchers1)(char)) +{ + return __matchers1(ch); +} +#endif + + +int main() +{ + return static_cast(search('A', Fun)); +} + diff --git a/tests/NonTypeTemplateParameterPackTest.expect b/tests/NonTypeTemplateParameterPackTest.expect index 43b0aea9..418cc8ae 100644 --- a/tests/NonTypeTemplateParameterPackTest.expect +++ b/tests/NonTypeTemplateParameterPackTest.expect @@ -79,10 +79,10 @@ class Test /* First instantiated from: NonTypeTemplateParameterPackTest.cpp:18 */ #ifdef INSIGHTS_USE_TEMPLATE template<> - inline int summ(int & i, int & rest) + inline int summ(int & i, int & __rest1) { if constexpr(true) { - return i + this->summ(rest); + return i + this->summ(__rest1); } }