1//===------- SemaTemplate.cpp - Semantic Analysis for C++ Templates -------===/ 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7//===----------------------------------------------------------------------===/ 8// --- 3341 unchanged lines hidden (view full) --- 3350} 3351 3352/// \brief Check that the given template argument corresponds to the given 3353/// template parameter. 3354/// 3355/// \param Param The template parameter against which the argument will be 3356/// checked. 3357/// |
3358/// \param Arg The template argument, which may be updated due to conversions. |
3359/// 3360/// \param Template The template in which the template argument resides. 3361/// 3362/// \param TemplateLoc The location of the template name for the template 3363/// whose argument list we're matching. 3364/// 3365/// \param RAngleLoc The location of the right angle bracket ('>') that closes 3366/// the template argument list. --- 61 unchanged lines hidden (view full) --- 3428 case TemplateArgument::Expression: { 3429 TemplateArgument Result; 3430 ExprResult Res = 3431 CheckTemplateArgument(NTTP, NTTPType, Arg.getArgument().getAsExpr(), 3432 Result, CTAK); 3433 if (Res.isInvalid()) 3434 return true; 3435 |
3436 // If the resulting expression is new, then use it in place of the 3437 // old expression in the template argument. 3438 if (Res.get() != Arg.getArgument().getAsExpr()) { 3439 TemplateArgument TA(Res.get()); 3440 Arg = TemplateArgumentLoc(TA, Res.get()); 3441 } 3442 |
3443 Converted.push_back(Result); 3444 break; 3445 } 3446 3447 case TemplateArgument::Declaration: 3448 case TemplateArgument::Integral: 3449 case TemplateArgument::NullPtr: 3450 // We've already checked this template argument, so just copy --- 191 unchanged lines hidden (view full) --- 3642 3643/// \brief Check that the given template argument list is well-formed 3644/// for specializing the given template. 3645bool Sema::CheckTemplateArgumentList(TemplateDecl *Template, 3646 SourceLocation TemplateLoc, 3647 TemplateArgumentListInfo &TemplateArgs, 3648 bool PartialTemplateArgs, 3649 SmallVectorImpl<TemplateArgument> &Converted) { |
3650 // Make a copy of the template arguments for processing. Only make the 3651 // changes at the end when successful in matching the arguments to the 3652 // template. 3653 TemplateArgumentListInfo NewArgs = TemplateArgs; 3654 |
3655 TemplateParameterList *Params = Template->getTemplateParameters(); 3656 |
3657 SourceLocation RAngleLoc = NewArgs.getRAngleLoc(); |
3658 3659 // C++ [temp.arg]p1: 3660 // [...] The type and form of each template-argument specified in 3661 // a template-id shall match the type and form specified for the 3662 // corresponding parameter declared by the template in its 3663 // template-parameter-list. 3664 bool isTemplateTemplateParameter = isa<TemplateTemplateParmDecl>(Template); 3665 SmallVector<TemplateArgument, 2> ArgumentPack; |
3666 unsigned ArgIdx = 0, NumArgs = NewArgs.size(); |
3667 LocalInstantiationScope InstScope(*this, true); 3668 for (TemplateParameterList::iterator Param = Params->begin(), 3669 ParamEnd = Params->end(); 3670 Param != ParamEnd; /* increment in loop */) { 3671 // If we have an expanded parameter pack, make sure we don't have too 3672 // many arguments. 3673 if (Optional<unsigned> Expansions = getExpandedPackSize(*Param)) { 3674 if (*Expansions == ArgumentPack.size()) { --- 19 unchanged lines hidden (view full) --- 3694 Diag(Template->getLocation(), diag::note_template_decl_here) 3695 << Params->getSourceRange(); 3696 return true; 3697 } 3698 } 3699 3700 if (ArgIdx < NumArgs) { 3701 // Check the template argument we were given. |
3702 if (CheckTemplateArgument(*Param, NewArgs[ArgIdx], Template, |
3703 TemplateLoc, RAngleLoc, 3704 ArgumentPack.size(), Converted)) 3705 return true; 3706 3707 bool PackExpansionIntoNonPack = |
3708 NewArgs[ArgIdx].getArgument().isPackExpansion() && |
3709 (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param)); 3710 if (PackExpansionIntoNonPack && isa<TypeAliasTemplateDecl>(Template)) { 3711 // Core issue 1430: we have a pack expansion as an argument to an 3712 // alias template, and it's not part of a parameter pack. This 3713 // can't be canonicalized, so reject it now. |
3714 Diag(NewArgs[ArgIdx].getLocation(), |
3715 diag::err_alias_template_expansion_into_fixed_list) |
3716 << NewArgs[ArgIdx].getSourceRange(); |
3717 Diag((*Param)->getLocation(), diag::note_template_param_here); 3718 return true; 3719 } 3720 3721 // We're now done with this argument. 3722 ++ArgIdx; 3723 3724 if ((*Param)->isTemplateParameterPack()) { --- 15 unchanged lines hidden (view full) --- 3740 // If we were part way through filling in an expanded parameter pack, 3741 // fall back to just producing individual arguments. 3742 Converted.insert(Converted.end(), 3743 ArgumentPack.begin(), ArgumentPack.end()); 3744 ArgumentPack.clear(); 3745 } 3746 3747 while (ArgIdx < NumArgs) { |
3748 Converted.push_back(NewArgs[ArgIdx].getArgument()); |
3749 ++ArgIdx; 3750 } 3751 3752 return false; 3753 } 3754 3755 continue; 3756 } --- 34 unchanged lines hidden (view full) --- 3791 3792 // Retrieve the default template argument from the template 3793 // parameter. For each kind of template parameter, we substitute the 3794 // template arguments provided thus far and any "outer" template arguments 3795 // (when the template parameter was part of a nested template) into 3796 // the default argument. 3797 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) { 3798 if (!TTP->hasDefaultArgument()) |
3799 return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); |
3800 3801 TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(*this, 3802 Template, 3803 TemplateLoc, 3804 RAngleLoc, 3805 TTP, 3806 Converted); 3807 if (!ArgType) 3808 return true; 3809 3810 Arg = TemplateArgumentLoc(TemplateArgument(ArgType->getType()), 3811 ArgType); 3812 } else if (NonTypeTemplateParmDecl *NTTP 3813 = dyn_cast<NonTypeTemplateParmDecl>(*Param)) { 3814 if (!NTTP->hasDefaultArgument()) |
3815 return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); |
3816 3817 ExprResult E = SubstDefaultTemplateArgument(*this, Template, 3818 TemplateLoc, 3819 RAngleLoc, 3820 NTTP, 3821 Converted); 3822 if (E.isInvalid()) 3823 return true; 3824 3825 Expr *Ex = E.getAs<Expr>(); 3826 Arg = TemplateArgumentLoc(TemplateArgument(Ex), Ex); 3827 } else { 3828 TemplateTemplateParmDecl *TempParm 3829 = cast<TemplateTemplateParmDecl>(*Param); 3830 3831 if (!TempParm->hasDefaultArgument()) |
3832 return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); |
3833 3834 NestedNameSpecifierLoc QualifierLoc; 3835 TemplateName Name = SubstDefaultTemplateArgument(*this, Template, 3836 TemplateLoc, 3837 RAngleLoc, 3838 TempParm, 3839 Converted, 3840 QualifierLoc); --- 11 unchanged lines hidden (view full) --- 3852 if (Inst.isInvalid()) 3853 return true; 3854 3855 // Check the default template argument. 3856 if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc, 3857 RAngleLoc, 0, Converted)) 3858 return true; 3859 |
3860 // Core issue 150 (assumed resolution): if this is a template template 3861 // parameter, keep track of the default template arguments from the |
3862 // template definition. 3863 if (isTemplateTemplateParameter) |
3864 NewArgs.addArgument(Arg); 3865 |
3866 // Move to the next template parameter and argument. 3867 ++Param; 3868 ++ArgIdx; 3869 } 3870 3871 // If we're performing a partial argument substitution, allow any trailing 3872 // pack expansions; they might be empty. This can happen even if 3873 // PartialTemplateArgs is false (the list of arguments is complete but 3874 // still dependent). 3875 if (ArgIdx < NumArgs && CurrentInstantiationScope && 3876 CurrentInstantiationScope->getPartiallySubstitutedPack()) { |
3877 while (ArgIdx < NumArgs && NewArgs[ArgIdx].getArgument().isPackExpansion()) 3878 Converted.push_back(NewArgs[ArgIdx++].getArgument()); |
3879 } 3880 3881 // If we have any leftover arguments, then there were too many arguments. 3882 // Complain and fail. 3883 if (ArgIdx < NumArgs) |
3884 return diagnoseArityMismatch(*this, Template, TemplateLoc, NewArgs); |
3885 |
3886 // No problems found with the new argument list, propagate changes back 3887 // to caller. 3888 TemplateArgs = NewArgs; 3889 |
3890 return false; 3891} 3892 3893namespace { 3894 class UnnamedLocalNoLinkageFinder 3895 : public TypeVisitor<UnnamedLocalNoLinkageFinder, bool> 3896 { 3897 Sema &S; --- 4415 unchanged lines hidden --- |