Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions clang/lib/AST/TemplateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,8 @@ TemplateArgumentLoc::TemplateArgumentLoc(ASTContext &Ctx,
LocInfo(Ctx, TemplateKWLoc, QualifierLoc, TemplateNameLoc, EllipsisLoc) {
assert(Argument.getKind() == TemplateArgument::Template ||
Argument.getKind() == TemplateArgument::TemplateExpansion);
// We can't assume QualifierLoc.getNestedNameSpecifier() ==
// Argument.getAsTemplateOrTemplatePattern().getQualifier() at this point,
// because in template rewriting, we may substitute a DependentTemplateName
// (which has a NNSLoc) into a template template parameter (which
// doesn't have a NNSLoc).
assert(QualifierLoc.getNestedNameSpecifier() ==
Argument.getAsTemplateOrTemplatePattern().getQualifier());
}

NestedNameSpecifierLoc TemplateArgumentLoc::getTemplateQualifierLoc() const {
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,9 +2173,6 @@ bool SubstituteParameterMappings::substitute(NormalizedConstraint &N) {
/*Pattern=*/nullptr,
/*ForConstraintInstantiation=*/true);

// Don't build Subst* nodes to model lambda expressions.
// The transform of Subst* is oblivious to the lambda type.
MLTAL.setKind(TemplateSubstitutionKind::Rewrite);
return SubstituteParameterMappings(
SemaRef, &MLTAL, CSE->getTemplateArgsAsWritten(), InFoldExpr)
.substitute(CC.getNormalizedConstraint());
Expand Down
21 changes: 11 additions & 10 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,15 +2268,6 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
// We're rewriting the template parameter as a reference to another
// template parameter.
Arg = getTemplateArgumentPackPatternForRewrite(Arg);
if (Arg.getKind() != TemplateArgument::Expression) {
assert(SemaRef.inParameterMappingSubstitution() ||
SemaRef.inConstraintSubstitution());
ExprResult Expr = SemaRef.BuildExpressionFromNonTypeTemplateArgument(
Arg, E->getLocation());
if (Expr.isInvalid())
return E;
Arg = TemplateArgument(Expr.get(), /*IsCanonical=*/false);
}
assert(Arg.getKind() == TemplateArgument::Expression &&
"unexpected nontype template argument kind in template rewrite");
// FIXME: This can lead to the same subexpression appearing multiple times
Expand Down Expand Up @@ -2498,11 +2489,21 @@ ExprResult
TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr(
SubstNonTypeTemplateParmExpr *E) {
ExprResult SubstReplacement = E->getReplacement();
QualType ParamType = E->getParameterType(getSema().Context);
bool WasDependentLambda = false;
if (auto *RT = dyn_cast<RecordType>(ParamType);
RT && RT->getAsCXXRecordDecl())
WasDependentLambda = RT->getAsCXXRecordDecl()->isDependentLambda();
if (!isa<ConstantExpr>(SubstReplacement.get()))
SubstReplacement = TransformExpr(E->getReplacement());
if (SubstReplacement.isInvalid())
return true;
QualType SubstType = TransformType(E->getParameterType(getSema().Context));
// FIXME: This transform cannot find the instantiated lambda declaration
// because lambdas are instantiated in a unique scope.
QualType SubstType =
WasDependentLambda
? SubstReplacement.get()->getType().getUnqualifiedType()
: TransformType(ParamType);
if (SubstType.isNull())
return true;
// The type may have been previously dependent and not now, which means we
Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaTemplate/concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,4 +1287,12 @@ struct __completion_domain_or_none_ : __mdefer_<__mtransform<>> {};

}

namespace case2 {

template<auto& Q, class P> concept C = Q.template operator()<P>();
template<class P> concept E = C<[]<class Ty>{ return false; }, P>;
static_assert(!E<int>);

}

}