================ @@ -1442,8 +1442,49 @@ Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { if (D->isUnsupportedFriend()) { InstTy = Ty; } else { - InstTy = SemaRef.SubstType(Ty, TemplateArgs, - D->getLocation(), DeclarationName()); + if (D->isVariadic()) { + SmallVector<UnexpandedParameterPack, 2> Unexpanded; + SemaRef.collectUnexpandedParameterPacks(Ty->getTypeLoc(), Unexpanded); + assert(!Unexpanded.empty() && "Pack expansion without packs"); + + bool ShouldExpand = true; + bool RetainExpansion = false; + std::optional<unsigned> NumExpansions; + if (SemaRef.CheckParameterPacksForExpansion( + D->getEllipsisLoc(), D->getSourceRange(), Unexpanded, + TemplateArgs, ShouldExpand, RetainExpansion, NumExpansions)) + return nullptr; + + assert(!RetainExpansion && + "should never retain an expansion for a FriendPackDecl"); + + if (ShouldExpand) { + SmallVector<FriendDecl *> Decls; + for (unsigned I = 0; I != *NumExpansions; I++) { + Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); + TypeSourceInfo *TSI = SemaRef.SubstType( + Ty, TemplateArgs, D->getEllipsisLoc(), DeclarationName()); + if (!TSI) + return nullptr; + + auto FD = + FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), + TSI, D->getFriendLoc()); + + FD->setAccess(AS_public); + Owner->addDecl(FD); + Decls.push_back(FD); + } + + auto FPD = FriendPackDecl::Create(SemaRef.Context, Owner, D, Decls); ---------------- zyn0217 wrote:
```suggestion auto *FPD = FriendPackDecl::Create(SemaRef.Context, Owner, D, Decls); ``` https://github.com/llvm/llvm-project/pull/101448 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits