[cfe-commits] r121491 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/instantiate-template-template-parm.cpp

Peter Collingbourne peter at pcc.me.uk
Fri Dec 10 09:08:54 PST 2010


Author: pcc
Date: Fri Dec 10 11:08:53 2010
New Revision: 121491

URL: http://llvm.org/viewvc/llvm-project?rev=121491&view=rev
Log:
Do not substitute template types if template has dependent context

We should not substitute template types if the template has a dependent
context because the template argument stack is not yet fully formed.
Instead, defer substitution until the template has a non-dependent
context (i.e. instantiation of an outer template).

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/instantiate-template-template-parm.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=121491&r1=121490&r2=121491&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Dec 10 11:08:53 2010
@@ -2110,9 +2110,12 @@
   // Check non-type template parameters.
   if (NonTypeTemplateParmDecl *NTTP =dyn_cast<NonTypeTemplateParmDecl>(Param)) {    
     // Do substitution on the type of the non-type template parameter
-    // with the template arguments we've seen thus far.
+    // with the template arguments we've seen thus far.  But if the
+    // template has a dependent context then we cannot substitute yet.
     QualType NTTPType = NTTP->getType();
-    if (NTTPType->isDependentType()) {
+    if (NTTPType->isDependentType() &&
+        !isa<TemplateTemplateParmDecl>(Template) &&
+        !Template->getDeclContext()->isDependentContext()) {
       // Do substitution on the type of the non-type template parameter.
       InstantiatingTemplate Inst(*this, TemplateLoc, Template,
                                  NTTP, Converted.data(), Converted.size(),

Modified: cfe/trunk/test/SemaTemplate/instantiate-template-template-parm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-template-template-parm.cpp?rev=121491&r1=121490&r2=121491&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-template-template-parm.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-template-template-parm.cpp Fri Dec 10 11:08:53 2010
@@ -44,3 +44,18 @@
 
 X2<int, X3i> x2okay;
 X2<long, X3l> x2bad; // expected-note{{instantiation}}
+
+template <typename T, template <T, T> class TT, class R = TT<1, 2> >
+struct Comp {
+  typedef R r1;
+  template <T x, T y> struct gt {
+    static const bool result = x > y;
+  };
+  typedef gt<2, 1> r2;
+};
+
+template <int x, int y> struct lt {
+  static const bool result = x < y;
+};
+
+Comp<int, lt> c0;





More information about the cfe-commits mailing list