diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-01-09 02:22:22 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-01-09 02:22:22 +0000 |
commit | 4e8e2e809406fa7e1b4f6d04d16b85f0f0952374 (patch) | |
tree | e35a3d219439d9e9020294c8f83415641ea9e4fa /lib/Sema/SemaTemplate.cpp | |
parent | cdb7256298771af460cb02d4200561ffdfaa1df0 (diff) |
PR18401: Fix assert by implementing the current proposed direction of core
issue 1430. Don't allow a pack expansion to be used as an argument to an alias
template unless the corresponding parameter is a parameter pack.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198833 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index b468e31f09..97137184c2 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -1975,17 +1975,15 @@ QualType Sema::CheckTemplateIdType(TemplateName Name, // Check that the template argument list is well-formed for this // template. SmallVector<TemplateArgument, 4> Converted; - bool ExpansionIntoFixedList = false; if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs, - false, Converted, &ExpansionIntoFixedList)) + false, Converted)) return QualType(); QualType CanonType; bool InstantiationDependent = false; - TypeAliasTemplateDecl *AliasTemplate = 0; - if (!ExpansionIntoFixedList && - (AliasTemplate = dyn_cast<TypeAliasTemplateDecl>(Template))) { + if (TypeAliasTemplateDecl *AliasTemplate = + dyn_cast<TypeAliasTemplateDecl>(Template)) { // Find the canonical type for this type alias template specialization. TypeAliasDecl *Pattern = AliasTemplate->getTemplatedDecl(); if (Pattern->isInvalidDecl()) @@ -2590,11 +2588,10 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc, // Check that the template argument list is well-formed for this template. SmallVector<TemplateArgument, 4> Converted; - bool ExpansionIntoFixedList = false; if (CheckTemplateArgumentList( Template, TemplateNameLoc, const_cast<TemplateArgumentListInfo &>(TemplateArgs), false, - Converted, &ExpansionIntoFixedList)) + Converted)) return true; // Find the variable template specialization declaration that @@ -3549,11 +3546,7 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, - SmallVectorImpl<TemplateArgument> &Converted, - bool *ExpansionIntoFixedList) { - if (ExpansionIntoFixedList) - *ExpansionIntoFixedList = false; - + SmallVectorImpl<TemplateArgument> &Converted) { TemplateParameterList *Params = Template->getTemplateParameters(); SourceLocation RAngleLoc = TemplateArgs.getRAngleLoc(); @@ -3606,6 +3599,20 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, ArgumentPack.size(), Converted)) return true; + if (TemplateArgs[ArgIdx].getArgument().isPackExpansion() && + isa<TypeAliasTemplateDecl>(Template) && + !(Param + 1 == ParamEnd && (*Param)->isTemplateParameterPack() && + !getExpandedPackSize(*Param))) { + // Core issue 1430: we have a pack expansion as an argument to an + // alias template, and it's not part of a final parameter pack. This + // can't be canonicalized, so reject it now. + Diag(TemplateArgs[ArgIdx].getLocation(), + diag::err_alias_template_expansion_into_fixed_list) + << TemplateArgs[ArgIdx].getSourceRange(); + Diag((*Param)->getLocation(), diag::note_template_param_here); + return true; + } + // We're now done with this argument. ++ArgIdx; @@ -3652,9 +3659,6 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, ArgumentPack.data(), ArgumentPack.size())); ArgumentPack.clear(); - } else if (ExpansionIntoFixedList) { - // We have expanded a pack into a fixed list. - *ExpansionIntoFixedList = true; } return false; |