Fix template parameter default args missed if redecled
authorErich Keane <erich.keane@intel.com>
Tue, 24 Oct 2017 01:39:56 +0000 (01:39 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 24 Oct 2017 01:39:56 +0000 (01:39 +0000)
This bug was found via self-build on lld, and worked around
here: https://reviews.llvm.org/rL316180

The issue is that the 'using' causes the lookup to pick up the
first decl. However, when setting inherited default parameters,
we only update 'forward', not 'backward'. SO, only the newest param
list has all the information about the default arguments.

This patch ensures that the list of parameters we look through checks
the newest decl's template parameter list so it doesn't miss a default.

Differential Revision: https://reviews.llvm.org/D39127

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316405 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplate.cpp

index 0930fdd653b9078b489f9b43d7c68e95efceb2fb..26b80f11fb486c6c12859aec0202c9c62ad45a0e 100644 (file)
@@ -4805,7 +4805,12 @@ bool Sema::CheckTemplateArgumentList(
   // template.
   TemplateArgumentListInfo NewArgs = TemplateArgs;
 
-  TemplateParameterList *Params = Template->getTemplateParameters();
+  // Make sure we get the template parameter list from the most
+  // recentdeclaration, since that is the only one that has is guaranteed to
+  // have all the default template argument information.
+  TemplateParameterList *Params =
+      cast<TemplateDecl>(Template->getMostRecentDecl())
+          ->getTemplateParameters();
 
   SourceLocation RAngleLoc = NewArgs.getRAngleLoc();