aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorJason Rice <ricejasonf@gmail.com>2025-01-29 12:43:52 -0800
committerGitHub <noreply@github.com>2025-01-29 21:43:52 +0100
commitabc8812df02599fc413d9ed77b992f8236ed2af9 (patch)
treed5fc8a01c03d5700aed337d8b8516fa3d461a326 /clang/lib/Sema/SemaTemplateInstantiate.cpp
parent608012ace43b42d97884204016c6a8f4883b4359 (diff)
downloadllvm-abc8812df02599fc413d9ed77b992f8236ed2af9.zip
llvm-abc8812df02599fc413d9ed77b992f8236ed2af9.tar.gz
llvm-abc8812df02599fc413d9ed77b992f8236ed2af9.tar.bz2
[Clang][P1061] Add stuctured binding packs (#121417)
This is an implementation of P1061 Structure Bindings Introduce a Pack without the ability to use packs outside of templates. There is a couple of ways the AST could have been sliced so let me know what you think. The only part of this change that I am unsure of is the serialization/deserialization stuff. I followed the implementation of other Exprs, but I do not really know how it is tested. Thank you for your time considering this. --------- Co-authored-by: Yanzuo Liu <zwuis@outlook.com>
Diffstat (limited to 'clang/lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index b4fa23d..12e98a3 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1583,6 +1583,10 @@ namespace {
/// pack.
ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
+ // Transform a ResolvedUnexpandedPackExpr
+ ExprResult
+ TransformResolvedUnexpandedPackExpr(ResolvedUnexpandedPackExpr *E);
+
QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
FunctionProtoTypeLoc TL) {
// Call the base version; it will forward to our overridden version below.
@@ -1848,7 +1852,8 @@ bool TemplateInstantiator::AlreadyTransformed(QualType T) {
if (T.isNull())
return true;
- if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
+ if (T->isInstantiationDependentType() || T->isVariablyModifiedType() ||
+ T->containsUnexpandedParameterPack())
return false;
getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -2473,6 +2478,15 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
if (PD->isParameterPack())
return TransformFunctionParmPackRefExpr(E, PD);
+ if (BindingDecl *BD = dyn_cast<BindingDecl>(D); BD && BD->isParameterPack()) {
+ BD = cast_or_null<BindingDecl>(TransformDecl(BD->getLocation(), BD));
+ if (!BD)
+ return ExprError();
+ if (auto *RP =
+ dyn_cast_if_present<ResolvedUnexpandedPackExpr>(BD->getBinding()))
+ return TransformResolvedUnexpandedPackExpr(RP);
+ }
+
return inherited::TransformDeclRefExpr(E);
}
@@ -2637,6 +2651,19 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
return Result;
}
+ExprResult TemplateInstantiator::TransformResolvedUnexpandedPackExpr(
+ ResolvedUnexpandedPackExpr *E) {
+ if (getSema().ArgumentPackSubstitutionIndex != -1) {
+ assert(static_cast<unsigned>(getSema().ArgumentPackSubstitutionIndex) <
+ E->getNumExprs() &&
+ "ArgumentPackSubstitutionIndex is out of range");
+ return TransformExpr(
+ E->getExpansion(getSema().ArgumentPackSubstitutionIndex));
+ }
+
+ return inherited::TransformResolvedUnexpandedPackExpr(E);
+}
+
QualType TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL,
bool SuppressObjCLifetime) {