[cfe-commits] r127091 - in /cfe/trunk: lib/Sema/TreeTransform.h test/SemaTemplate/issue150.cpp

Douglas Gregor dgregor at apple.com
Sat Mar 5 09:19:27 PST 2011


Author: dgregor
Date: Sat Mar  5 11:19:27 2011
New Revision: 127091

URL: http://llvm.org/viewvc/llvm-project?rev=127091&view=rev
Log:
When transforming a substituted template type parameter, try to
transform the type that replaces the template type parameter. In the
vast majority of cases, there's nothing to do, because most template
type parameters are replaced with something non-dependent that doesn't
need further transformation. However, when we're dealing with the
default template arguments of template template parameters, we might
end up replacing a template parameter (of the template template
parameter) with a template parameter of the enclosing template. 
 
This addresses part of PR9016, but not within function
templates. That's a separate issue.


Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaTemplate/issue150.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=127091&r1=127090&r2=127091&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sat Mar  5 11:19:27 2011
@@ -4126,7 +4126,28 @@
 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
                                          TypeLocBuilder &TLB,
                                          SubstTemplateTypeParmTypeLoc TL) {
-  return TransformTypeSpecType(TLB, TL);
+  const SubstTemplateTypeParmType *T = TL.getTypePtr();
+  
+  // Substitute into the replacement type, which itself might involve something
+  // that needs to be transformed. This only tends to occur with default
+  // template arguments of template template parameters.
+  TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
+  QualType Replacement = getDerived().TransformType(T->getReplacementType());
+  if (Replacement.isNull())
+    return QualType();
+  
+  // Always canonicalize the replacement type.
+  Replacement = SemaRef.Context.getCanonicalType(Replacement);
+  QualType Result
+    = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 
+                                                   Replacement);
+  
+  // Propagate type-source information.
+  SubstTemplateTypeParmTypeLoc NewTL
+    = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
+  NewTL.setNameLoc(TL.getNameLoc());
+  return Result;
+
 }
 
 template<typename Derived>

Modified: cfe/trunk/test/SemaTemplate/issue150.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/issue150.cpp?rev=127091&r1=127090&r2=127091&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/issue150.cpp (original)
+++ cfe/trunk/test/SemaTemplate/issue150.cpp Sat Mar  5 11:19:27 2011
@@ -69,3 +69,29 @@
 
   int check0[is_same<X<int, int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1];
 }
+
+namespace PR9016 {
+  template<typename > struct allocator ;
+  template<typename > struct less ;
+
+  template<class T, template<class> class Compare, class Default,
+           template<class> class Alloc>
+  struct interval_set { };
+
+  template <class X, template<class> class = less> struct interval_type_default {
+    typedef X type;
+  };
+
+  template <class T,
+            template<class _T, template<class> class Compare = less,
+                     class = typename interval_type_default<_T,Compare>::type,
+                     template<class> class = allocator> class IntervalSet>
+  struct ZZZ
+  {
+    IntervalSet<T> IntervalSetT;
+  };
+  
+  void test() {
+    ZZZ<int, interval_set> zzz;
+  }
+}





More information about the cfe-commits mailing list