PR12438: Profile a reference to a type template parameter by depth and index,
not by canonical decl. This only matters for sizeof...(Pack) expressions; in
all other cases, we'd profile it as a type instead.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153884 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp
index c999ed4..e5526ce 100644
--- a/lib/AST/StmtProfile.cpp
+++ b/lib/AST/StmtProfile.cpp
@@ -1083,6 +1083,14 @@
       return;
     }
 
+    if (const TemplateTypeParmDecl *TTP =
+          dyn_cast<TemplateTypeParmDecl>(D)) {
+      ID.AddInteger(TTP->getDepth());
+      ID.AddInteger(TTP->getIndex());
+      ID.AddBoolean(TTP->isParameterPack());
+      return;
+    }
+
     if (const TemplateTemplateParmDecl *TTP =
           dyn_cast<TemplateTemplateParmDecl>(D)) {
       ID.AddInteger(TTP->getDepth());
diff --git a/test/SemaTemplate/canonical-expr-type-0x.cpp b/test/SemaTemplate/canonical-expr-type-0x.cpp
index 94ae360..d7379ea 100644
--- a/test/SemaTemplate/canonical-expr-type-0x.cpp
+++ b/test/SemaTemplate/canonical-expr-type-0x.cpp
@@ -2,15 +2,24 @@
 
 void f();
 
-// FIXME: would like to refer to the first function parameter in these test,
-// but that won't work (yet).
-
 // Test typeof(expr) canonicalization
 template<typename T, T N>
-void f0(T x, decltype(f(N)) y) { } // expected-note{{previous}}
+void f0(T x, decltype(f(N, x)) y) { } // expected-note{{previous}}
 
 template<typename T, T N>
-void f0(T x, decltype((f)(N)) y) { }
+void f0(T x, decltype((f)(N, x)) y) { }
 
 template<typename U, U M>
-void f0(U u, decltype(f(M))) { } // expected-error{{redefinition}}
+void f0(U u, decltype(f(M, u))) { } // expected-error{{redefinition}}
+
+// PR12438: Test sizeof...() canonicalization
+template<int> struct N {};
+
+template<typename...T>
+N<sizeof...(T)> f1() {} // expected-note{{previous}}
+
+template<typename, typename...T>
+N<sizeof...(T)> f1() {}
+
+template<class...U>
+N<sizeof...(U)> f1() {} // expected-error{{redefinition}}