From 0f6931a2c2cf7f19bab07ab752dfd632d8494205 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 2 Apr 2012 18:53:24 +0000 Subject: [PATCH] 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 --- lib/AST/StmtProfile.cpp | 8 ++++++++ test/SemaTemplate/canonical-expr-type-0x.cpp | 21 ++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index c999ed4526..e5526cea74 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -1083,6 +1083,14 @@ void StmtProfiler::VisitDecl(const Decl *D) { return; } + if (const TemplateTypeParmDecl *TTP = + dyn_cast(D)) { + ID.AddInteger(TTP->getDepth()); + ID.AddInteger(TTP->getIndex()); + ID.AddBoolean(TTP->isParameterPack()); + return; + } + if (const TemplateTemplateParmDecl *TTP = dyn_cast(D)) { ID.AddInteger(TTP->getDepth()); diff --git a/test/SemaTemplate/canonical-expr-type-0x.cpp b/test/SemaTemplate/canonical-expr-type-0x.cpp index 94ae360b43..d7379eadab 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 -void f0(T x, decltype(f(N)) y) { } // expected-note{{previous}} +void f0(T x, decltype(f(N, x)) y) { } // expected-note{{previous}} template -void f0(T x, decltype((f)(N)) y) { } +void f0(T x, decltype((f)(N, x)) y) { } template -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 struct N {}; + +template +N f1() {} // expected-note{{previous}} + +template +N f1() {} + +template +N f1() {} // expected-error{{redefinition}} -- 2.40.0