PR12569: Instantiate exception specifications of explicit instantiations
and explicit specializations of function templates appropriately.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154956 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 39c27fc..4d312f8 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2377,7 +2377,16 @@
 
 void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
                                     FunctionDecl *Decl) {
-  FunctionDecl *Tmpl = Decl->getTemplateInstantiationPattern();
+  // Find the template declaration which contains the exception specification.
+  // Per [except.spec]p4, prefer the exception spec on the primary template
+  // if this is an explicit instantiation.
+  FunctionDecl *Tmpl = 0;
+  if (Decl->getPrimaryTemplate())
+    Tmpl = Decl->getPrimaryTemplate()->getTemplatedDecl();
+  else if (FunctionDecl *MemTmpl = Decl->getInstantiatedFromMemberFunction())
+    Tmpl = MemTmpl;
+  else
+    Tmpl = Decl->getTemplateInstantiationPattern();
   assert(Tmpl && "can't instantiate non-template");
 
   if (Decl->getType()->castAs<FunctionProtoType>()->getExceptionSpecType()