Skip to content

Commit a0d644d

Browse files
committed
Fix SemaTemplate/concepts-lambda.cpp
1 parent 6f462d8 commit a0d644d

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13134,6 +13134,8 @@ class Sema final : public SemaBase {
1313413134
/// Whether we're substituting into constraints.
1313513135
bool InConstraintSubstitution;
1313613136

13137+
bool InParameterMappingSubstitution;
13138+
1313713139
/// The point of instantiation or synthesis within the source code.
1313813140
SourceLocation PointOfInstantiation;
1313913141

@@ -13873,11 +13875,17 @@ class Sema final : public SemaBase {
1387313875
}
1387413876

1387513877
/// Determine whether we are currently performing constraint substitution.
13878+
// FIXME: Rename it
1387613879
bool inConstraintSubstitution() const {
1387713880
return !CodeSynthesisContexts.empty() &&
1387813881
CodeSynthesisContexts.back().InConstraintSubstitution;
1387913882
}
1388013883

13884+
bool inParameterMappingSubstitution() const {
13885+
return !CodeSynthesisContexts.empty() &&
13886+
CodeSynthesisContexts.back().InParameterMappingSubstitution;
13887+
}
13888+
1388113889
using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
1388213890

1388313891
/// \brief create a Requirement::SubstitutionDiagnostic with only a

clang/include/clang/Sema/Template.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ enum class TemplateSubstitutionKind : char {
261261
// ==
262262
// AssociatedDecl) &&
263263
// "Trying to change incorrect declaration?");
264+
TemplateArgumentLists.back().AssociatedDeclAndFinal.setPointer(AssociatedDecl);
264265
TemplateArgumentLists.back().Args = Args;
265266
}
266267

clang/lib/Sema/SemaConcept.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,9 @@ static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N,
16591659
/*RelativeToPrimary=*/true,
16601660
/*Pattern=*/nullptr,
16611661
/*ForConstraintInstantiation=*/true);
1662-
1662+
// Don't build Subst* nodes to model lambda expressions.
1663+
// The transform of Subst* is oblivious to the lambda type.
1664+
MLTAL.setKind(TemplateSubstitutionKind::Rewrite);
16631665
return substituteParameterMappings(S, N, MLTAL,
16641666
CSE->getTemplateArgsAsWritten());
16651667
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,9 @@ static ExprResult formImmediatelyDeclaredConstraint(
11651165
ExprResult ImmediatelyDeclaredConstraint = S.CheckConceptTemplateId(
11661166
SS, /*TemplateKWLoc=*/SourceLocation(), NameInfo,
11671167
/*FoundDecl=*/FoundDecl ? FoundDecl : NamedConcept, NamedConcept,
1168-
&ConstraintArgs);
1168+
&ConstraintArgs,
1169+
/*DoCheckConstraintSatisfaction=*/
1170+
!S.inParameterMappingSubstitution());
11691171
if (ImmediatelyDeclaredConstraint.isInvalid() || !EllipsisLoc.isValid())
11701172
return ImmediatelyDeclaredConstraint;
11711173

@@ -4742,7 +4744,7 @@ ExprResult Sema::CheckConceptTemplateId(
47424744
*TemplateArgs, CTAI.CanonicalConverted);
47434745
MultiLevelTemplateArgumentList MLTAL(NamedConcept, CTAI.CanonicalConverted,
47444746
/*Final=*/false);
4745-
auto *CL = ConceptReference::Create(
4747+
auto *CL = ConceptReference::Create(
47464748
Context,
47474749
SS.isSet() ? SS.getWithLocInContext(Context) : NestedNameSpecifierLoc{},
47484750
TemplateKWLoc, ConceptNameInfo, FoundDecl, NamedConcept,

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,15 @@ Sema::InstantiatingTemplate::InstantiatingTemplate(
623623
Inst.DeductionInfo = DeductionInfo;
624624
Inst.InstantiationRange = InstantiationRange;
625625
Inst.InConstraintSubstitution =
626-
Inst.Kind == CodeSynthesisContext::ConstraintSubstitution;
627-
if (!SemaRef.CodeSynthesisContexts.empty())
626+
Inst.Kind == CodeSynthesisContext::ConstraintsCheck;
627+
Inst.InParameterMappingSubstitution =
628+
Inst.Kind == CodeSynthesisContext::ParameterMappingSubstitution;
629+
if (!SemaRef.CodeSynthesisContexts.empty()) {
628630
Inst.InConstraintSubstitution |=
629631
SemaRef.CodeSynthesisContexts.back().InConstraintSubstitution;
632+
Inst.InParameterMappingSubstitution |=
633+
SemaRef.CodeSynthesisContexts.back().InParameterMappingSubstitution;
634+
}
630635

631636
SemaRef.pushCodeSynthesisContext(Inst);
632637

@@ -2225,6 +2230,14 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
22252230
// We're rewriting the template parameter as a reference to another
22262231
// template parameter.
22272232
Arg = getTemplateArgumentPackPatternForRewrite(Arg);
2233+
if (Arg.getKind() != TemplateArgument::Expression) {
2234+
assert(SemaRef.inParameterMappingSubstitution());
2235+
// FIXME: SourceLocation()?
2236+
ExprResult E = SemaRef.BuildExpressionFromNonTypeTemplateArgument(Arg, SourceLocation());
2237+
if (E.isInvalid())
2238+
return E;
2239+
Arg = TemplateArgument(E.get(), /*IsCanonical=*/false);
2240+
}
22282241
assert(Arg.getKind() == TemplateArgument::Expression &&
22292242
"unexpected nontype template argument kind in template rewrite");
22302243
// FIXME: This can lead to the same subexpression appearing multiple times
@@ -3249,7 +3262,7 @@ bool Sema::SubstTypeConstraint(
32493262
const ASTTemplateArgumentListInfo *TemplArgInfo =
32503263
TC->getTemplateArgsAsWritten();
32513264

3252-
if (!EvaluateConstraints) {
3265+
if (!EvaluateConstraints && !inParameterMappingSubstitution()) {
32533266
UnsignedOrNone Index = TC->getArgPackSubstIndex();
32543267
if (!Index)
32553268
Index = SemaRef.ArgPackSubstIndex;

0 commit comments

Comments
 (0)