Egregious, disgusting workaround for PR5866. We need to rework how we
keep track of friends within templates, which will provide a real for
PR5866. For now, this makes sure we don't do something entirely stupid
with friends of specializations.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92143 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 2e4ee63..b70b0dc 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -5380,6 +5380,9 @@
   FrD->setAccess(AS_public);
   CurContext->addDecl(FrD);
 
+  if (D.getName().getKind() == UnqualifiedId::IK_TemplateId)
+    FrD->setSpecialization(true);
+
   return DeclPtrTy::make(ND);
 }
 
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 18a7325..1ec91bd 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -401,7 +401,10 @@
     // Hack to make this work almost well pending a rewrite.
     if (ND->getDeclContext()->isRecord())
       NewND = SemaRef.FindInstantiatedDecl(ND, TemplateArgs);
-    else
+    else if (D->wasSpecialization()) {
+      // Totally egregious hack to work around PR5866
+      return 0;
+    } else
       NewND = Visit(ND);
     if (!NewND) return 0;
 
@@ -687,7 +690,7 @@
 ///   1) instantiating function templates
 ///   2) substituting friend declarations
 /// FIXME: preserve function definitions in case #2
-  Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
+Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
                                        TemplateParameterList *TemplateParams) {
   // Check whether there is already a function template specialization for
   // this declaration.