Deleted Added
sdiff udiff text old ( 280031 ) new ( 283526 )
full compact
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.
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 Converted.push_back(Result);
3437 break;
3438 }
3439
3440 case TemplateArgument::Declaration:
3441 case TemplateArgument::Integral:
3442 case TemplateArgument::NullPtr:
3443 // We've already checked this template argument, so just copy

--- 191 unchanged lines hidden (view full) ---

3635
3636/// \brief Check that the given template argument list is well-formed
3637/// for specializing the given template.
3638bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
3639 SourceLocation TemplateLoc,
3640 TemplateArgumentListInfo &TemplateArgs,
3641 bool PartialTemplateArgs,
3642 SmallVectorImpl<TemplateArgument> &Converted) {
3643 TemplateParameterList *Params = Template->getTemplateParameters();
3644
3645 SourceLocation RAngleLoc = TemplateArgs.getRAngleLoc();
3646
3647 // C++ [temp.arg]p1:
3648 // [...] The type and form of each template-argument specified in
3649 // a template-id shall match the type and form specified for the
3650 // corresponding parameter declared by the template in its
3651 // template-parameter-list.
3652 bool isTemplateTemplateParameter = isa<TemplateTemplateParmDecl>(Template);
3653 SmallVector<TemplateArgument, 2> ArgumentPack;
3654 unsigned ArgIdx = 0, NumArgs = TemplateArgs.size();
3655 LocalInstantiationScope InstScope(*this, true);
3656 for (TemplateParameterList::iterator Param = Params->begin(),
3657 ParamEnd = Params->end();
3658 Param != ParamEnd; /* increment in loop */) {
3659 // If we have an expanded parameter pack, make sure we don't have too
3660 // many arguments.
3661 if (Optional<unsigned> Expansions = getExpandedPackSize(*Param)) {
3662 if (*Expansions == ArgumentPack.size()) {

--- 19 unchanged lines hidden (view full) ---

3682 Diag(Template->getLocation(), diag::note_template_decl_here)
3683 << Params->getSourceRange();
3684 return true;
3685 }
3686 }
3687
3688 if (ArgIdx < NumArgs) {
3689 // Check the template argument we were given.
3690 if (CheckTemplateArgument(*Param, TemplateArgs[ArgIdx], Template,
3691 TemplateLoc, RAngleLoc,
3692 ArgumentPack.size(), Converted))
3693 return true;
3694
3695 bool PackExpansionIntoNonPack =
3696 TemplateArgs[ArgIdx].getArgument().isPackExpansion() &&
3697 (!(*Param)->isTemplateParameterPack() || getExpandedPackSize(*Param));
3698 if (PackExpansionIntoNonPack && isa<TypeAliasTemplateDecl>(Template)) {
3699 // Core issue 1430: we have a pack expansion as an argument to an
3700 // alias template, and it's not part of a parameter pack. This
3701 // can't be canonicalized, so reject it now.
3702 Diag(TemplateArgs[ArgIdx].getLocation(),
3703 diag::err_alias_template_expansion_into_fixed_list)
3704 << TemplateArgs[ArgIdx].getSourceRange();
3705 Diag((*Param)->getLocation(), diag::note_template_param_here);
3706 return true;
3707 }
3708
3709 // We're now done with this argument.
3710 ++ArgIdx;
3711
3712 if ((*Param)->isTemplateParameterPack()) {

--- 15 unchanged lines hidden (view full) ---

3728 // If we were part way through filling in an expanded parameter pack,
3729 // fall back to just producing individual arguments.
3730 Converted.insert(Converted.end(),
3731 ArgumentPack.begin(), ArgumentPack.end());
3732 ArgumentPack.clear();
3733 }
3734
3735 while (ArgIdx < NumArgs) {
3736 Converted.push_back(TemplateArgs[ArgIdx].getArgument());
3737 ++ArgIdx;
3738 }
3739
3740 return false;
3741 }
3742
3743 continue;
3744 }

--- 34 unchanged lines hidden (view full) ---

3779
3780 // Retrieve the default template argument from the template
3781 // parameter. For each kind of template parameter, we substitute the
3782 // template arguments provided thus far and any "outer" template arguments
3783 // (when the template parameter was part of a nested template) into
3784 // the default argument.
3785 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
3786 if (!TTP->hasDefaultArgument())
3787 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3788 TemplateArgs);
3789
3790 TypeSourceInfo *ArgType = SubstDefaultTemplateArgument(*this,
3791 Template,
3792 TemplateLoc,
3793 RAngleLoc,
3794 TTP,
3795 Converted);
3796 if (!ArgType)
3797 return true;
3798
3799 Arg = TemplateArgumentLoc(TemplateArgument(ArgType->getType()),
3800 ArgType);
3801 } else if (NonTypeTemplateParmDecl *NTTP
3802 = dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
3803 if (!NTTP->hasDefaultArgument())
3804 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3805 TemplateArgs);
3806
3807 ExprResult E = SubstDefaultTemplateArgument(*this, Template,
3808 TemplateLoc,
3809 RAngleLoc,
3810 NTTP,
3811 Converted);
3812 if (E.isInvalid())
3813 return true;
3814
3815 Expr *Ex = E.getAs<Expr>();
3816 Arg = TemplateArgumentLoc(TemplateArgument(Ex), Ex);
3817 } else {
3818 TemplateTemplateParmDecl *TempParm
3819 = cast<TemplateTemplateParmDecl>(*Param);
3820
3821 if (!TempParm->hasDefaultArgument())
3822 return diagnoseArityMismatch(*this, Template, TemplateLoc,
3823 TemplateArgs);
3824
3825 NestedNameSpecifierLoc QualifierLoc;
3826 TemplateName Name = SubstDefaultTemplateArgument(*this, Template,
3827 TemplateLoc,
3828 RAngleLoc,
3829 TempParm,
3830 Converted,
3831 QualifierLoc);

--- 11 unchanged lines hidden (view full) ---

3843 if (Inst.isInvalid())
3844 return true;
3845
3846 // Check the default template argument.
3847 if (CheckTemplateArgument(*Param, Arg, Template, TemplateLoc,
3848 RAngleLoc, 0, Converted))
3849 return true;
3850
3851 // Core issue 150 (assumed resolution): if this is a template template
3852 // parameter, keep track of the default template arguments from the
3853 // template definition.
3854 if (isTemplateTemplateParameter)
3855 TemplateArgs.addArgument(Arg);
3856
3857 // Move to the next template parameter and argument.
3858 ++Param;
3859 ++ArgIdx;
3860 }
3861
3862 // If we're performing a partial argument substitution, allow any trailing
3863 // pack expansions; they might be empty. This can happen even if
3864 // PartialTemplateArgs is false (the list of arguments is complete but
3865 // still dependent).
3866 if (ArgIdx < NumArgs && CurrentInstantiationScope &&
3867 CurrentInstantiationScope->getPartiallySubstitutedPack()) {
3868 while (ArgIdx < NumArgs &&
3869 TemplateArgs[ArgIdx].getArgument().isPackExpansion())
3870 Converted.push_back(TemplateArgs[ArgIdx++].getArgument());
3871 }
3872
3873 // If we have any leftover arguments, then there were too many arguments.
3874 // Complain and fail.
3875 if (ArgIdx < NumArgs)
3876 return diagnoseArityMismatch(*this, Template, TemplateLoc, TemplateArgs);
3877
3878 return false;
3879}
3880
3881namespace {
3882 class UnnamedLocalNoLinkageFinder
3883 : public TypeVisitor<UnnamedLocalNoLinkageFinder, bool>
3884 {
3885 Sema &S;

--- 4415 unchanged lines hidden ---