From b1ce9297371b65b3726c09e85aed9781f70bca14 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 22 Jun 2013 22:03:31 +0000 Subject: [PATCH] Fix assert if an attempt is made to explicitly instantiate an alias template. Patch by Ismail Pazarbasi! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184650 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplate.cpp | 14 +++++++++++--- test/SemaCXX/using-decl-templates.cpp | 9 ++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 7ad3131627..88b24a1702 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -6341,14 +6341,22 @@ Sema::ActOnExplicitInstantiation(Scope *S, AttributeList *Attr) { // Find the class template we're specializing TemplateName Name = TemplateD.getAsVal(); - ClassTemplateDecl *ClassTemplate - = cast(Name.getAsTemplateDecl()); - + TemplateDecl *TD = Name.getAsTemplateDecl(); // Check that the specialization uses the same tag kind as the // original template. TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForTypeSpec(TagSpec); assert(Kind != TTK_Enum && "Invalid enum tag in class template explicit instantiation!"); + + if (isa(TD)) { + Diag(KWLoc, diag::err_tag_reference_non_tag) << Kind; + Diag(TD->getTemplatedDecl()->getLocation(), + diag::note_previous_use); + return true; + } + + ClassTemplateDecl *ClassTemplate = cast(TD); + if (!isAcceptableTagRedeclaration(ClassTemplate->getTemplatedDecl(), Kind, /*isDefinition*/false, KWLoc, *ClassTemplate->getIdentifier())) { diff --git a/test/SemaCXX/using-decl-templates.cpp b/test/SemaCXX/using-decl-templates.cpp index 2fc6795642..8314688bcb 100644 --- a/test/SemaCXX/using-decl-templates.cpp +++ b/test/SemaCXX/using-decl-templates.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s template struct A { void f() { } @@ -85,3 +85,10 @@ template class UsingTypenameNNS { using typename T::X; typename X::X x; }; + +namespace aliastemplateinst { + template struct A { }; + template using APtr = A; // expected-note{{previous use is here}} + + template struct APtr; // expected-error{{elaborated type refers to a non-tag type}} +} -- 2.40.0