diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -2926,13 +2926,7 @@ return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation(); } - SourceRange getSourceRange() const override LLVM_READONLY { - if (isExplicitSpecialization()) { - if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo()) - return SourceRange(getOuterLocStart(), Info->getRAngleLoc()); - } - return VarDecl::getSourceRange(); - } + SourceRange getSourceRange() const override LLVM_READONLY; void Profile(llvm::FoldingSetNodeID &ID) const { Profile(ID, TemplateArgs->asArray(), getASTContext()); @@ -3091,13 +3085,7 @@ return First->InstantiatedFromMember.setInt(true); } - SourceRange getSourceRange() const override LLVM_READONLY { - if (isExplicitSpecialization()) { - if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten()) - return SourceRange(getOuterLocStart(), Info->getRAngleLoc()); - } - return VarDecl::getSourceRange(); - } + SourceRange getSourceRange() const override LLVM_READONLY; void Profile(llvm::FoldingSetNodeID &ID) const { Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(), diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1402,6 +1402,21 @@ ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo); } +SourceRange VarTemplateSpecializationDecl::getSourceRange() const { + if (const Expr *Init = getInit()) { + SourceLocation InitEnd = Init->getEndLoc(); + // If Init is implicit, ignore its source range + if (InitEnd.isValid() && InitEnd != getLocation()) + return SourceRange(getOuterLocStart(), InitEnd); + } + if (isExplicitSpecialization()) { + if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo()) + return SourceRange(getOuterLocStart(), Info->getRAngleLoc()); + } + return VarDecl::getSourceRange(); +} + + //===----------------------------------------------------------------------===// // VarTemplatePartialSpecializationDecl Implementation //===----------------------------------------------------------------------===// @@ -1447,6 +1462,20 @@ return new (C, ID) VarTemplatePartialSpecializationDecl(C); } +SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const { + if (const Expr *Init = getInit()) { + SourceLocation InitEnd = Init->getEndLoc(); + // If Init is implicit, ignore its source range + if (InitEnd.isValid() && InitEnd != getLocation()) + return SourceRange(getOuterLocStart(), InitEnd); + } + if (isExplicitSpecialization()) { + if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten()) + return SourceRange(getOuterLocStart(), Info->getRAngleLoc()); + } + return VarDecl::getSourceRange(); +} + static TemplateParameterList * createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) { // typename T