From 542b548e041a6fab0fe06601ccc6b91a81bc217a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 14 Oct 2009 17:30:58 +0000 Subject: [PATCH] When mapping from an injected-class-name to its corresponding template, make sure to get the template that corresponds to *this* declaration of the class template or specialization, rather than the canonical specialization. Fixes PR5187. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84119 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplate.cpp | 2 +- test/SemaTemplate/default-arguments.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 4a410ecb14..d56b4e114e 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -45,7 +45,7 @@ static NamedDecl *isAcceptableTemplateName(ASTContext &Context, NamedDecl *D) { // which could be the current specialization or another // specialization. if (Record->isInjectedClassName()) { - Record = cast(Record->getCanonicalDecl()); + Record = cast(Record->getDeclContext()); if (Record->getDescribedClassTemplate()) return Record->getDescribedClassTemplate(); diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp index f9bb44ecb9..33677aab73 100644 --- a/test/SemaTemplate/default-arguments.cpp +++ b/test/SemaTemplate/default-arguments.cpp @@ -22,3 +22,23 @@ template::v> struct p { }; // expected-error {{no member na template struct p; // expected-note {{in instantiation of default argument for 'p' required here}} template struct p; + +// PR5187 +template +struct A; + +template +struct A; + +template +struct A { + void f(A); +}; + +template +struct B { }; + +template<> +struct B { + typedef B type; +};