@@ -475,21 +475,6 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
475
475
assert ((ND || DC) && " Can't find arguments for a decl if one isn't provided" );
476
476
// Accumulate the set of template argument lists in this structure.
477
477
MultiLevelTemplateArgumentList Result;
478
- getTemplateInstantiationArgs (
479
- Result, ND, DC, Final, Innermost, RelativeToPrimary, Pattern,
480
- ForConstraintInstantiation, SkipForSpecialization,
481
- ForDefaultArgumentSubstitution);
482
- return Result;
483
- }
484
-
485
- void Sema::getTemplateInstantiationArgs (
486
- MultiLevelTemplateArgumentList &Result, const NamedDecl *ND,
487
- const DeclContext *DC, bool Final,
488
- std::optional<ArrayRef<TemplateArgument>> Innermost, bool RelativeToPrimary,
489
- const FunctionDecl *Pattern, bool ForConstraintInstantiation,
490
- bool SkipForSpecialization, bool ForDefaultArgumentSubstitution) {
491
- assert ((ND || DC) && " Can't find arguments for a decl if one isn't provided" );
492
- // Accumulate the set of template argument lists in this structure.
493
478
494
479
using namespace TemplateInstArgsHelpers ;
495
480
const Decl *CurDecl = ND;
@@ -550,12 +535,14 @@ void Sema::getTemplateInstantiationArgs(
550
535
}
551
536
552
537
if (R.IsDone )
553
- return ;
538
+ return Result ;
554
539
if (R.ClearRelativeToPrimary )
555
540
RelativeToPrimary = false ;
556
541
assert (R.NextDecl );
557
542
CurDecl = R.NextDecl ;
558
543
}
544
+
545
+ return Result;
559
546
}
560
547
561
548
bool Sema::CodeSynthesisContext::isInstantiationRecord () const {
@@ -1362,19 +1349,6 @@ namespace {
1362
1349
// Whether an incomplete substituion should be treated as an error.
1363
1350
bool BailOutOnIncomplete;
1364
1351
1365
- private:
1366
- bool isSubstitutingConstraints () const {
1367
- return llvm::any_of (SemaRef.CodeSynthesisContexts , [](auto &Context) {
1368
- return Context.Kind ==
1369
- Sema::CodeSynthesisContext::ConstraintSubstitution;
1370
- });
1371
- }
1372
-
1373
- // CWG2770: Function parameters should be instantiated when they are
1374
- // needed by a satisfaction check of an atomic constraint or
1375
- // (recursively) by another function parameter.
1376
- bool maybeInstantiateFunctionParameterToScope (ParmVarDecl *OldParm);
1377
-
1378
1352
public:
1379
1353
typedef TreeTransform<TemplateInstantiator> inherited;
1380
1354
@@ -1431,19 +1405,12 @@ namespace {
1431
1405
ArrayRef<UnexpandedParameterPack> Unexpanded,
1432
1406
bool &ShouldExpand, bool &RetainExpansion,
1433
1407
std::optional<unsigned > &NumExpansions) {
1434
- if (SemaRef.CurrentInstantiationScope && isSubstitutingConstraints ()) {
1435
- for (UnexpandedParameterPack ParmPack : Unexpanded) {
1436
- NamedDecl *VD = ParmPack.first .dyn_cast <NamedDecl *>();
1437
- if (!isa_and_present<ParmVarDecl>(VD))
1438
- continue ;
1439
- if (maybeInstantiateFunctionParameterToScope (cast<ParmVarDecl>(VD)))
1440
- return true ;
1441
- }
1442
- }
1443
-
1444
- return getSema ().CheckParameterPacksForExpansion (
1445
- EllipsisLoc, PatternRange, Unexpanded, TemplateArgs, ShouldExpand,
1446
- RetainExpansion, NumExpansions);
1408
+ return getSema ().CheckParameterPacksForExpansion (EllipsisLoc,
1409
+ PatternRange, Unexpanded,
1410
+ TemplateArgs,
1411
+ ShouldExpand,
1412
+ RetainExpansion,
1413
+ NumExpansions);
1447
1414
}
1448
1415
1449
1416
void ExpandingFunctionParameterPack (ParmVarDecl *Pack) {
@@ -1944,62 +1911,9 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
1944
1911
// template parameter.
1945
1912
}
1946
1913
1947
- if (SemaRef.CurrentInstantiationScope ) {
1948
- if (isSubstitutingConstraints () && isa<ParmVarDecl>(D) &&
1949
- maybeInstantiateFunctionParameterToScope (cast<ParmVarDecl>(D)))
1950
- return nullptr ;
1951
- }
1952
-
1953
1914
return SemaRef.FindInstantiatedDecl (Loc, cast<NamedDecl>(D), TemplateArgs);
1954
1915
}
1955
1916
1956
- bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope (
1957
- ParmVarDecl *OldParm) {
1958
- if (SemaRef.CurrentInstantiationScope ->findInstantiationUnsafe (OldParm))
1959
- return false ;
1960
- // We're instantiating a function parameter whose associated function template
1961
- // has not been instantiated at this point for constraint evaluation, so make
1962
- // sure the instantiated parameters are owned by a function declaration such
1963
- // that they can be correctly 'captured' in tryCaptureVariable().
1964
- Sema::ContextRAII Context (SemaRef, OldParm->getDeclContext ());
1965
-
1966
- if (!OldParm->isParameterPack ())
1967
- return !TransformFunctionTypeParam (OldParm, /* indexAdjustment=*/ 0 ,
1968
- /* NumExpansions=*/ std::nullopt ,
1969
- /* ExpectParameterPack=*/ false );
1970
-
1971
- SmallVector<UnexpandedParameterPack, 2 > Unexpanded;
1972
-
1973
- // Find the parameter packs that could be expanded.
1974
- TypeLoc TL = OldParm->getTypeSourceInfo ()->getTypeLoc ();
1975
- PackExpansionTypeLoc ExpansionTL = TL.castAs <PackExpansionTypeLoc>();
1976
- TypeLoc Pattern = ExpansionTL.getPatternLoc ();
1977
- SemaRef.collectUnexpandedParameterPacks (Pattern, Unexpanded);
1978
- assert (!Unexpanded.empty () && " Pack expansion without parameter packs?" );
1979
-
1980
- bool ShouldExpand = false ;
1981
- bool RetainExpansion = false ;
1982
- std::optional<unsigned > OrigNumExpansions =
1983
- ExpansionTL.getTypePtr ()->getNumExpansions ();
1984
- std::optional<unsigned > NumExpansions = OrigNumExpansions;
1985
- if (TryExpandParameterPacks (ExpansionTL.getEllipsisLoc (),
1986
- Pattern.getSourceRange (), Unexpanded,
1987
- ShouldExpand, RetainExpansion, NumExpansions))
1988
- return true ;
1989
-
1990
- assert (ShouldExpand && !RetainExpansion &&
1991
- " Shouldn't preserve pack expansion when evaluating constraints" );
1992
- ExpandingFunctionParameterPack (OldParm);
1993
- for (unsigned I = 0 ; I != *NumExpansions; ++I) {
1994
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex (getSema (), I);
1995
- if (!TransformFunctionTypeParam (OldParm, /* indexAdjustment=*/ 0 ,
1996
- /* NumExpansions=*/ OrigNumExpansions,
1997
- /* ExpectParameterPack=*/ false ))
1998
- return true ;
1999
- }
2000
- return false ;
2001
- }
2002
-
2003
1917
Decl *TemplateInstantiator::TransformDefinition (SourceLocation Loc, Decl *D) {
2004
1918
Decl *Inst = getSema ().SubstDecl (D, getSema ().CurContext , TemplateArgs);
2005
1919
if (!Inst)
@@ -4677,8 +4591,9 @@ static const Decl *getCanonicalParmVarDecl(const Decl *D) {
4677
4591
return D;
4678
4592
}
4679
4593
4594
+
4680
4595
llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4681
- LocalInstantiationScope::findInstantiationUnsafe (const Decl *D) {
4596
+ LocalInstantiationScope::findInstantiationOf (const Decl *D) {
4682
4597
D = getCanonicalParmVarDecl (D);
4683
4598
for (LocalInstantiationScope *Current = this ; Current;
4684
4599
Current = Current->Outer ) {
@@ -4703,14 +4618,6 @@ LocalInstantiationScope::findInstantiationUnsafe(const Decl *D) {
4703
4618
break ;
4704
4619
}
4705
4620
4706
- return nullptr ;
4707
- }
4708
-
4709
- llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
4710
- LocalInstantiationScope::findInstantiationOf (const Decl *D) {
4711
- auto *Result = findInstantiationUnsafe (D);
4712
- if (Result)
4713
- return Result;
4714
4621
// If we're performing a partial substitution during template argument
4715
4622
// deduction, we may not have values for template parameters yet.
4716
4623
if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
0 commit comments