Skip to content

Commit c37199b

Browse files
committed
Fix pack expansion
clang/test/SemaTemplate/alias-template-with-lambdas.cpp
1 parent a0d644d commit c37199b

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

clang/include/clang/Sema/SemaConcept.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct NormalizedConstraint {
6565
struct AtomicBits {
6666
LLVM_PREFERRED_TYPE(ConstraintKind)
6767
unsigned Kind : 5;
68-
unsigned : 1;
68+
unsigned Placeholder : 1;
6969
unsigned PackSubstitutionIndex : 26;
7070
llvm::SmallBitVector Indexes;
7171
TemplateArgumentLoc *Args;
@@ -114,6 +114,7 @@ struct NormalizedConstraint {
114114
const NamedDecl *ConstraintDecl,
115115
UnsignedOrNone PackIndex)
116116
: Atomic{llvm::to_underlying(ConstraintKind::Atomic),
117+
/*Placeholder=*/0,
117118
PackIndex.toInternalRepresentation(),
118119
/*Indexes=*/{},
119120
/*Args=*/nullptr,
@@ -134,7 +135,8 @@ struct NormalizedConstraint {
134135
NormalizedConstraint *SubConstraint,
135136
UnsignedOrNone PackIndex)
136137
: ConceptId{{llvm::to_underlying(ConstraintKind::ConceptId),
137-
PackIndex.toInternalRepresentation(), /*Indexes=*/{},
138+
/*Placeholder=*/0, PackIndex.toInternalRepresentation(),
139+
/*Indexes=*/{},
138140
/*Args=*/nullptr, ConceptId, ConstraintDecl},
139141
SubConstraint} {}
140142

@@ -237,7 +239,8 @@ struct NormalizedConstraint {
237239
fromAssociatedConstraints(Sema &S, const NamedDecl *D,
238240
ArrayRef<AssociatedConstraint> ACs);
239241
static NormalizedConstraint *fromConstraintExpr(Sema &S, const NamedDecl *D,
240-
const Expr *E);
242+
const Expr *E,
243+
UnsignedOrNone SubstIndex);
241244
};
242245

243246
class CompoundConstraint : public NormalizedConstraint {

clang/lib/Sema/SemaConcept.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ SubstitutionInTemplateArguments(
368368

369369
TemplateArgumentListInfo SubstArgs;
370370
if (Constraint.hasParameterMapping()) {
371+
Sema::ArgPackSubstIndexRAII SubstIndex(
372+
S, Constraint.getPackSubstitutionIndex());
371373
if (S.SubstTemplateArgumentsInParameterMapping(
372374
Constraint.getParameterMapping(), MLTAL, SubstArgs) ||
373375
Trap.hasErrorOccurred())
@@ -590,6 +592,8 @@ static bool calculateConstraintSatisfaction(
590592
return Ok;
591593

592594
Sema::SFINAETrap Trap(S);
595+
Sema::ArgPackSubstIndexRAII SubstIndex(
596+
S, Constraint.getPackSubstitutionIndex());
593597

594598
const ASTTemplateArgumentListInfo *Ori =
595599
Constraint.getConceptId()->getTemplateArgsAsWritten();
@@ -604,7 +608,8 @@ static bool calculateConstraintSatisfaction(
604608
Ori->NumTemplateArgs, TransArgs))
605609
return Ok;
606610

607-
if (S.SubstTemplateArguments(TransArgs.arguments(), MLTAL, OutArgs) ||
611+
if (S.SubstTemplateArguments(TransArgs.arguments(), *SubstitutedArgs,
612+
OutArgs) ||
608613
Trap.hasErrorOccurred())
609614
return Ok;
610615

@@ -1669,11 +1674,13 @@ static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N,
16691674
NormalizedConstraint *NormalizedConstraint::fromAssociatedConstraints(
16701675
Sema &S, const NamedDecl *D, ArrayRef<AssociatedConstraint> ACs) {
16711676
assert(ACs.size() != 0);
1672-
auto Conjunction = fromConstraintExpr(S, D, ACs[0].ConstraintExpr);
1677+
auto *Conjunction =
1678+
fromConstraintExpr(S, D, ACs[0].ConstraintExpr, ACs[0].ArgPackSubstIndex);
16731679
if (!Conjunction)
16741680
return nullptr;
16751681
for (unsigned I = 1; I < ACs.size(); ++I) {
1676-
auto Next = fromConstraintExpr(S, D, ACs[I].ConstraintExpr);
1682+
auto *Next = fromConstraintExpr(S, D, ACs[I].ConstraintExpr,
1683+
ACs[I].ArgPackSubstIndex);
16771684
if (!Next)
16781685
return nullptr;
16791686
Conjunction = CompoundConstraint::CreateConjunction(S.getASTContext(),
@@ -1682,9 +1689,8 @@ NormalizedConstraint *NormalizedConstraint::fromAssociatedConstraints(
16821689
return Conjunction;
16831690
}
16841691

1685-
NormalizedConstraint *
1686-
NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
1687-
const Expr *E) {
1692+
NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
1693+
Sema &S, const NamedDecl *D, const Expr *E, UnsignedOrNone SubstIndex) {
16881694
assert(E != nullptr);
16891695

16901696
// C++ [temp.constr.normal]p1.1
@@ -1705,10 +1711,10 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
17051711
// See http://cplusplus.github.io/concepts-ts/ts-active.html#28
17061712

17071713
if (LogicalBinOp BO = E) {
1708-
auto LHS = fromConstraintExpr(S, D, BO.getLHS());
1714+
auto *LHS = fromConstraintExpr(S, D, BO.getLHS(), SubstIndex);
17091715
if (!LHS)
17101716
return nullptr;
1711-
auto RHS = fromConstraintExpr(S, D, BO.getRHS());
1717+
auto *RHS = fromConstraintExpr(S, D, BO.getRHS(), SubstIndex);
17121718
if (!RHS)
17131719
return nullptr;
17141720

@@ -1736,7 +1742,7 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
17361742
ConceptDecl *CD = CSE->getNamedConcept();
17371743
SubNF = NormalizedConstraint::fromAssociatedConstraints(
17381744
S, CSE->getNamedConcept(),
1739-
AssociatedConstraint(CD->getConstraintExpr()));
1745+
AssociatedConstraint(CD->getConstraintExpr(), SubstIndex));
17401746

17411747
if (!SubNF)
17421748
return nullptr;
@@ -1746,7 +1752,7 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
17461752

17471753
return ConceptIdConstraint::Create(S.getASTContext(),
17481754
CSE->getConceptReference(), SubNF, D,
1749-
S.ArgPackSubstIndex);
1755+
SubstIndex);
17501756

17511757
} else if (auto *FE = dyn_cast<const CXXFoldExpr>(E);
17521758
FE && S.getLangOpts().CPlusPlus26 &&
@@ -1761,8 +1767,8 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
17611767
: FoldExpandedConstraint::FoldOperatorKind::Or;
17621768

17631769
if (FE->getInit()) {
1764-
auto LHS = fromConstraintExpr(S, D, FE->getLHS());
1765-
auto RHS = fromConstraintExpr(S, D, FE->getRHS());
1770+
auto *LHS = fromConstraintExpr(S, D, FE->getLHS(), SubstIndex);
1771+
auto *RHS = fromConstraintExpr(S, D, FE->getRHS(), SubstIndex);
17661772
if (!LHS || !RHS)
17671773
return nullptr;
17681774

@@ -1779,13 +1785,13 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
17791785
: CCK_Disjunction),
17801786
RHS);
17811787
}
1782-
auto Sub = fromConstraintExpr(S, D, FE->getPattern());
1788+
auto *Sub = fromConstraintExpr(S, D, FE->getPattern(), SubstIndex);
17831789
if (!Sub)
17841790
return nullptr;
17851791
return FoldExpandedConstraint::Create(S.getASTContext(), FE->getPattern(),
17861792
Kind, Sub);
17871793
}
1788-
return AtomicConstraint::Create(S.getASTContext(), E, D, S.ArgPackSubstIndex);
1794+
return AtomicConstraint::Create(S.getASTContext(), E, D, SubstIndex);
17891795
}
17901796

17911797
bool FoldExpandedConstraint::AreCompatibleForSubsumption(

0 commit comments

Comments
 (0)