Devirtualize NamedDecl::getNameForDiagnostic().


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125751 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 441444d..0b07d13 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -601,6 +601,30 @@
   }
 }
 
+void NamedDecl::getNameForDiagnostic(std::string &S,
+                                     const PrintingPolicy &Policy,
+                                     bool Qualified) const {
+  if (Qualified)
+    S += getQualifiedNameAsString(Policy);
+  else
+    S += getNameAsString();
+
+  const TemplateArgumentList *TemplateArgs = 0;
+
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
+    TemplateArgs = FD->getTemplateSpecializationArgs();
+  else if (const ClassTemplateSpecializationDecl *Spec
+                              = dyn_cast<ClassTemplateSpecializationDecl>(this))
+    TemplateArgs = &Spec->getTemplateArgs();
+  
+  
+   if (TemplateArgs)
+     S += TemplateSpecializationType::PrintTemplateArgumentList(
+                                                          TemplateArgs->data(),
+                                                          TemplateArgs->size(),
+                                                          Policy);
+}
+
 void NamedDecl::ClearLinkageCache() {
   // Note that we can't skip clearing the linkage of children just
   // because the parent doesn't have cached linkage:  we don't cache
@@ -1283,19 +1307,6 @@
 // FunctionDecl Implementation
 //===----------------------------------------------------------------------===//
 
-void FunctionDecl::getNameForDiagnostic(std::string &S,
-                                        const PrintingPolicy &Policy,
-                                        bool Qualified) const {
-  NamedDecl::getNameForDiagnostic(S, Policy, Qualified);
-  const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs();
-  if (TemplateArgs)
-    S += TemplateSpecializationType::PrintTemplateArgumentList(
-                                                         TemplateArgs->data(),
-                                                         TemplateArgs->size(),
-                                                               Policy);
-    
-}
-
 bool FunctionDecl::isVariadic() const {
   if (const FunctionProtoType *FT = getType()->getAs<FunctionProtoType>())
     return FT->isVariadic();