Skip to content

Commit 1a7cee2

Browse files
committed
Revert "[Clang][Sema] Retain the expanding index for unevaluated type constraints (#109518)"
This reverts commit 50e5411.
1 parent 471bef0 commit 1a7cee2

File tree

4 files changed

+7
-135
lines changed

4 files changed

+7
-135
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11350,7 +11350,6 @@ class Sema final : public SemaBase {
1135011350
ConceptDecl *NamedConcept, NamedDecl *FoundDecl,
1135111351
const TemplateArgumentListInfo *TemplateArgs,
1135211352
TemplateTypeParmDecl *ConstrainedParameter,
11353-
QualType ConstrainedType,
1135411353
SourceLocation EllipsisLoc);
1135511354

1135611355
bool AttachTypeConstraint(AutoTypeLoc TL,

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,7 @@ bool Sema::BuildTypeConstraint(const CXXScopeSpec &SS,
11331133
SS.isSet() ? SS.getWithLocInContext(Context) : NestedNameSpecifierLoc(),
11341134
ConceptName, CD, /*FoundDecl=*/USD ? cast<NamedDecl>(USD) : CD,
11351135
TypeConstr->LAngleLoc.isValid() ? &TemplateArgs : nullptr,
1136-
ConstrainedParameter, Context.getTypeDeclType(ConstrainedParameter),
1137-
EllipsisLoc);
1136+
ConstrainedParameter, EllipsisLoc);
11381137
}
11391138

11401139
template <typename ArgumentLocAppender>
@@ -1191,7 +1190,6 @@ bool Sema::AttachTypeConstraint(NestedNameSpecifierLoc NS,
11911190
ConceptDecl *NamedConcept, NamedDecl *FoundDecl,
11921191
const TemplateArgumentListInfo *TemplateArgs,
11931192
TemplateTypeParmDecl *ConstrainedParameter,
1194-
QualType ConstrainedType,
11951193
SourceLocation EllipsisLoc) {
11961194
// C++2a [temp.param]p4:
11971195
// [...] If Q is of the form C<A1, ..., An>, then let E' be
@@ -1200,7 +1198,7 @@ bool Sema::AttachTypeConstraint(NestedNameSpecifierLoc NS,
12001198
TemplateArgs ? ASTTemplateArgumentListInfo::Create(Context,
12011199
*TemplateArgs) : nullptr;
12021200

1203-
QualType ParamAsArgument = ConstrainedType;
1201+
QualType ParamAsArgument(ConstrainedParameter->getTypeForDecl(), 0);
12041202

12051203
ExprResult ImmediatelyDeclaredConstraint = formImmediatelyDeclaredConstraint(
12061204
*this, NS, NameInfo, NamedConcept, FoundDecl,

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,21 +1717,6 @@ namespace {
17171717
SubstTemplateTypeParmPackTypeLoc TL,
17181718
bool SuppressObjCLifetime);
17191719

1720-
QualType
1721-
TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB,
1722-
SubstTemplateTypeParmTypeLoc TL) {
1723-
if (SemaRef.CodeSynthesisContexts.back().Kind !=
1724-
Sema::CodeSynthesisContext::ConstraintSubstitution)
1725-
return inherited::TransformSubstTemplateTypeParmType(TLB, TL);
1726-
1727-
auto PackIndex = TL.getTypePtr()->getPackIndex();
1728-
std::optional<Sema::ArgumentPackSubstitutionIndexRAII> SubstIndex;
1729-
if (SemaRef.ArgumentPackSubstitutionIndex == -1 && PackIndex)
1730-
SubstIndex.emplace(SemaRef, *PackIndex);
1731-
1732-
return inherited::TransformSubstTemplateTypeParmType(TLB, TL);
1733-
}
1734-
17351720
CXXRecordDecl::LambdaDependencyKind
17361721
ComputeLambdaDependency(LambdaScopeInfo *LSI) {
17371722
if (auto TypeAlias =
@@ -3166,58 +3151,6 @@ namespace {
31663151

31673152
} // namespace
31683153

3169-
namespace {
3170-
3171-
struct ExpandPackedTypeConstraints
3172-
: TreeTransform<ExpandPackedTypeConstraints> {
3173-
3174-
using inherited = TreeTransform<ExpandPackedTypeConstraints>;
3175-
3176-
ExpandPackedTypeConstraints(Sema &SemaRef) : inherited(SemaRef) {}
3177-
3178-
using inherited::TransformTemplateTypeParmType;
3179-
3180-
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
3181-
TemplateTypeParmTypeLoc TL, bool) {
3182-
const TemplateTypeParmType *T = TL.getTypePtr();
3183-
if (!T->isParameterPack()) {
3184-
TemplateTypeParmTypeLoc NewTL =
3185-
TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
3186-
NewTL.setNameLoc(TL.getNameLoc());
3187-
return TL.getType();
3188-
}
3189-
3190-
assert(SemaRef.ArgumentPackSubstitutionIndex != -1);
3191-
3192-
QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
3193-
TL.getType(), T->getDecl(), T->getIndex(),
3194-
SemaRef.ArgumentPackSubstitutionIndex);
3195-
SubstTemplateTypeParmTypeLoc NewTL =
3196-
TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
3197-
NewTL.setNameLoc(TL.getNameLoc());
3198-
return Result;
3199-
}
3200-
3201-
QualType TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB,
3202-
SubstTemplateTypeParmTypeLoc TL) {
3203-
const SubstTemplateTypeParmType *T = TL.getTypePtr();
3204-
if (T->getPackIndex()) {
3205-
SubstTemplateTypeParmTypeLoc TypeLoc =
3206-
TLB.push<SubstTemplateTypeParmTypeLoc>(TL.getType());
3207-
TypeLoc.setNameLoc(TL.getNameLoc());
3208-
return TypeLoc.getType();
3209-
}
3210-
return inherited::TransformSubstTemplateTypeParmType(TLB, TL);
3211-
}
3212-
3213-
bool SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
3214-
TemplateArgumentListInfo &Out) {
3215-
return inherited::TransformTemplateArguments(Args.begin(), Args.end(), Out);
3216-
}
3217-
};
3218-
3219-
} // namespace
3220-
32213154
bool Sema::SubstTypeConstraint(
32223155
TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
32233156
const MultiLevelTemplateArgumentList &TemplateArgs,
@@ -3226,62 +3159,9 @@ bool Sema::SubstTypeConstraint(
32263159
TC->getTemplateArgsAsWritten();
32273160

32283161
if (!EvaluateConstraints) {
3229-
bool ShouldExpandExplicitTemplateArgs =
3230-
TemplArgInfo && ArgumentPackSubstitutionIndex != -1 &&
3231-
llvm::any_of(TemplArgInfo->arguments(), [](auto &Arg) {
3232-
return Arg.getArgument().containsUnexpandedParameterPack();
3233-
});
3234-
3235-
// We want to transform the packs into Subst* nodes for type constraints
3236-
// inside a pack expansion. For example,
3237-
//
3238-
// template <class... Ts> void foo() {
3239-
// bar([](C<Ts> auto value) {}...);
3240-
// }
3241-
//
3242-
// As we expand Ts in the process of instantiating foo(), and retain
3243-
// the original template depths of Ts until the constraint evaluation, we
3244-
// would otherwise have no chance to expand Ts by the time of evaluating
3245-
// C<auto, Ts>.
3246-
//
3247-
// So we form a Subst* node for Ts along with a proper substitution index
3248-
// here, and substitute the node with a complete MLTAL later in evaluation.
3249-
if (ShouldExpandExplicitTemplateArgs) {
3250-
TemplateArgumentListInfo InstArgs;
3251-
InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc);
3252-
InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc);
3253-
if (ExpandPackedTypeConstraints(*this).SubstTemplateArguments(
3254-
TemplArgInfo->arguments(), InstArgs))
3255-
return true;
3256-
3257-
// The type of the original parameter.
3258-
auto *ConstraintExpr = TC->getImmediatelyDeclaredConstraint();
3259-
QualType ConstrainedType;
3260-
3261-
if (auto *FE = dyn_cast<CXXFoldExpr>(ConstraintExpr)) {
3262-
assert(FE->getLHS());
3263-
ConstraintExpr = FE->getLHS();
3264-
}
3265-
auto *CSE = cast<ConceptSpecializationExpr>(ConstraintExpr);
3266-
assert(!CSE->getTemplateArguments().empty() &&
3267-
"Empty template arguments?");
3268-
ConstrainedType = CSE->getTemplateArguments()[0].getAsType();
3269-
assert(!ConstrainedType.isNull() &&
3270-
"Failed to extract the original ConstrainedType?");
3271-
3272-
return AttachTypeConstraint(
3273-
TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
3274-
TC->getNamedConcept(),
3275-
/*FoundDecl=*/TC->getConceptReference()->getFoundDecl(), &InstArgs,
3276-
Inst, ConstrainedType,
3277-
Inst->isParameterPack()
3278-
? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
3279-
->getEllipsisLoc()
3280-
: SourceLocation());
3281-
}
3282-
Inst->setTypeConstraint(TC->getConceptReference(),
3283-
TC->getImmediatelyDeclaredConstraint());
3284-
return false;
3162+
Inst->setTypeConstraint(TC->getConceptReference(),
3163+
TC->getImmediatelyDeclaredConstraint());
3164+
return false;
32853165
}
32863166

