@@ -986,47 +986,33 @@ ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
986
986
987
987
SourceRange
988
988
ClassTemplateSpecializationDecl::getSourceRange () const {
989
- using CTPSDecl = ClassTemplatePartialSpecializationDecl;
990
- if (ExplicitInfo) {
991
- SourceLocation Begin = getTemplateKeywordLoc ();
992
- if (Begin.isInvalid ()) {
993
- if (getNumTemplateParameterLists ())
994
- Begin = getTemplateParameterList (0 )->getTemplateLoc ();
995
- else if (const auto *CTPSD = dyn_cast<CTPSDecl>(this ))
996
- Begin = CTPSD->getTemplateParameters ()->getTemplateLoc ();
997
- }
998
- if (Begin.isValid ()) {
999
- // Here we have an explicit (partial) specialization or instantiation.
1000
- assert (getSpecializationKind () == TSK_ExplicitSpecialization ||
1001
- getSpecializationKind () == TSK_ExplicitInstantiationDeclaration ||
1002
- getSpecializationKind () == TSK_ExplicitInstantiationDefinition);
1003
- if (getExternLoc ().isValid ())
1004
- Begin = getExternLoc ();
1005
- SourceLocation End = getBraceRange ().getEnd ();
1006
- if (End.isInvalid ())
1007
- End = getTemplateArgsAsWritten ()->getRAngleLoc ();
1008
- return SourceRange (Begin, End);
1009
- }
1010
- // An implicit instantiation of a class template partial specialization
1011
- // uses ExplicitInfo to record the TypeAsWritten, but the source
1012
- // locations should be retrieved from the instantiation pattern.
1013
- auto *ctpsd = const_cast <CTPSDecl *>(cast<CTPSDecl>(this ));
1014
- CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember ();
1015
- assert (inst_from != nullptr );
1016
- return inst_from->getSourceRange ();
1017
- }
1018
- else {
989
+ if (getSpecializationKind () == TSK_ExplicitInstantiationDeclaration) {
990
+ return SourceRange (getExternLoc (), getTemplateArgsAsWritten ()->getRAngleLoc ());
991
+ } else if (getSpecializationKind () == TSK_ExplicitInstantiationDefinition) {
992
+ return SourceRange (getTemplateKeywordLoc (), getTemplateArgsAsWritten ()->getRAngleLoc ());
993
+ } else if (!isExplicitSpecialization ()) {
1019
994
// No explicit info available.
1020
995
llvm::PointerUnion<ClassTemplateDecl *,
1021
996
ClassTemplatePartialSpecializationDecl *>
1022
- inst_from = getInstantiatedFrom ();
1023
- if (inst_from .isNull ())
997
+ InstFrom = getInstantiatedFrom ();
998
+ if (InstFrom .isNull ())
1024
999
return getSpecializedTemplate ()->getSourceRange ();
1025
- if (const auto *ctd = inst_from .dyn_cast <ClassTemplateDecl *>())
1026
- return ctd ->getSourceRange ();
1027
- return inst_from .get <ClassTemplatePartialSpecializationDecl *>()
1000
+ if (const auto *CTD = InstFrom .dyn_cast <ClassTemplateDecl *>())
1001
+ return CTD ->getSourceRange ();
1002
+ return InstFrom .get <ClassTemplatePartialSpecializationDecl *>()
1028
1003
->getSourceRange ();
1029
1004
}
1005
+ SourceLocation Begin = TagDecl::getOuterLocStart ();
1006
+ if (const auto *CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(this )) {
1007
+ if (const auto *InstFrom = CTPSD->getInstantiatedFromMember ())
1008
+ return InstFrom->getSourceRange ();
1009
+ else if (!getNumTemplateParameterLists ())
1010
+ Begin = CTPSD->getTemplateParameters ()->getTemplateLoc ();
1011
+ }
1012
+ SourceLocation End = getBraceRange ().getEnd ();
1013
+ if (End.isInvalid ())
1014
+ End = getTemplateArgsAsWritten ()->getRAngleLoc ();
1015
+ return SourceRange (Begin, End);
1030
1016
}
1031
1017
1032
1018
void ClassTemplateSpecializationDecl::setExternLoc (SourceLocation Loc) {
@@ -1395,6 +1381,12 @@ SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
1395
1381
if (isExplicitSpecialization () && !hasInit ()) {
1396
1382
if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten ())
1397
1383
return SourceRange (getOuterLocStart (), Info->getRAngleLoc ());
1384
+ } else if (getTemplateSpecializationKind () == TSK_ExplicitInstantiationDeclaration ) {
1385
+ if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten ())
1386
+ return SourceRange (getExternLoc (), Info->getRAngleLoc ());
1387
+ } else if (getTemplateSpecializationKind () == TSK_ExplicitInstantiationDefinition) {
1388
+ if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten ())
1389
+ return SourceRange (getTemplateKeywordLoc (), Info->getRAngleLoc ());
1398
1390
}
1399
1391
return VarDecl::getSourceRange ();
1400
1392
}
0 commit comments