From 09d8212989c64abad4b745f37f56ca77b44de537 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Mon, 3 Oct 2011 20:34:03 +0000 Subject: [PATCH] Fixed source range for template implicit instantiations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141018 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclTemplate.cpp | 30 +++++++++++++++++++--------- lib/Sema/SemaTemplate.cpp | 2 +- lib/Sema/SemaTemplateInstantiate.cpp | 3 +++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/AST/DeclTemplate.cpp b/lib/AST/DeclTemplate.cpp index 078869cec4..558a4ccac9 100644 --- a/lib/AST/DeclTemplate.cpp +++ b/lib/AST/DeclTemplate.cpp @@ -656,15 +656,27 @@ ClassTemplateSpecializationDecl::getSpecializedTemplate() const { SourceRange ClassTemplateSpecializationDecl::getSourceRange() const { - if (!ExplicitInfo) - return SourceRange(); - SourceLocation Begin = getExternLoc(); - if (Begin.isInvalid()) - Begin = getTemplateKeywordLoc(); - SourceLocation End = getRBraceLoc(); - if (End.isInvalid()) - End = getTypeAsWritten()->getTypeLoc().getEndLoc(); - return SourceRange(Begin, End); + if (ExplicitInfo) { + SourceLocation Begin = getExternLoc(); + if (Begin.isInvalid()) + Begin = getTemplateKeywordLoc(); + SourceLocation End = getRBraceLoc(); + if (End.isInvalid()) + End = getTypeAsWritten()->getTypeLoc().getEndLoc(); + return SourceRange(Begin, End); + } + else { + // No explicit info available. + llvm::PointerUnion + inst_from = getInstantiatedFrom(); + if (inst_from.isNull()) + return getSpecializedTemplate()->getSourceRange(); + if (ClassTemplateDecl *ctd = inst_from.dyn_cast()) + return ctd->getSourceRange(); + return inst_from.get() + ->getSourceRange(); + } } //===----------------------------------------------------------------------===// diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 06f783d58c..c8cf6c4c2c 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2007,7 +2007,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, Decl = ClassTemplateSpecializationDecl::Create(Context, ClassTemplate->getTemplatedDecl()->getTagKind(), ClassTemplate->getDeclContext(), - ClassTemplate->getLocation(), + ClassTemplate->getTemplatedDecl()->getLocStart(), ClassTemplate->getLocation(), ClassTemplate, Converted.data(), diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 42a654a0ee..301bf6a112 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1818,6 +1818,9 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, if (!FieldsWithMemberInitializers.empty()) ActOnFinishDelayedMemberInitializers(Instantiation); + if (TSK == TSK_ImplicitInstantiation) + Instantiation->setRBraceLoc(Pattern->getRBraceLoc()); + if (Instantiation->isInvalidDecl()) Invalid = true; else { -- 2.40.0