32873167
TemplateArgumentListInfo InstArgs;
@@ -3297,7 +3177,6 @@ bool Sema::SubstTypeConstraint(
32973177
TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
32983178
TC->getNamedConcept(),
32993179
/*FoundDecl=*/TC->getConceptReference()->getFoundDecl(), &InstArgs, Inst,
3300-
Context.getTypeDeclType(Inst),
33013180
Inst->isParameterPack()
33023181
? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint())
33033182
->getEllipsisLoc()

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,9 +3052,7 @@ InventTemplateParameter(TypeProcessingState &state, QualType T,
30523052
AutoLoc.getNestedNameSpecifierLoc(), AutoLoc.getConceptNameInfo(),
30533053
AutoLoc.getNamedConcept(), /*FoundDecl=*/AutoLoc.getFoundDecl(),
30543054
AutoLoc.hasExplicitTemplateArgs() ? &TAL : nullptr,
3055-
InventedTemplateParam,
3056-
S.Context.getTypeDeclType(InventedTemplateParam),
3057-
D.getEllipsisLoc());
3055+
InventedTemplateParam, D.getEllipsisLoc());
30583056
}
30593057
} else {
30603058
// The 'auto' appears in the decl-specifiers; we've not finished forming
@@ -3091,9 +3089,7 @@ InventTemplateParameter(TypeProcessingState &state, QualType T,
30913089
/*FoundDecl=*/
30923090
USD ? cast<NamedDecl>(USD) : CD,
30933091
TemplateId->LAngleLoc.isValid() ? &TemplateArgsInfo : nullptr,
3094-
InventedTemplateParam,
3095-
S.Context.getTypeDeclType(InventedTemplateParam),
3096-
D.getEllipsisLoc());
3092+
InventedTemplateParam, D.getEllipsisLoc());
30973093
}
30983094
}
30993095
}

0 commit comments

Comments
 (0)