Skip to content

[clang] Do not substitute parameter pack while retaining the pack expansion #108197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ class TreeTransform {
class ForgetPartiallySubstitutedPackRAII {
Derived &Self;
TemplateArgument Old;
// Set the pack expansion index to -1 to avoid pack substitution and
// indicate that parameter packs should be instantiated as themselves.
Sema::ArgumentPackSubstitutionIndexRAII ResetPackSubstIndex;

public:
ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
ForgetPartiallySubstitutedPackRAII(Derived &Self)
: Self(Self), ResetPackSubstIndex(Self.getSema(), -1) {
Old = Self.ForgetPartiallySubstitutedPack();
}

Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaTemplate/pack-deduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,17 @@ void Run() {
Outer<void>::Inner<0>().Test(1,1);
}
}

namespace GH107560 {
int bar(...);

template <int> struct Int {};

template <class ...T>
constexpr auto foo(T... x) -> decltype(bar(T(x)...)) { return 10; }

template <class ...T>
constexpr auto baz(Int<foo<T>(T())>... x) -> int { return 1; }

static_assert(baz<Int<1>, Int<2>, Int<3>>(Int<10>(), Int<10>(), Int<10>()) == 1, "");
}
Loading