Fix for PR5710: make sure to put function template specializations into the
DeclContext, so they don't completely disappear from the AST.

I don't particularly like this fix, but I don't see any obviously better way
to deal with it, and I think it's pretty clearly an improvement; comments
welcome.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index f276faf..c557e61 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -741,6 +741,9 @@
   // from being visible?
   if (isa<ClassTemplateSpecializationDecl>(D))
     return;
+  if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+    if (FD->isFunctionTemplateSpecialization())
+      return;
 
   DeclContext *PrimaryContext = getPrimaryContext();
   if (PrimaryContext != this) {
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index bb3f869..472dc94 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -379,7 +379,9 @@
   // scope.
   if ((isa<FunctionTemplateDecl>(D) &&
        cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->isOutOfLine()) ||
-      (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isOutOfLine()) ||
+      (isa<FunctionDecl>(D) &&
+       (cast<FunctionDecl>(D)->isFunctionTemplateSpecialization() ||
+        cast<FunctionDecl>(D)->isOutOfLine())) ||
       (isa<VarDecl>(D) && cast<VarDecl>(D)->isOutOfLine()))
     return;
 
@@ -2023,9 +2025,7 @@
 
   // If this has an identifier and is not an invalid redeclaration or 
   // function template specialization, add it to the scope stack.
-  if (Name && !(Redeclaration && New->isInvalidDecl()) &&
-      !(isa<FunctionDecl>(New) && 
-        cast<FunctionDecl>(New)->isFunctionTemplateSpecialization()))
+  if (Name && !(Redeclaration && New->isInvalidDecl()))
     PushOnScopeChains(New, S);
 
   return DeclPtrTy::make(New);