MitalAshok updated this revision to Diff 543183. MitalAshok edited the summary of this revision. MitalAshok added a comment.
Added entry to changelog and the test from the bug report Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154716/new/ https://reviews.llvm.org/D154716 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaTemplateInstantiate.cpp clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/lambda-pack-expansion.cpp Index: clang/test/SemaCXX/lambda-pack-expansion.cpp =================================================================== --- clang/test/SemaCXX/lambda-pack-expansion.cpp +++ clang/test/SemaCXX/lambda-pack-expansion.cpp @@ -21,3 +21,30 @@ take_by_ref(x); } } + +namespace GH63677 { + +template<typename> +void f() { + []<typename... Ts>() -> void { + [...us = Ts{}]{ + (Ts(us), ...); + }; + }.template operator()<int, int>(); +} + +template void f<int>(); + +template <class> +inline constexpr auto fun = + []<class... Ts>(Ts... ts) { + return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable { + return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...); + }; + }; + +void f() { + [[maybe_unused]] auto s = fun<int>(1, 2, 3, 4); +} + +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -13340,14 +13340,14 @@ OldVD->getInit()->getSourceRange(), Unexpanded, Expand, RetainExpansion, NumExpansions)) return ExprError(); + assert(!RetainExpansion && "Should not need to retain expansion after a " + "capture since it cannot be extended"); if (Expand) { for (unsigned I = 0; I != *NumExpansions; ++I) { Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); SubstInitCapture(SourceLocation(), std::nullopt); } - } - if (!Expand || RetainExpansion) { - ForgetPartiallySubstitutedPackRAII Forget(getDerived()); + } else { SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1270,7 +1270,8 @@ } void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { - if (Old->isParameterPack()) { + if (Old->isParameterPack() && + (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) { SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); for (auto *New : NewDecls) SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -782,6 +782,8 @@ (`#63903 <https://github.com/llvm/llvm-project/issues/63903>`_) - Fix constraint checking of non-generic lambdas. (`#63181 <https://github.com/llvm/llvm-project/issues/63181>`_) +- Fix init-capture packs having a size of one before being instantiated + (`#63677 <https://github.com/llvm/llvm-project/issues/63677>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang/test/SemaCXX/lambda-pack-expansion.cpp =================================================================== --- clang/test/SemaCXX/lambda-pack-expansion.cpp +++ clang/test/SemaCXX/lambda-pack-expansion.cpp @@ -21,3 +21,30 @@ take_by_ref(x); } } + +namespace GH63677 { + +template<typename> +void f() { + []<typename... Ts>() -> void { + [...us = Ts{}]{ + (Ts(us), ...); + }; + }.template operator()<int, int>(); +} + +template void f<int>(); + +template <class> +inline constexpr auto fun = + []<class... Ts>(Ts... ts) { + return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable { + return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...); + }; + }; + +void f() { + [[maybe_unused]] auto s = fun<int>(1, 2, 3, 4); +} + +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -13340,14 +13340,14 @@ OldVD->getInit()->getSourceRange(), Unexpanded, Expand, RetainExpansion, NumExpansions)) return ExprError(); + assert(!RetainExpansion && "Should not need to retain expansion after a " + "capture since it cannot be extended"); if (Expand) { for (unsigned I = 0; I != *NumExpansions; ++I) { Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); SubstInitCapture(SourceLocation(), std::nullopt); } - } - if (!Expand || RetainExpansion) { - ForgetPartiallySubstitutedPackRAII Forget(getDerived()); + } else { SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); } Index: clang/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiate.cpp +++ clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1270,7 +1270,8 @@ } void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { - if (Old->isParameterPack()) { + if (Old->isParameterPack() && + (NewDecls.size() != 1 || !NewDecls.front()->isParameterPack())) { SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); for (auto *New : NewDecls) SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -782,6 +782,8 @@ (`#63903 <https://github.com/llvm/llvm-project/issues/63903>`_) - Fix constraint checking of non-generic lambdas. (`#63181 <https://github.com/llvm/llvm-project/issues/63181>`_) +- Fix init-capture packs having a size of one before being instantiated + (`#63677 <https://github.com/llvm/llvm-project/issues/63677>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits