Skip to content

Commit 2929344

Browse files
zyn0217cor3ntin
authored andcommitted
Use ordinary substitution for parameter mapping (#60)
1 parent b78291a commit 2929344

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

clang/lib/AST/TemplateBase.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,8 @@ TemplateArgumentLoc::TemplateArgumentLoc(ASTContext &Ctx,
606606
LocInfo(Ctx, TemplateKWLoc, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
607607
assert(Argument.getKind() == TemplateArgument::Template ||
608608
Argument.getKind() == TemplateArgument::TemplateExpansion);
609-
// We can't assume QualifierLoc.getNestedNameSpecifier() ==
610-
// Argument.getAsTemplateOrTemplatePattern().getQualifier() at this point,
611-
// because in template rewriting, we may substitute a DependentTemplateName
612-
// (which has a NNSLoc) into a template template parameter (which
613-
// doesn't have a NNSLoc).
609+
assert(QualifierLoc.getNestedNameSpecifier() ==
610+
Argument.getAsTemplateOrTemplatePattern().getQualifier());
614611
}
615612

616613
NestedNameSpecifierLoc TemplateArgumentLoc::getTemplateQualifierLoc() const {

clang/lib/Sema/SemaConcept.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,9 +2173,6 @@ bool SubstituteParameterMappings::substitute(NormalizedConstraint &N) {
21732173
/*Pattern=*/nullptr,
21742174
/*ForConstraintInstantiation=*/true);
21752175

2176-
// Don't build Subst* nodes to model lambda expressions.
2177-
// The transform of Subst* is oblivious to the lambda type.
2178-
MLTAL.setKind(TemplateSubstitutionKind::Rewrite);
21792176
return SubstituteParameterMappings(
21802177
SemaRef, &MLTAL, CSE->getTemplateArgsAsWritten(), InFoldExpr)
21812178
.substitute(CC.getNormalizedConstraint());

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,15 +2268,6 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
22682268
// We're rewriting the template parameter as a reference to another
22692269
// template parameter.
22702270
Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2271-
if (Arg.getKind() != TemplateArgument::Expression) {
2272-
assert(SemaRef.inParameterMappingSubstitution() ||
2273-
SemaRef.inConstraintSubstitution());
2274-
ExprResult Expr = SemaRef.BuildExpressionFromNonTypeTemplateArgument(
2275-
Arg, E->getLocation());
2276-
if (Expr.isInvalid())
2277-
return E;
2278-
Arg = TemplateArgument(Expr.get(), /*IsCanonical=*/false);
2279-
}
22802271
assert(Arg.getKind() == TemplateArgument::Expression &&
22812272
"unexpected nontype template argument kind in template rewrite");
22822273
// FIXME: This can lead to the same subexpression appearing multiple times
@@ -2498,11 +2489,21 @@ ExprResult
24982489
TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
24992490
SubstNonTypeTemplateParmExpr *E) {
25002491
ExprResult SubstReplacement = E->getReplacement();
2492+
QualType ParamType = E->getParameterType(getSema().Context);
2493+
bool WasDependentLambda = false;
2494+
if (auto *RT = dyn_cast<RecordType>(ParamType);
2495+
RT && RT->getAsCXXRecordDecl())
2496+
WasDependentLambda = RT->getAsCXXRecordDecl()->isDependentLambda();
25012497
if (!isa<ConstantExpr>(SubstReplacement.get()))
25022498
SubstReplacement = TransformExpr(E->getReplacement());
25032499
if (SubstReplacement.isInvalid())
25042500
return true;
2505-
QualType SubstType = TransformType(E->getParameterType(getSema().Context));
2501+
// FIXME: This transform cannot find the instantiated lambda declaration
2502+
// because lambdas are instantiated in a unique scope.
2503+
QualType SubstType =
2504+
WasDependentLambda
2505+
? SubstReplacement.get()->getType().getUnqualifiedType()
2506+
: TransformType(ParamType);
25062507
if (SubstType.isNull())
25072508
return true;
25082509
// The type may have been previously dependent and not now, which means we

clang/test/SemaTemplate/concepts.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,4 +1308,12 @@ struct __completion_domain_or_none_ : __mdefer_<__mtransform<>> {};
13081308

13091309
}
13101310

1311+
namespace case2 {
1312+
1313+
template<auto& Q, class P> concept C = Q.template operator()<P>();
1314+
template<class P> concept E = C<[]<class Ty>{ return false; }, P>;
1315+
static_assert(!E<int>);
1316+
1317+
}
1318+
13111319
}

0 commit comments

Comments
 (0)