]> granicus.if.org Git - clang/commitdiff
Fixed source range for template implicit instantiations.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 3 Oct 2011 20:34:03 +0000 (20:34 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 3 Oct 2011 20:34:03 +0000 (20:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141018 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclTemplate.cpp
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateInstantiate.cpp

index 078869cec43739ce11ecba50dd7422babf65bfb2..558a4ccac96b7ac9480c13f4c4e2d0784b534f13 100644 (file)
@@ -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<ClassTemplateDecl *,
+                       ClassTemplatePartialSpecializationDecl *>
+      inst_from = getInstantiatedFrom();
+    if (inst_from.isNull())
+      return getSpecializedTemplate()->getSourceRange();
+    if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
+      return ctd->getSourceRange();
+    return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
+      ->getSourceRange();
+  }
 }
 
 //===----------------------------------------------------------------------===//
index 06f783d58cf9ebaa97146b5d37eb4d4745eb8783..c8cf6c4c2c91aca954ad68423c877fdef81ce03e 100644 (file)
@@ -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(),
index 42a654a0ee8e0440db32938278ce0f04334a1616..301bf6a1126072f12f29cb2dbdda522433c40f0a 100644 (file)
@@ -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 {