Preserve type-source information in friend declarations.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99525 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index de6fff7..cbd9086 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -480,13 +480,17 @@
 
   // Handle friend type expressions by simply substituting template
   // parameters into the pattern type.
-  if (Type *Ty = D->getFriendType()) {
-    QualType T = SemaRef.SubstType(QualType(Ty,0), TemplateArgs,
-                                   D->getLocation(), DeclarationName());
-    if (T.isNull()) return 0;
+  if (TypeSourceInfo *Ty = D->getFriendType()) {
+    TypeSourceInfo *InstTy = 
+      SemaRef.SubstType(Ty, TemplateArgs,
+                        D->getLocation(), DeclarationName());
+    if (!InstTy) return 0;
 
-    assert(getLangOptions().CPlusPlus0x || T->isRecordType());
-    FU = T.getTypePtr();
+    // This assertion is valid because the source type was necessarily
+    // an elaborated-type-specifier with a record tag.
+    assert(getLangOptions().CPlusPlus0x || InstTy->getType()->isRecordType());
+
+    FU = InstTy;
 
   // Handle everything else by appropriate substitution.
   } else {