Deleted Added
full compact
SemaTemplate.cpp (195099) SemaTemplate.cpp (195341)
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,
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))
855 false, 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
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
936Sema::OwningExprResult Sema::BuildTemplateIdExpr(TemplateName Template,
937 SourceLocation TemplateNameLoc,
938 SourceLocation LAngleLoc,
939 const TemplateArgument *TemplateArgs,
940 unsigned NumTemplateArgs,
941 SourceLocation RAngleLoc) {
942 // FIXME: Can we do any checking at this point? I guess we could check the
943 // template arguments that we have against the template name, if the template
944 // name refers to a single template. That's not a terribly common case,
945 // though.
946 return Owned(TemplateIdRefExpr::Create(Context,
947 /*FIXME: New type?*/Context.OverloadTy,
948 /*FIXME: Necessary?*/0,
949 /*FIXME: Necessary?*/SourceRange(),
950 Template, TemplateNameLoc, LAngleLoc,
951 TemplateArgs,
952 NumTemplateArgs, RAngleLoc));
953}
954
955Sema::OwningExprResult Sema::ActOnTemplateIdExpr(TemplateTy TemplateD,
956 SourceLocation TemplateNameLoc,
957 SourceLocation LAngleLoc,
958 ASTTemplateArgsPtr TemplateArgsIn,
959 SourceLocation *TemplateArgLocs,
960 SourceLocation RAngleLoc) {
961 TemplateName Template = TemplateD.getAsVal<TemplateName>();
962
963 // Translate the parser's template argument list in our AST format.
964 llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
965 translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
966
967 return BuildTemplateIdExpr(Template, TemplateNameLoc, LAngleLoc,
968 TemplateArgs.data(), TemplateArgs.size(),
969 RAngleLoc);
970}
971
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,
972/// \brief Form a dependent template name.
973///
974/// This action forms a dependent template name given the template
975/// name and its (presumably dependent) scope specifier. For
976/// example, given "MetaFun::template apply", the scope specifier \p
977/// SS will be "MetaFun::", \p TemplateKWLoc contains the location
978/// of the "template" keyword, and "apply" is the \p Name.
979Sema::TemplateTy

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

