Deleted Added
sdiff udiff text old ( 195099 ) new ( 195341 )
full compact
1//===------- SemaTemplate.cpp - Semantic Analysis for C++ Templates -------===/
2
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//===----------------------------------------------------------------------===/

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

847 }
848
849 // Check that the template argument list is well-formed for this
850 // template.
851 TemplateArgumentListBuilder Converted(Template->getTemplateParameters(),
852 NumTemplateArgs);
853 if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc,
854 TemplateArgs, NumTemplateArgs, RAngleLoc,
855 Converted))
856 return QualType();
857
858 assert((Converted.structuredSize() ==
859 Template->getTemplateParameters()->size()) &&
860 "Converted template argument list is too short!");
861
862 QualType CanonType;
863

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

928 TemplateArgsIn.release();
929
930 if (Result.isNull())
931 return true;
932
933 return Result.getAsOpaquePtr();
934}
935
936/// \brief Form a dependent template name.
937///
938/// This action forms a dependent template name given the template
939/// name and its (presumably dependent) scope specifier. For
940/// example, given "MetaFun::template apply", the scope specifier \p
941/// SS will be "MetaFun::", \p TemplateKWLoc contains the location
942/// of the "template" keyword, and "apply" is the \p Name.
943Sema::TemplateTy

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

1014/// \brief Check that the given template argument list is well-formed
1015/// for specializing the given template.
1016bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
1017 SourceLocation TemplateLoc,
1018 SourceLocation LAngleLoc,
1019 const TemplateArgument *TemplateArgs,
1020 unsigned NumTemplateArgs,
1021 SourceLocation RAngleLoc,
1022 TemplateArgumentListBuilder &Converted) {
1023 TemplateParameterList *Params = Template->getTemplateParameters();
1024 unsigned NumParams = Params->size();
1025 unsigned NumArgs = NumTemplateArgs;
1026 bool Invalid = false;
1027
1028 bool HasParameterPack =
1029 NumParams > 0 && Params->getParam(NumParams - 1)->isTemplateParameterPack();
1030
1031 if ((NumArgs > NumParams && !HasParameterPack) ||
1032 NumArgs < Params->getMinRequiredArguments()) {
1033 // FIXME: point at either the first arg beyond what we can handle,
1034 // or the '>', depending on whether we have too many or too few
1035 // arguments.
1036 SourceRange Range;
1037 if (NumArgs > NumParams)
1038 Range = SourceRange(TemplateArgs[NumParams].getLocation(), RAngleLoc);
1039 Diag(TemplateLoc, diag::err_template_arg_list_different_arity)
1040 << (NumArgs > NumParams)

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

1051 // [...] The type and form of each template-argument specified in
1052 // a template-id shall match the type and form specified for the
1053 // corresponding parameter declared by the template in its
1054 // template-parameter-list.
1055 unsigned ArgIdx = 0;
1056 for (TemplateParameterList::iterator Param = Params->begin(),
1057 ParamEnd = Params->end();
1058 Param != ParamEnd; ++Param, ++ArgIdx) {
1059 // Decode the template argument
1060 TemplateArgument Arg;
1061 if (ArgIdx >= NumArgs) {
1062 // Retrieve the default template argument from the template
1063 // parameter.
1064 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
1065 if (TTP->isParameterPack()) {
1066 // We have an empty argument pack.

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

2297 translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
2298
2299 // Check that the template argument list is well-formed for this
2300 // template.
2301 TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
2302 TemplateArgs.size());
2303 if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
2304 TemplateArgs.data(), TemplateArgs.size(),
2305 RAngleLoc, Converted))
2306 return true;
2307
2308 assert((Converted.structuredSize() ==
2309 ClassTemplate->getTemplateParameters()->size()) &&
2310 "Converted template argument list is too short!");
2311
2312 // Find the class template (partial) specialization declaration that
2313 // corresponds to these arguments.

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

2493
2494 // We may be starting the definition of this specialization.
2495 if (TK == TK_Definition)
2496 Specialization->startDefinition();
2497
2498 // Add the specialization into its lexical context, so that it can
2499 // be seen when iterating through the list of declarations in that
2500 // context. However, specializations are not found by name lookup.
2501 CurContext->addDecl(Context, Specialization);
2502 return DeclPtrTy::make(Specialization);
2503}
2504
2505Sema::DeclPtrTy
2506Sema::ActOnTemplateDeclarator(Scope *S,
2507 MultiTemplateParamsArg TemplateParameterLists,
2508 Declarator &D) {
2509 return HandleDeclarator(S, D, move(TemplateParameterLists), false);

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

2592 translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
2593
2594 // Check that the template argument list is well-formed for this
2595 // template.
2596 TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
2597 TemplateArgs.size());
2598 if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
2599 TemplateArgs.data(), TemplateArgs.size(),
2600 RAngleLoc, Converted))
2601 return true;
2602
2603 assert((Converted.structuredSize() ==
2604 ClassTemplate->getTemplateParameters()->size()) &&
2605 "Converted template argument list is too short!");
2606
2607 // Find the class template specialization declaration that
2608 // corresponds to these arguments.

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

2649 // use it for anything, since it is semantically irrelevant.
2650 Specialization
2651 = ClassTemplateSpecializationDecl::Create(Context,
2652 ClassTemplate->getDeclContext(),
2653 TemplateNameLoc,
2654 ClassTemplate,
2655 Converted, 0);
2656 Specialization->setLexicalDeclContext(CurContext);
2657 CurContext->addDecl(Context, Specialization);
2658 return DeclPtrTy::make(Specialization);
2659 }
2660
2661 // If we have already (implicitly) instantiated this
2662 // specialization, there is less work to do.
2663 if (PrevDecl->getSpecializationKind() == TSK_ImplicitInstantiation)
2664 SpecializationRequiresInstantiation = false;
2665

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

2698 Context.getTypeDeclType(Specialization));
2699 Specialization->setTypeAsWritten(WrittenTy);
2700 TemplateArgsIn.release();
2701
2702 // Add the explicit instantiation into its lexical context. However,
2703 // since explicit instantiations are never found by name lookup, we
2704 // just put it into the declaration context directly.
2705 Specialization->setLexicalDeclContext(CurContext);
2706 CurContext->addDecl(Context, Specialization);
2707
2708 // C++ [temp.explicit]p3:
2709 // A definition of a class template or class member template
2710 // shall be in scope at the point of the explicit instantiation of
2711 // the class template or class member template.
2712 //
2713 // This check comes when we actually try to perform the
2714 // instantiation.

--- 187 unchanged lines hidden ---