@@ -503,7 +503,6 @@ static TemplateDeductionResult DeduceNonTypeTemplateArgument(
503
503
const NonTypeTemplateParmDecl *NTTP, ValueDecl *D, QualType T,
504
504
TemplateDeductionInfo &Info,
505
505
SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
506
- D = D ? cast<ValueDecl>(D->getCanonicalDecl ()) : nullptr ;
507
506
TemplateArgument New (D, T);
508
507
return DeduceNonTypeTemplateArgument (
509
508
S, TemplateParams, NTTP, DeducedTemplateArgument (New), T, Info, Deduced);
@@ -1380,11 +1379,6 @@ static bool isForwardingReference(QualType Param, unsigned FirstInnerIndex) {
1380
1379
return false ;
1381
1380
}
1382
1381
1383
- static CXXRecordDecl *getCanonicalRD (QualType T) {
1384
- return cast<CXXRecordDecl>(
1385
- T->castAs <RecordType>()->getDecl ()->getCanonicalDecl ());
1386
- }
1387
-
1388
1382
// / Attempt to deduce the template arguments by checking the base types
1389
1383
// / according to (C++20 [temp.deduct.call] p4b3.
1390
1384
// /
@@ -1439,7 +1433,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
1439
1433
for (const auto &Base : RD->bases ()) {
1440
1434
QualType T = Base.getType ();
1441
1435
assert (T->isRecordType () && " Base class that isn't a record?" );
1442
- if (Visited.insert (:: getCanonicalRD (T )).second )
1436
+ if (Visited.insert (T-> getAsCXXRecordDecl ( )).second )
1443
1437
ToVisit.push_back (T);
1444
1438
}
1445
1439
};
@@ -1460,7 +1454,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
1460
1454
1461
1455
// If this was a successful deduction, add it to the list of matches,
1462
1456
// otherwise we need to continue searching its bases.
1463
- const CXXRecordDecl *RD = :: getCanonicalRD ( NextT);
1457
+ const CXXRecordDecl *RD = NextT-> getAsCXXRecordDecl ( );
1464
1458
if (BaseResult == TemplateDeductionResult::Success)
1465
1459
Matches.insert ({RD, DeducedCopy});
1466
1460
else
@@ -1481,7 +1475,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
1481
1475
// We can give up once we have a single item (or have run out of things to
1482
1476
// search) since cyclical inheritance isn't valid.
1483
1477
while (Matches.size () > 1 && !ToVisit.empty ()) {
1484
- const CXXRecordDecl *RD = :: getCanonicalRD ( ToVisit.pop_back_val ());
1478
+ const CXXRecordDecl *RD = ToVisit.pop_back_val ()-> getAsCXXRecordDecl ( );
1485
1479
Matches.erase (RD);
1486
1480
1487
1481
// Always add all bases, since the inheritance tree can contain
@@ -2030,15 +2024,16 @@ static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(
2030
2024
if (!S.isCompleteType (Info.getLocation (), A))
2031
2025
return Result;
2032
2026
2033
- if (getCanonicalRD (A)->isInvalidDecl ())
2027
+ const CXXRecordDecl *RD = A->getAsCXXRecordDecl ();
2028
+ if (RD->isInvalidDecl ())
2034
2029
return Result;
2035
2030
2036
2031
// Reset the incorrectly deduced argument from above.
2037
2032
Deduced = DeducedOrig;
2038
2033
2039
2034
// Check bases according to C++14 [temp.deduct.call] p4b3:
2040
- auto BaseResult = DeduceTemplateBases (S, getCanonicalRD (A),
2041
- TemplateParams, P, Info, Deduced);
2035
+ auto BaseResult =
2036
+ DeduceTemplateBases (S, RD, TemplateParams, P, Info, Deduced);
2042
2037
return BaseResult != TemplateDeductionResult::Invalid ? BaseResult
2043
2038
: Result;
2044
2039
}
@@ -3369,9 +3364,7 @@ Sema::DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType,
3369
3364
// Use the InjectedClassNameType.
3370
3365
PType = Context.getTypeDeclType (CTD->getTemplatedDecl ());
3371
3366
} else if (const auto *AliasTemplate = dyn_cast<TypeAliasTemplateDecl>(TD)) {
3372
- PType = AliasTemplate->getTemplatedDecl ()
3373
- ->getUnderlyingType ()
3374
- .getCanonicalType ();
3367
+ PType = AliasTemplate->getTemplatedDecl ()->getUnderlyingType ();
3375
3368
} else {
3376
3369
assert (false && " Expected a class or alias template" );
3377
3370
}
@@ -3505,15 +3498,15 @@ TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments(
3505
3498
// the explicit template arguments. They'll be used as part of deduction
3506
3499
// for this template parameter pack.
3507
3500
unsigned PartiallySubstitutedPackIndex = -1u ;
3508
- if (!CanonicalBuilder .empty ()) {
3509
- const TemplateArgument &Arg = CanonicalBuilder .back ();
3501
+ if (!SugaredBuilder .empty ()) {
3502
+ const TemplateArgument &Arg = SugaredBuilder .back ();
3510
3503
if (Arg.getKind () == TemplateArgument::Pack) {
3511
- auto *Param = TemplateParams->getParam (CanonicalBuilder .size () - 1 );
3504
+ auto *Param = TemplateParams->getParam (SugaredBuilder .size () - 1 );
3512
3505
// If this is a fully-saturated fixed-size pack, it should be
3513
3506
// fully-substituted, not partially-substituted.
3514
3507
std::optional<unsigned > Expansions = getExpandedPackSize (Param);
3515
3508
if (!Expansions || Arg.pack_size () < *Expansions) {
3516
- PartiallySubstitutedPackIndex = CanonicalBuilder .size () - 1 ;
3509
+ PartiallySubstitutedPackIndex = SugaredBuilder .size () - 1 ;
3517
3510
CurrentInstantiationScope->SetPartiallySubstitutedPack (
3518
3511
Param, Arg.pack_begin (), Arg.pack_size ());
3519
3512
}
@@ -3890,8 +3883,8 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
3890
3883
if (!Specialization || Specialization->isInvalidDecl ())
3891
3884
return TemplateDeductionResult::SubstitutionFailure;
3892
3885
3893
- assert (Specialization->getPrimaryTemplate ()-> getCanonicalDecl () ==
3894
- FunctionTemplate-> getCanonicalDecl ( ));
3886
+ assert (isSameDeclaration ( Specialization->getPrimaryTemplate (),
3887
+ FunctionTemplate));
3895
3888
3896
3889
// If the template argument list is owned by the function template
3897
3890
// specialization, release it.
@@ -4736,8 +4729,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
4736
4729
// types, template argument deduction fails.
4737
4730
if (!ArgFunctionType.isNull ()) {
4738
4731
if (IsAddressOfFunction ? !isSameOrCompatibleFunctionType (
4739
- Context.getCanonicalType (SpecializationType),
4740
- Context.getCanonicalType (ArgFunctionType))
4732
+ SpecializationType, ArgFunctionType)
4741
4733
: !Context.hasSameFunctionTypeIgnoringExceptionSpec (
4742
4734
SpecializationType, ArgFunctionType)) {
4743
4735
Info.FirstArg = TemplateArgument (SpecializationType);
@@ -4751,19 +4743,16 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
4751
4743
4752
4744
TemplateDeductionResult Sema::DeduceTemplateArguments (
4753
4745
FunctionTemplateDecl *ConversionTemplate, QualType ObjectType,
4754
- Expr::Classification ObjectClassification, QualType ToType ,
4746
+ Expr::Classification ObjectClassification, QualType A ,
4755
4747
CXXConversionDecl *&Specialization, TemplateDeductionInfo &Info) {
4756
4748
if (ConversionTemplate->isInvalidDecl ())
4757
4749
return TemplateDeductionResult::Invalid;
4758
4750
4759
4751
CXXConversionDecl *ConversionGeneric
4760
4752
= cast<CXXConversionDecl>(ConversionTemplate->getTemplatedDecl ());
4761
4753
4762
- QualType FromType = ConversionGeneric->getConversionType ();
4763
-
4764
- // Canonicalize the types for deduction.
4765
- QualType P = Context.getCanonicalType (FromType);
4766
- QualType A = Context.getCanonicalType (ToType);
4754
+ QualType P = ConversionGeneric->getConversionType ();
4755
+ bool IsReferenceP = P->isReferenceType (), IsReferenceA = A->isReferenceType ();
4767
4756
4768
4757
// C++0x [temp.deduct.conv]p2:
4769
4758
// If P is a reference type, the type referred to by P is used for
@@ -4779,7 +4768,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
4779
4768
// We work around a defect in the standard here: cv-qualifiers are also
4780
4769
// removed from P and A in this case, unless P was a reference type. This
4781
4770
// seems to mostly match what other compilers are doing.
4782
- if (!FromType-> getAs <ReferenceType>() ) {
4771
+ if (!IsReferenceP ) {
4783
4772
A = A.getUnqualifiedType ();
4784
4773
P = P.getUnqualifiedType ();
4785
4774
}
@@ -4835,7 +4824,7 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
4835
4824
// - If the original A is a reference type, A can be more
4836
4825
// cv-qualified than the deduced A (i.e., the type referred to
4837
4826
// by the reference)
4838
- if (ToType-> isReferenceType () )
4827
+ if (IsReferenceA )
4839
4828
TDF |= TDF_ArgWithReferenceType;
4840
4829
// - The deduced A can be another pointer or pointer to member
4841
4830
// type that can be converted to A via a qualification
@@ -5736,17 +5725,6 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
5736
5725
return AtLeastAsConstrained1 ? FT1 : FT2;
5737
5726
}
5738
5727
5739
- // / Determine if the two templates are equivalent.
5740
- static bool isSameTemplate (TemplateDecl *T1, TemplateDecl *T2) {
5741
- if (T1 == T2)
5742
- return true ;
5743
-
5744
- if (!T1 || !T2)
5745
- return false ;
5746
-
5747
- return T1->getCanonicalDecl () == T2->getCanonicalDecl ();
5748
- }
5749
-
5750
5728
UnresolvedSetIterator Sema::getMostSpecialized (
5751
5729
UnresolvedSetIterator SpecBegin, UnresolvedSetIterator SpecEnd,
5752
5730
TemplateSpecCandidateSet &FailedCandidates,
@@ -5774,9 +5752,9 @@ UnresolvedSetIterator Sema::getMostSpecialized(
5774
5752
FunctionTemplateDecl *Challenger
5775
5753
= cast<FunctionDecl>(*I)->getPrimaryTemplate ();
5776
5754
assert (Challenger && " Not a function template specialization?" );
5777
- if (isSameTemplate (getMoreSpecializedTemplate (BestTemplate, Challenger, Loc ,
5778
- TPOC_Other, 0 ),
5779
- Challenger)) {
5755
+ if (declaresSameEntity (getMoreSpecializedTemplate (BestTemplate, Challenger,
5756
+ Loc, TPOC_Other, 0 ),
5757
+ Challenger)) {
5780
5758
Best = I;
5781
5759
BestTemplate = Challenger;
5782
5760
}
@@ -5789,9 +5767,9 @@ UnresolvedSetIterator Sema::getMostSpecialized(
5789
5767
FunctionTemplateDecl *Challenger
5790
5768
= cast<FunctionDecl>(*I)->getPrimaryTemplate ();
5791
5769
if (I != Best &&
5792
- !isSameTemplate (getMoreSpecializedTemplate (BestTemplate, Challenger,
5793
- Loc, TPOC_Other, 0 ),
5794
- BestTemplate)) {
5770
+ !declaresSameEntity (getMoreSpecializedTemplate (BestTemplate, Challenger,
5771
+ Loc, TPOC_Other, 0 ),
5772
+ BestTemplate)) {
5795
5773
Ambiguous = true ;
5796
5774
break ;
5797
5775
}
@@ -6116,11 +6094,10 @@ Sema::getMoreSpecializedPartialSpecialization(
6116
6094
" the partial specializations being compared should specialize"
6117
6095
" the same template." );
6118
6096
TemplateName Name (PS1->getSpecializedTemplate ());
6119
- TemplateName CanonTemplate = Context.getCanonicalTemplateName (Name);
6120
6097
QualType PT1 = Context.getTemplateSpecializationType (
6121
- CanonTemplate , PS1->getTemplateArgs ().asArray ());
6098
+ Name , PS1->getTemplateArgs ().asArray ());
6122
6099
QualType PT2 = Context.getTemplateSpecializationType (
6123
- CanonTemplate , PS2->getTemplateArgs ().asArray ());
6100
+ Name , PS2->getTemplateArgs ().asArray ());
6124
6101
6125
6102
TemplateDeductionInfo Info (Loc);
6126
6103
return getMoreSpecialized (*this , PT1, PT2, PS1, PS2, Info);
@@ -6129,12 +6106,11 @@ Sema::getMoreSpecializedPartialSpecialization(
6129
6106
bool Sema::isMoreSpecializedThanPrimary (
6130
6107
VarTemplatePartialSpecializationDecl *Spec, TemplateDeductionInfo &Info) {
6131
6108
VarTemplateDecl *Primary = Spec->getSpecializedTemplate ();
6132
- TemplateName CanonTemplate =
6133
- Context.getCanonicalTemplateName (TemplateName (Primary));
6109
+ TemplateName Name (Primary);
6134
6110
QualType PrimaryT = Context.getTemplateSpecializationType (
6135
- CanonTemplate , Primary->getInjectedTemplateArgs ());
6111
+ Name , Primary->getInjectedTemplateArgs ());
6136
6112
QualType PartialT = Context.getTemplateSpecializationType (
6137
- CanonTemplate , Spec->getTemplateArgs ().asArray ());
6113
+ Name , Spec->getTemplateArgs ().asArray ());
6138
6114
6139
6115
VarTemplatePartialSpecializationDecl *MaybeSpec =
6140
6116
getMoreSpecialized (*this , PartialT, PrimaryT, Spec, Primary, Info);
0 commit comments