1050/// \brief Check that the given template argument list is well-formed
1051/// for specializing the given template.
1052bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
1053 SourceLocation TemplateLoc,
1054 SourceLocation LAngleLoc,
1055 const TemplateArgument *TemplateArgs,
1056 unsigned NumTemplateArgs,
1057 SourceLocation RAngleLoc,
1058 bool PartialTemplateArgs,
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) ||
1059 TemplateArgumentListBuilder &Converted) {
1060 TemplateParameterList *Params = Template->getTemplateParameters();
1061 unsigned NumParams = Params->size();
1062 unsigned NumArgs = NumTemplateArgs;
1063 bool Invalid = false;
1064
1065 bool HasParameterPack =
1066 NumParams > 0 && Params->getParam(NumParams - 1)->isTemplateParameterPack();
1067
1068 if ((NumArgs > NumParams && !HasParameterPack) ||
1032 NumArgs < Params->getMinRequiredArguments()) {
1069 (NumArgs < Params->getMinRequiredArguments() &&
1070 !PartialTemplateArgs)) {
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) {
1071 // FIXME: point at either the first arg beyond what we can handle,
1072 // or the '>', depending on whether we have too many or too few
1073 // arguments.
1074 SourceRange Range;
1075 if (NumArgs > NumParams)
1076 Range = SourceRange(TemplateArgs[NumParams].getLocation(), RAngleLoc);
1077 Diag(TemplateLoc, diag::err_template_arg_list_different_arity)
1078 << (NumArgs > NumParams)

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

1089 // [...] The type and form of each template-argument specified in
1090 // a template-id shall match the type and form specified for the
1091 // corresponding parameter declared by the template in its
1092 // template-parameter-list.
1093 unsigned ArgIdx = 0;
1094 for (TemplateParameterList::iterator Param = Params->begin(),
1095 ParamEnd = Params->end();
1096 Param != ParamEnd; ++Param, ++ArgIdx) {
1097 if (ArgIdx > NumArgs && PartialTemplateArgs)
1098 break;
1099
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(),
1100 // Decode the template argument
1101 TemplateArgument Arg;
1102 if (ArgIdx >= NumArgs) {
1103 // Retrieve the default template argument from the template
1104 // parameter.
1105 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
1106 if (TTP->isParameterPack()) {
1107 // We have an empty argument pack.

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

2338 translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
2339
2340 // Check that the template argument list is well-formed for this
2341 // template.
2342 TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
2343 TemplateArgs.size());
2344 if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
2345 TemplateArgs.data(), TemplateArgs.size(),
2305 RAngleLoc, Converted))
2346 RAngleLoc, false, 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.
2347 return true;
2348
2349 assert((Converted.structuredSize() ==
2350 ClassTemplate->getTemplateParameters()->size()) &&
2351 "Converted template argument list is too short!");
2352
2353 // Find the class template (partial) specialization declaration that
2354 // corresponds to these arguments.

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

2534
2535 // We may be starting the definition of this specialization.
2536 if (TK == TK_Definition)
2537 Specialization->startDefinition();
2538
2539 // Add the specialization into its lexical context, so that it can
2540 // be seen when iterating through the list of declarations in that
2541 // context. However, specializations are not found by name lookup.
2501 CurContext->addDecl(Context, Specialization);
2542 CurContext->addDecl(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(),
2543 return DeclPtrTy::make(Specialization);
2544}
2545
2546Sema::DeclPtrTy
2547Sema::ActOnTemplateDeclarator(Scope *S,
2548 MultiTemplateParamsArg TemplateParameterLists,
2549 Declarator &D) {
2550 return HandleDeclarator(S, D, move(TemplateParameterLists), false);

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

2633 translateTemplateArguments(TemplateArgsIn, TemplateArgLocs, TemplateArgs);
2634
2635 // Check that the template argument list is well-formed for this
2636 // template.
2637 TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
2638 TemplateArgs.size());
2639 if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
2640 TemplateArgs.data(), TemplateArgs.size(),
2600 RAngleLoc, Converted))
2641 RAngleLoc, false, 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);
2642 return true;
2643
2644 assert((Converted.structuredSize() ==
2645 ClassTemplate->getTemplateParameters()->size()) &&
2646 "Converted template argument list is too short!");
2647
2648 // Find the class template specialization declaration that
2649 // corresponds to these arguments.

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

2690 // use it for anything, since it is semantically irrelevant.
2691 Specialization
2692 = ClassTemplateSpecializationDecl::Create(Context,
2693 ClassTemplate->getDeclContext(),
2694 TemplateNameLoc,
2695 ClassTemplate,
2696 Converted, 0);
2697 Specialization->setLexicalDeclContext(CurContext);
2657 CurContext->addDecl(Context, Specialization);
2698 CurContext->addDecl(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);
2699 return DeclPtrTy::make(Specialization);
2700 }
2701
2702 // If we have already (implicitly) instantiated this
2703 // specialization, there is less work to do.
2704 if (PrevDecl->getSpecializationKind() == TSK_ImplicitInstantiation)
2705 SpecializationRequiresInstantiation = false;
2706

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

2739 Context.getTypeDeclType(Specialization));
2740 Specialization->setTypeAsWritten(WrittenTy);
2741 TemplateArgsIn.release();
2742
2743 // Add the explicit instantiation into its lexical context. However,
2744 // since explicit instantiations are never found by name lookup, we
2745 // just put it into the declaration context directly.
2746 Specialization->setLexicalDeclContext(CurContext);
2706 CurContext->addDecl(Context, Specialization);
2747 CurContext->addDecl(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 ---
2748
2749 // C++ [temp.explicit]p3:
2750 // A definition of a class template or class member template
2751 // shall be in scope at the point of the explicit instantiation of
2752 // the class template or class member template.
2753 //
2754 // This check comes when we actually try to perform the
2755 // instantiation.

--- 187 unchanged lines hidden ---