26 #include "llvm/ADT/SmallBitVector.h" 68 using namespace clang;
73 if (Y.getBitWidth() > X.getBitWidth())
74 X = X.extend(Y.getBitWidth());
75 else if (Y.getBitWidth() < X.getBitWidth())
76 Y = Y.extend(X.getBitWidth());
79 if (X.isSigned() != Y.isSigned()) {
81 if ((Y.isSigned() && Y.isNegative()) || (X.isSigned() && X.isNegative()))
96 TemplateDeductionInfo &Info,
97 SmallVectorImpl<DeducedTemplateArgument> &Deduced);
104 TemplateDeductionInfo &Info,
105 SmallVectorImpl<DeducedTemplateArgument> &
108 bool PartialOrdering =
false,
109 bool DeducedFromArrayBound =
false);
113 ArrayRef<TemplateArgument> Params,
114 ArrayRef<TemplateArgument> Args,
115 TemplateDeductionInfo &Info,
116 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
117 bool NumberOfArgumentsMustMatch);
121 bool OnlyDeduced,
unsigned Depth,
122 llvm::SmallBitVector &
Used);
125 bool OnlyDeduced,
unsigned Level,
126 llvm::SmallBitVector &Deduced);
137 E = IC->getSubExpr();
139 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
140 E = Subst->getReplacement();
146 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
147 if (NTTP->getDepth() == Info.getDeducedDepth())
156 if (
NamedDecl *NX = dyn_cast<NamedDecl>(X))
157 X = NX->getUnderlyingDecl();
158 if (
NamedDecl *NY = dyn_cast<NamedDecl>(Y))
159 Y = NY->getUnderlyingDecl();
194 llvm_unreachable(
"Non-deduced template arguments handled above");
245 llvm::FoldingSetNodeID ID1, ID2;
309 XA != XAEnd; ++XA, ++YA) {
315 NewPack.push_back(Merged);
323 llvm_unreachable(
"Invalid TemplateArgument Kind!");
332 QualType ValueType, TemplateDeductionInfo &Info,
333 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
334 assert(NTTP->
getDepth() == Info.getDeducedDepth() &&
335 "deducing non-type template argument with wrong depth");
339 if (Result.isNull()) {
341 Info.FirstArg = Deduced[NTTP->
getIndex()];
342 Info.SecondArg = NewDeduced;
360 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
361 ParamType = Expansion->getPattern();
379 QualType ValueType,
bool DeducedFromArrayBound, TemplateDeductionInfo &Info,
380 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
382 S, TemplateParams, NTTP,
384 DeducedFromArrayBound),
385 ValueType, Info, Deduced);
393 TemplateDeductionInfo &Info,
394 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
398 NullPtrType, CK_NullToPointer)
402 Value->
getType(), Info, Deduced);
412 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
415 Value->
getType(), Info, Deduced);
425 TemplateDeductionInfo &Info,
426 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
438 TemplateDeductionInfo &Info,
439 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
448 = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
450 if (TempParam->getDepth() != Info.getDeducedDepth())
455 Deduced[TempParam->getIndex()],
457 if (Result.isNull()) {
458 Info.Param = TempParam;
459 Info.FirstArg = Deduced[TempParam->getIndex()];
460 Info.SecondArg = NewDeduced;
464 Deduced[TempParam->getIndex()] = Result;
501 TemplateDeductionInfo &Info,
502 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
503 assert(Arg.
isCanonical() &&
"Argument type must be canonical");
506 if (
auto *Injected = dyn_cast<InjectedClassNameType>(Arg))
507 Arg = Injected->getInjectedSpecializationType();
511 = dyn_cast<TemplateSpecializationType>(Arg)) {
516 SpecArg->getTemplateName(),
526 SpecArg->template_arguments(), Info, Deduced,
567 case Type::TypeOfExpr:
569 case Type::DependentName:
571 case Type::UnresolvedUsing:
572 case Type::TemplateTypeParm:
575 case Type::ConstantArray:
576 case Type::IncompleteArray:
577 case Type::VariableArray:
578 case Type::DependentSizedArray:
580 cast<ArrayType>(T)->getElementType());
588 static std::pair<unsigned, unsigned>
591 return std::make_pair(TTP->getDepth(), TTP->getIndex());
594 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
601 static std::pair<unsigned, unsigned>
605 return std::make_pair(TTP->getDepth(), TTP->getIndex());
644 class PackDeductionScope {
649 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
652 unsigned NumPartialPackArgs = 0;
653 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
655 if (
auto *Partial =
Scope->getPartiallySubstitutedPack(
656 &PartialPackArgs, &NumPartialPackArgs))
662 llvm::SmallBitVector SawIndices(TemplateParams->
size());
664 auto AddPack = [&](
unsigned Index) {
665 if (SawIndices[Index])
667 SawIndices[Index] =
true;
672 Pack.
Saved = Deduced[Index];
675 Packs.push_back(Pack);
681 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
682 unsigned Depth, Index;
687 assert(!Packs.empty() &&
"Pack expansion without unexpanded packs?");
691 IsPartiallyExpanded =
693 PartialPackDepthIndex ==
697 if (IsPartiallyExpanded)
698 PackElements += NumPartialPackArgs;
704 llvm::SmallBitVector
Used(TemplateParams->
size());
707 for (
int Index =
Used.find_first(); Index != -1;
708 Index =
Used.find_next(Index))
713 for (
auto &Pack : Packs) {
720 if (PartialPackDepthIndex ==
722 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
731 if (Pack.New.size() > PackElements)
732 Deduced[Pack.Index] = Pack.New[PackElements];
737 ~PackDeductionScope() {
738 for (
auto &Pack : Packs)
744 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
747 void nextPackElement() {
751 for (
auto &Pack : Packs) {
753 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
754 while (Pack.New.size() < PackElements)
756 if (Pack.New.size() == PackElements)
757 Pack.New.push_back(DeducedArg);
759 Pack.New[PackElements] = DeducedArg;
760 DeducedArg = Pack.New.size() > PackElements + 1
761 ? Pack.New[PackElements + 1]
774 for (
auto &Pack : Packs) {
776 Deduced[Pack.Index] = Pack.Saved;
780 if (PackElements && Pack.New.empty()) {
781 if (Pack.DeferredDeduction.isNull()) {
788 NewPack = Pack.DeferredDeduction;
790 }
else if (Pack.New.empty()) {
796 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
804 Pack.New[0].wasDeducedFromArrayBound());
810 if (Pack.Outer->DeferredDeduction.isNull()) {
813 Pack.Outer->DeferredDeduction = NewPack;
816 Loc = &Pack.Outer->DeferredDeduction;
818 Loc = &Deduced[Pack.Index];
827 if (!Result.
isNull() && !Pack.DeferredDeduction.isNull()) {
829 NewPack = Pack.DeferredDeduction;
852 unsigned PackElements = 0;
853 bool IsPartiallyExpanded =
false;
892 const QualType *Params,
unsigned NumParams,
893 const QualType *Args,
unsigned NumArgs,
894 TemplateDeductionInfo &Info,
895 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
897 bool PartialOrdering =
false) {
899 if (NumParams != NumArgs &&
900 !(NumParams && isa<PackExpansionType>(Params[NumParams - 1])) &&
901 !(NumArgs && isa<PackExpansionType>(Args[NumArgs - 1])))
909 unsigned ArgIdx = 0, ParamIdx = 0;
910 for (; ParamIdx != NumParams; ++ParamIdx) {
918 if (ArgIdx >= NumArgs)
921 if (isa<PackExpansionType>(Args[ArgIdx])) {
931 Params[ParamIdx], Args[ArgIdx],
944 if (ParamIdx + 1 < NumParams)
955 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
957 for (; ArgIdx < NumArgs; ++ArgIdx) {
961 Args[ArgIdx], Info, Deduced,
962 TDF, PartialOrdering))
965 PackScope.nextPackElement();
970 if (
auto Result = PackScope.finish())
975 if (ArgIdx < NumArgs)
988 if (ParamQs == ArgQs)
1025 if (!ParamFunction || !ArgFunction)
1026 return Param == Arg;
1030 if (IsFunctionConversion(Param, Arg, AdjustedParam))
1035 return Param == Arg;
1044 if (!Guide || !Guide->isImplicit())
1056 if (ParamRef->getPointeeType().getQualifiers())
1059 return TypeParm && TypeParm->
getIndex() >= FirstInnerIndex;
1092 TemplateDeductionInfo &Info,
1093 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1095 bool PartialOrdering,
1096 bool DeducedFromArrayBound) {
1105 = dyn_cast<PackExpansionType>(Arg))
1106 Arg = ArgExpansion->getPattern();
1108 if (PartialOrdering) {
1190 TDF &= ~TDF_TopLevelParameterTypeList;
1208 Info.getDeducedDepth() != TemplateTypeParm->getDepth())
1211 unsigned Index = TemplateTypeParm->getIndex();
1212 bool RecanonicalizeArg =
false;
1216 if (isa<ArrayType>(Arg)) {
1221 RecanonicalizeArg =
true;
1229 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1235 assert(TemplateTypeParm->getDepth() == Info.getDeducedDepth() &&
1236 "saw template type parameter with wrong depth");
1257 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1274 if (RecanonicalizeArg)
1282 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1283 Info.FirstArg = Deduced[Index];
1284 Info.SecondArg = NewDeduced;
1288 Deduced[Index] = Result;
1300 if (isa<SubstTemplateTypeParmPackType>(Param))
1334 : ParamUnqualType == ArgUnqualType;
1341 #define NON_CANONICAL_TYPE(Class, Base) \ 1342 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class); 1343 #define TYPE(Class, Base) 1344 #include "clang/AST/TypeNodes.def" 1346 case Type::TemplateTypeParm:
1347 case Type::SubstTemplateTypeParmPack:
1348 llvm_unreachable(
"Type nodes handled above");
1353 case Type::VariableArray:
1355 case Type::FunctionNoProto:
1358 case Type::ObjCObject:
1359 case Type::ObjCInterface:
1360 case Type::ObjCObjectPointer: {
1364 if (TDF & TDF_IgnoreQualifiers) {
1376 cast<ComplexType>(Param)->getElementType(),
1377 ComplexArg->getElementType(),
1378 Info, Deduced, TDF);
1386 cast<AtomicType>(Param)->getValueType(),
1387 AtomicArg->getValueType(),
1388 Info, Deduced, TDF);
1393 case Type::Pointer: {
1406 cast<PointerType>(Param)->getPointeeType(),
1408 Info, Deduced, SubTDF);
1412 case Type::LValueReference: {
1419 cast<LValueReferenceType>(Param)->getPointeeType(),
1424 case Type::RValueReference: {
1431 cast<RValueReferenceType>(Param)->getPointeeType(),
1437 case Type::IncompleteArray: {
1440 if (!IncompleteArrayArg)
1447 Info, Deduced, SubTDF);
1451 case Type::ConstantArray: {
1454 if (!ConstantArrayArg)
1460 return Sema::TDK_NonDeducedMismatch;
1466 Info, Deduced, SubTDF);
1470 case Type::DependentSizedArray: {
1484 Info, Deduced, SubTDF))
1495 assert(NTTP->
getDepth() == Info.getDeducedDepth() &&
1496 "saw non-type template parameter with wrong depth");
1498 = dyn_cast<ConstantArrayType>(ArrayArg)) {
1499 llvm::APSInt Size(ConstantArrayArg->getSize());
1506 = dyn_cast<DependentSizedArrayType>(ArrayArg))
1507 if (DependentArrayArg->getSizeExpr())
1509 DependentArrayArg->getSizeExpr(),
1519 case Type::FunctionProto: {
1523 if (!FunctionProtoArg)
1527 cast<FunctionProtoType>(Param);
1534 return Sema::TDK_NonDeducedMismatch;
1547 FunctionProtoArg->
getNumParams(), Info, Deduced, SubTDF))
1560 assert(NTTP->getDepth() == Info.getDeducedDepth() &&
1561 "saw non-type template parameter with wrong depth");
1563 llvm::APSInt Noexcept(1);
1574 true, Info, Deduced);
1579 S, TemplateParams, NTTP, ArgNoexceptExpr, Info, Deduced);
1589 case Type::InjectedClassName: {
1592 Param = cast<InjectedClassNameType>(Param)
1593 ->getInjectedSpecializationType();
1594 assert(isa<TemplateSpecializationType>(Param) &&
1595 "injected class name is not a template specialization type");
1604 case Type::TemplateSpecialization: {
1606 cast<TemplateSpecializationType>(Param);
1619 S, TemplateParams, SpecParam, Arg, Info, Deduced);
1642 Deduced = DeducedOrig;
1647 llvm::SmallPtrSet<const RecordType *, 8> Visited;
1649 ToVisit.push_back(RecordT);
1650 bool Successful =
false;
1652 while (!ToVisit.empty()) {
1654 const RecordType *NextT = ToVisit.pop_back_val();
1657 if (!Visited.insert(NextT).second)
1662 if (NextT != RecordT) {
1663 TemplateDeductionInfo BaseInfo(Info.getLocation());
1666 QualType(NextT, 0), BaseInfo, Deduced);
1678 std::swap(SuccessfulDeduced, Deduced);
1680 Info.Param = BaseInfo.Param;
1681 Info.FirstArg = BaseInfo.FirstArg;
1682 Info.SecondArg = BaseInfo.SecondArg;
1685 Deduced = DeducedOrig;
1690 for (
const auto &
Base : Next->
bases()) {
1691 assert(
Base.getType()->isRecordType() &&
1692 "Base class that isn't a record?");
1698 std::swap(SuccessfulDeduced, Deduced);
1714 case Type::MemberPointer: {
1723 false, Info.getLocation());
1727 false, Info.getLocation());
1734 TDF & TDF_IgnoreQualifiers))
1739 QualType(MemPtrArg->getClass(), 0),
1741 TDF & TDF_IgnoreQualifiers);
1749 case Type::BlockPointer: {
1765 case Type::ExtVector: {
1766 const ExtVectorType *VectorParam = cast<ExtVectorType>(Param);
1767 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1769 if (VectorParam->
getNumElements() != VectorArg->getNumElements())
1770 return Sema::TDK_NonDeducedMismatch;
1775 VectorArg->getElementType(),
1776 Info, Deduced, TDF);
1780 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1788 VectorArg->getElementType(),
1789 Info, Deduced, TDF);
1798 case Type::DependentSizedExtVector: {
1800 = cast<DependentSizedExtVectorType>(Param);
1802 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1807 VectorArg->getElementType(),
1808 Info, Deduced, TDF))
1818 ArgSize = VectorArg->getNumElements();
1828 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1833 VectorArg->getElementType(),
1834 Info, Deduced, TDF))
1844 VectorArg->getSizeExpr(),
1854 case Type::DependentAddressSpace: {
1856 cast<DependentAddressSpaceType>(Param);
1859 dyn_cast<DependentAddressSpaceType>(Arg)) {
1874 S, TemplateParams, NTTP, AddressSpaceArg->getAddrSpaceExpr(), Info,
1898 true, Info, Deduced);
1904 case Type::TypeOfExpr:
1906 case Type::DependentName:
1907 case Type::UnresolvedUsing:
1908 case Type::Decltype:
1909 case Type::UnaryTransform:
1911 case Type::DeducedTemplateSpecialization:
1912 case Type::DependentTemplateSpecialization:
1913 case Type::PackExpansion:
1919 llvm_unreachable(
"Invalid Type Class!");
1927 TemplateDeductionInfo &Info,
1928 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
1937 llvm_unreachable(
"Null template argument in parameter list");
1945 Info.FirstArg = Param;
1946 Info.SecondArg = Arg;
1954 Info.FirstArg = Param;
1955 Info.SecondArg = Arg;
1959 llvm_unreachable(
"caller should handle pack expansions");
1966 Info.FirstArg = Param;
1967 Info.SecondArg = Arg;
1975 Info.FirstArg = Param;
1976 Info.SecondArg = Arg;
1984 Info.FirstArg = Param;
1985 Info.SecondArg = Arg;
1990 Info.FirstArg = Param;
1991 Info.SecondArg = Arg;
1995 Info.FirstArg = Param;
1996 Info.SecondArg = Arg;
2021 Info.FirstArg = Param;
2022 Info.SecondArg = Arg;
2030 llvm_unreachable(
"Argument packs should be expanded by the caller!");
2033 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2046 if (ArgIdx == Args.size())
2053 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
2056 return ArgIdx < Args.size();
2062 bool FoundPackExpansion =
false;
2063 for (
const auto &A : Args) {
2064 if (FoundPackExpansion)
2070 if (A.isPackExpansion())
2071 FoundPackExpansion =
true;
2079 ArrayRef<TemplateArgument> Params,
2080 ArrayRef<TemplateArgument> Args,
2081 TemplateDeductionInfo &Info,
2082 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2083 bool NumberOfArgumentsMustMatch) {
2095 unsigned ArgIdx = 0, ParamIdx = 0;
2097 if (!Params[ParamIdx].isPackExpansion()) {
2102 return NumberOfArgumentsMustMatch
2109 if (Args[ArgIdx].isPackExpansion())
2115 Params[ParamIdx], Args[ArgIdx],
2138 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
2150 PackScope.nextPackElement();
2155 if (
auto Result = PackScope.finish())
2167 TemplateDeductionInfo &Info,
2168 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
2170 ArgList.
asArray(), Info, Deduced,
2178 bool PackExpansionMatchesPack =
false) {
2189 llvm_unreachable(
"Comparing NULL template argument");
2212 llvm::FoldingSetNodeID XID, YID;
2225 XP != XPEnd; ++XP, ++YP)
2232 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2253 llvm_unreachable(
"Can't get a NULL template argument here");
2262 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2270 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2278 BuildExpressionFromIntegralTemplateArgument(Arg, Loc).getAs<
Expr>();
2287 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
2290 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
2307 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2317 TemplateDeductionInfo &Info,
2319 SmallVectorImpl<TemplateArgument> &Output) {
2321 unsigned ArgumentPackIndex) {
2349 "deduced nested pack");
2356 diag::err_template_arg_deduced_incomplete_pack)
2360 if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
2364 PackedArgsBuilder.push_back(Output.pop_back_val());
2369 if (PackedArgsBuilder.empty()) {
2374 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2378 if (Inst.isInvalid() ||
2379 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
2380 NTTP->getDeclName()).isNull())
2382 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2398 return ConvertArg(Arg, 0);
2404 template<
typename TemplateDeclT>
2406 Sema &S, TemplateDeclT *Template,
bool IsDeduced,
2407 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2408 TemplateDeductionInfo &Info, SmallVectorImpl<TemplateArgument> &Builder,
2410 unsigned NumAlreadyConverted = 0,
bool PartialOverloading =
false) {
2413 for (
unsigned I = 0, N = TemplateParams->
size(); I != N; ++I) {
2416 if (!Deduced[I].isNull()) {
2417 if (I < NumAlreadyConverted) {
2422 CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
2425 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2432 Builder.push_back(Deduced[I]);
2440 IsDeduced, Builder)) {
2459 unsigned NumExplicitArgs;
2460 if (CurrentInstantiationScope &&
2461 CurrentInstantiationScope->getPartiallySubstitutedPack(
2462 &ExplicitArgs, &NumExplicitArgs) == Param) {
2464 llvm::makeArrayRef(ExplicitArgs, NumExplicitArgs)));
2468 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2474 Info, IsDeduced, Builder)) {
2485 bool HasDefaultArg =
false;
2488 assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
2489 isa<VarTemplatePartialSpecializationDecl>(Template));
2500 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2502 if (PartialOverloading)
break;
2513 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2526 if (
auto *DC = dyn_cast<DeclContext>(D))
2532 static constexpr
bool value =
false;
2536 static constexpr
bool value =
true;
2540 static constexpr
bool value =
true;
2544 template <
typename T>
2545 static typename std::enable_if<IsPartialSpecialization<T>::value,
2548 Sema &S, T *Partial,
bool IsPartialOrdering,
2550 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2551 TemplateDeductionInfo &Info) {
2564 S, Partial, IsPartialOrdering, Deduced, Info, Builder))
2571 Info.reset(DeducedArgumentList);
2579 auto *Template = Partial->getSpecializedTemplate();
2581 Partial->getTemplateArgsAsWritten();
2590 unsigned ArgIdx = InstArgs.
size(), ParamIdx = ArgIdx;
2591 if (ParamIdx >= Partial->getTemplateParameters()->size())
2592 ParamIdx = Partial->getTemplateParameters()->size() - 1;
2595 Partial->getTemplateParameters()->getParam(ParamIdx));
2597 Info.FirstArg = PartialTemplateArgs[ArgIdx].
getArgument();
2603 false, ConvertedInstArgs))
2607 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2611 Info.FirstArg = TemplateArgs[I];
2612 Info.SecondArg = InstArg;
2629 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2630 TemplateDeductionInfo &Info) {
2643 S, Template, PartialOrdering, Deduced, Info, Builder))
2648 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2653 Info.FirstArg = TemplateArgs[I];
2654 Info.SecondArg = InstArg;
2693 TemplateArgs, Info, Deduced))
2699 if (Inst.isInvalid())
2700 return TDK_InstantiationDepth;
2706 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2734 TemplateArgs, Info, Deduced))
2740 if (Inst.isInvalid())
2741 return TDK_InstantiationDepth;
2747 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2754 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
2806 if (ExplicitTemplateArgs.
size() == 0) {
2810 ParamTypes.push_back(
P->getType());
2813 *FunctionType = Function->
getType();
2834 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
2835 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info);
2836 if (Inst.isInvalid())
2837 return TDK_InstantiationDepth;
2839 if (CheckTemplateArgumentList(FunctionTemplate,
SourceLocation(),
2840 ExplicitTemplateArgs,
true, Builder,
false) ||
2842 unsigned Index = Builder.size();
2843 if (Index >= TemplateParams->
size())
2844 Index = TemplateParams->
size() - 1;
2846 return TDK_InvalidExplicitArguments;
2853 Info.
reset(ExplicitArgumentList);
2865 for (
unsigned I = 0, N = Builder.size(); I != N; ++I) {
2868 CurrentInstantiationScope->SetPartiallySubstitutedPack(
2878 assert(Proto &&
"Function template does not have a prototype?");
2893 ParamTypes,
nullptr, ExtParamInfos))
2894 return TDK_SubstitutionFailure;
2906 unsigned ThisTypeQuals = 0;
2908 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
2910 ThisTypeQuals = Method->getTypeQualifiers();
2921 return TDK_SubstitutionFailure;
2930 ParamTypes,
nullptr, ExtParamInfos))
2931 return TDK_SubstitutionFailure;
2941 if (getLangOpts().CPlusPlus17 &&
2943 Function->
getLocation(), EPI.ExceptionSpec, ExceptionStorage,
2945 return TDK_SubstitutionFailure;
2947 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
2952 return TDK_SubstitutionFailure;
2965 Deduced.reserve(TemplateParams->
size());
2966 for (
unsigned I = 0, N = ExplicitArgumentList->
size(); I != N; ++I) {
2971 Deduced.push_back(Arg);
2988 Info.CallArgIndex = OriginalArg.
ArgIdx;
3039 if (AQuals == DeducedAQuals) {
3057 bool ObjCLifetimeConversion =
false;
3061 ObjCLifetimeConversion) ||
3104 unsigned ParamIdx) {
3107 if (PD->isParameterPack()) {
3108 unsigned NumExpansions =
3110 if (Idx + NumExpansions > ParamIdx)
3111 return ParamIdx - Idx;
3112 Idx += NumExpansions;
3114 if (Idx == ParamIdx)
3120 llvm_unreachable(
"parameter index would not be produced from template");
3132 unsigned NumExplicitlySpecified,
FunctionDecl *&Specialization,
3135 bool PartialOverloading, llvm::function_ref<
bool()> CheckNonDependent) {
3145 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3146 CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3147 if (Inst.isInvalid())
3148 return TDK_InstantiationDepth;
3157 *
this, FunctionTemplate,
true, Deduced, Info, Builder,
3158 CurrentInstantiationScope, NumExplicitlySpecified,
3159 PartialOverloading))
3171 if (CheckNonDependent())
3172 return TDK_NonDependentConversionFailure;
3177 Info.
reset(DeducedArgumentList);
3185 Specialization = cast_or_null<FunctionDecl>(
3188 return TDK_SubstitutionFailure;
3204 return TDK_SubstitutionFailure;
3207 if (OriginalCallArgs) {
3212 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
3213 for (
unsigned I = 0, N = OriginalCallArgs->size(); I != N; ++I) {
3216 auto ParamIdx = OriginalArg.
ArgIdx;
3234 if (CacheEntry.
isNull()) {
3243 DeducedA = CacheEntry;
3257 SuppressedDiagnosticsMap::iterator
3259 if (Pos == SuppressedDiagnostics.end())
3277 if (Method->isInstance()) {
3297 bool ParamWasReference) {
3305 if (ParamWasReference)
3350 TemplateDeductionInfo Info(Ovl->
getNameLoc());
3352 Specialization, Info))
3360 if (ArgType.isNull())
continue;
3364 ArgType->isFunctionType())
3380 Deduced(TemplateParams->
size());
3381 TemplateDeductionInfo Info(Ovl->
getNameLoc());
3384 ArgType, Info, Deduced, TDF);
3385 if (Result)
continue;
3420 ParamRefType !=
nullptr);
3481 (isa<PointerType>(ParamType) &&
3495 QualType ParamType,
Expr *Arg, TemplateDeductionInfo &Info,
3496 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3497 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3498 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF);
3505 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3506 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
unsigned ArgIdx,
3522 ElTy = ArrTy->getElementType();
3533 S, TemplateParams, 0, ElTy, E, Info, Deduced, OriginalCallArgs,
true,
3541 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
3552 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
3553 true, Info, Deduced))
3565 QualType ParamType,
Expr *Arg, TemplateDeductionInfo &Info,
3566 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3567 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3568 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF) {
3570 QualType OrigParamType = ParamType;
3575 S, TemplateParams, FirstInnerIndex, ParamType, ArgType, Arg, TDF))
3581 Deduced, OriginalCallArgs, ArgIdx, TDF);
3588 OriginalCallArgs.push_back(
3591 ArgType, Info, Deduced, TDF);
3623 bool PartialOverloading,
3638 return TDK_TooFewArguments;
3639 else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
3645 return TDK_TooManyArguments;
3655 unsigned NumExplicitlySpecified = 0;
3656 if (ExplicitTemplateArgs) {
3658 SubstituteExplicitTemplateArguments(FunctionTemplate,
3659 *ExplicitTemplateArgs,
3667 NumExplicitlySpecified = Deduced.size();
3670 for (
unsigned I = 0; I != NumParams; ++I)
3677 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx) {
3687 *
this, TemplateParams, FirstInnerIndex, ParamType, Args[ArgIdx], Info, Deduced,
3688 OriginalCallArgs,
false, ArgIdx, 0);
3692 Deduced.resize(TemplateParams->
size());
3694 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
3695 ParamIdx != NumParamTypes; ++ParamIdx) {
3696 QualType ParamType = ParamTypes[ParamIdx];
3700 if (!ParamExpansion) {
3702 if (ArgIdx >= Args.size())
3705 ParamTypesForArgChecking.push_back(ParamType);
3706 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++))
3713 PackDeductionScope PackScope(*
this, TemplateParams, Deduced, Info,
3732 if (ParamIdx + 1 == NumParamTypes) {
3733 for (; ArgIdx < Args.size(); PackScope.nextPackElement(), ++ArgIdx) {
3734 ParamTypesForArgChecking.push_back(ParamPattern);
3735 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx))
3743 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
3744 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
3746 ParamTypesForArgChecking.push_back(ParamPattern);
3749 PackScope.nextPackElement();
3756 if (
auto Result = PackScope.finish())
3761 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
3762 &OriginalCallArgs, PartialOverloading,
3763 [&]() {
return CheckNonDependent(ParamTypesForArgChecking); });
3768 bool AdjustExceptionSpec) {
3769 if (ArgFunctionType.
isNull())
3770 return ArgFunctionType;
3778 bool Rebuild =
false;
3781 if (EPI.ExtInfo.getCC() != CC) {
3782 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
3787 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
3788 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
3793 ArgFunctionTypeP->hasExceptionSpec())) {
3799 return ArgFunctionType;
3802 ArgFunctionTypeP->getParamTypes(), EPI);
3837 bool IsAddressOfFunction) {
3849 unsigned NumExplicitlySpecified = 0;
3851 if (ExplicitTemplateArgs) {
3853 = SubstituteExplicitTemplateArguments(FunctionTemplate,
3854 *ExplicitTemplateArgs,
3855 Deduced, ParamTypes,
3856 &FunctionType, Info))
3859 NumExplicitlySpecified = Deduced.size();
3865 if (!IsAddressOfFunction)
3866 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, FunctionType,
3874 Deduced.resize(TemplateParams->
size());
3880 bool HasDeducedReturnType =
false;
3881 if (getLangOpts().CPlusPlus14 && IsAddressOfFunction &&
3883 FunctionType = SubstAutoType(FunctionType, Context.
DependentTy);
3884 HasDeducedReturnType =
true;
3887 if (!ArgFunctionType.
isNull()) {
3893 FunctionType, ArgFunctionType,
3894 Info, Deduced, TDF))
3900 NumExplicitlySpecified,
3901 Specialization, Info))
3906 if (HasDeducedReturnType &&
3908 DeduceReturnType(Specialization, Info.
getLocation(),
false))
3909 return TDK_MiscellaneousDeductionFailure;
3913 auto *SpecializationFPT =
3915 if (getLangOpts().CPlusPlus17 &&
3917 !ResolveExceptionSpec(Info.
getLocation(), SpecializationFPT))
3918 return TDK_MiscellaneousDeductionFailure;
3925 if (!IsAddressOfFunction)
3926 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, SpecializationType,
3932 if (!ArgFunctionType.
isNull()) {
3933 if (IsAddressOfFunction &&
3934 !isSameOrCompatibleFunctionType(
3937 return TDK_MiscellaneousDeductionFailure;
3939 if (!IsAddressOfFunction &&
3940 !Context.
hasSameType(SpecializationType, ArgFunctionType))
3941 return TDK_MiscellaneousDeductionFailure;
3982 assert(!A->
isReferenceType() &&
"Reference types were handled above");
4019 Deduced.resize(TemplateParams->
size());
4043 P, A, Info, Deduced, TDF))
4052 ConversionSpecialized, Info);
4053 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
4085 bool IsAddressOfFunction) {
4088 IsAddressOfFunction);
4094 class SubstituteDeducedTypeTransform :
4099 SubstituteDeducedTypeTransform(
Sema &SemaRef,
QualType Replacement,
4100 bool UseTypeSugar =
true)
4102 Replacement(Replacement), UseTypeSugar(UseTypeSugar) {}
4105 assert(isa<TemplateTypeParmType>(Replacement) &&
4106 "unexpected unsugared replacement kind");
4124 return TransformDesugared(TLB, TL);
4133 QualType TransformDeducedTemplateSpecializationType(
4136 return TransformDesugared(TLB, TL);
4156 return TransformType(TLB, TL);
4164 return DeduceAutoType(Type->
getTypeLoc(), Init, Result,
4165 DependentDeductionDepth);
4173 TemplateDeductionInfo &Info,
4174 ArrayRef<SourceRange> Ranges) {
4178 auto D = S.
Diag(Info.getLocation(), diag::err_auto_inconsistent_deduction);
4179 D << Info.FirstArg << Info.SecondArg;
4180 for (
auto R : Ranges)
4211 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
4213 return DAR_FailedAlreadyDiagnosed;
4214 Init = NonPlaceholder.
get();
4217 if (!DependentDeductionDepth &&
4219 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4220 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4221 return DAR_Succeeded;
4225 unsigned Depth = DependentDeductionDepth.getValueOr(0);
4231 if (AT->isDecltypeAuto()) {
4232 if (isa<InitListExpr>(Init)) {
4234 return DAR_FailedAlreadyDiagnosed;
4239 return DAR_FailedAlreadyDiagnosed;
4242 Result = SubstituteDeducedTypeTransform(*
this, Deduced).Apply(Type);
4244 return DAR_FailedAlreadyDiagnosed;
4245 return DAR_Succeeded;
4246 }
else if (!getLangOpts().CPlusPlus) {
4247 if (isa<InitListExpr>(Init)) {
4249 return DAR_FailedAlreadyDiagnosed;
4260 Context,
nullptr,
SourceLocation(), Loc, Depth, 0,
nullptr,
false,
false);
4264 Loc, Loc, TemplParamPtr, Loc,
nullptr);
4267 SubstituteDeducedTypeTransform(*
this, TemplArg,
false)
4269 assert(!FuncParam.
isNull() &&
4270 "substituting template parameter for 'auto' failed");
4283 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4284 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4285 return DAR_Succeeded;
4288 return DAR_FailedAlreadyDiagnosed;
4303 for (
unsigned i = 0, e = InitList->
getNumInits(); i < e; ++i) {
4307 *
this, TemplateParamsSt.get(), 0, TemplArg, Init,
4308 Info, Deduced, OriginalCallArgs,
true,
4310 return DeductionFailed(TDK, {DeducedFromInitRange,
4311 Init->getSourceRange()});
4315 DeducedFromInitRange = Init->getSourceRange();
4319 Diag(Loc, diag::err_auto_bitfield);
4320 return DAR_FailedAlreadyDiagnosed;
4324 *
this, TemplateParamsSt.get(), 0, FuncParam, Init, Info, Deduced,
4325 OriginalCallArgs,
false, 0, 0))
4326 return DeductionFailed(TDK, {});
4331 return DeductionFailed(TDK_Incomplete, {});
4336 DeducedType = BuildStdInitializerList(DeducedType, Loc);
4337 if (DeducedType.isNull())
4338 return DAR_FailedAlreadyDiagnosed;
4341 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(Type);
4343 return DAR_FailedAlreadyDiagnosed;
4347 QualType DeducedA = InitList ? Deduced[0].getAsType() : Result;
4349 assert((
bool)InitList == OriginalArg.DecomposedParam &&
4350 "decomposed non-init-list in auto deduction?");
4354 return DeductionFailed(TDK, {});
4358 return DAR_Succeeded;
4365 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4366 .TransformType(TypeWithAuto);
4373 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4374 .TransformType(TypeWithAuto);
4379 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
4381 .TransformType(TypeWithAuto);
4385 if (isa<InitListExpr>(Init))
4388 ? diag::err_init_capture_deduction_failure_from_init_list
4389 : diag::err_auto_var_deduction_failure_from_init_list)
4393 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
4394 : diag::err_auto_var_deduction_failure)
4406 CXXRecordDecl *Lambda = cast<CXXMethodDecl>(FD)->getParent();
4411 CallOp = InstantiateFunctionDeclaration(
4419 InstantiateFunctionDefinition(Loc, CallOp);
4425 "failed to deduce lambda return type");
4428 QualType RetType = getLambdaConversionFunctionResultType(
4441 InstantiateFunctionDefinition(Loc, FD);
4445 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
4449 return StillUndeduced;
4456 SmallVectorImpl<QualType> &ArgTypes) {
4471 ArgTypes.push_back(ArgTy);
4481 unsigned NumCallArguments1) {
4487 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
4490 Deduced.resize(TemplateParams->
size());
4495 TemplateDeductionInfo Info(Loc);
4521 unsigned NumComparedArguments = NumCallArguments1;
4523 if (!Method2 && Method1 && !Method1->
isStatic()) {
4526 ++NumComparedArguments;
4527 }
else if (!Method1 && Method2 && !Method2->
isStatic()) {
4534 Args2.insert(Args2.end(), Proto2->param_type_begin(),
4535 Proto2->param_type_end());
4540 if (Args1.size() > NumComparedArguments)
4541 Args1.resize(NumComparedArguments);
4542 if (Args2.size() > NumComparedArguments)
4543 Args2.resize(NumComparedArguments);
4545 Args1.data(), Args1.size(), Info, Deduced,
4556 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
4579 unsigned ArgIdx = 0, NumArgs = Deduced.size();
4580 for (; ArgIdx != NumArgs; ++ArgIdx)
4581 if (Deduced[ArgIdx].isNull())
4588 if (ArgIdx == NumArgs) {
4595 llvm::SmallBitVector UsedParameters(TemplateParams->
size());
4598 for (
unsigned I = 0, N = Args2.size(); I != N; ++I)
4606 TemplateParams->
getDepth(), UsedParameters);
4616 for (; ArgIdx != NumArgs; ++ArgIdx)
4619 if (Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
4638 while (--NumParams > 0) {
4669 unsigned NumCallArguments1,
4670 unsigned NumCallArguments2) {
4676 if (Better1 != Better2)
4677 return Better1 ? FT1 : FT2;
4679 if (!Better1 && !Better2)
4687 if (Variadic1 != Variadic2)
4688 return Variadic1? FT2 : FT1;
4734 bool Complain,
QualType TargetType) {
4735 if (SpecBegin == SpecEnd) {
4737 Diag(Loc, NoneDiag);
4743 if (SpecBegin + 1 == SpecEnd)
4750 = cast<FunctionDecl>(*Best)->getPrimaryTemplate();
4751 assert(BestTemplate &&
"Not a function template specialization?");
4754 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4755 assert(Challenger &&
"Not a function template specialization?");
4756 if (
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4760 BestTemplate = Challenger;
4766 bool Ambiguous =
false;
4769 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4771 !
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4786 Diag(Loc, AmbigDiag);
4791 const auto *FD = cast<FunctionDecl>(*I);
4792 PD << FD << getTemplateArgumentBindingsText(
4793 FD->getPrimaryTemplate()->getTemplateParameters(),
4794 *FD->getTemplateSpecializationArgs());
4795 if (!TargetType.
isNull())
4796 HandleFunctionTypeMismatch(PD, FD->getType(), TargetType);
4797 Diag((*I)->getLocation(), PD);
4811 template<
typename TemplateLikeDecl>
4813 TemplateLikeDecl *P2,
4814 TemplateDeductionInfo &Info) {
4842 Deduced.resize(P2->getTemplateParameters()->size());
4856 TST1->template_arguments()),
4885 if (Better1 == Better2)
4888 return Better1 ? PS1 : PS2;
4912 "the partial specializations being compared should specialize" 4913 " the same template.");
4925 if (Better1 == Better2)
4928 return Better1 ? PS1 : PS2;
4943 CanonTemplate, PrimaryArgs);
4987 for (
unsigned I = 0, N = P->
size(); I != N; ++I) {
4995 PArgList.addArgument(getTrivialTemplateArgumentLoc(
5003 if (CheckTemplateArgumentList(AArg, Loc, PArgList,
false, PArgs) ||
5025 llvm::SmallBitVector &
Used) {
5028 E = Expansion->getPattern();
5034 E = ICE->getSubExpr();
5036 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
5037 E = Subst->getReplacement();
5069 llvm::SmallBitVector &
Used) {
5076 OnlyDeduced, Depth, Used);
5086 llvm::SmallBitVector &
Used) {
5089 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
5090 if (TTP->getDepth() ==
Depth)
5091 Used[TTP->getIndex()] =
true;
5110 llvm::SmallBitVector &
Used) {
5122 cast<PointerType>(T)->getPointeeType(),
5128 case Type::BlockPointer:
5130 cast<BlockPointerType>(T)->getPointeeType(),
5136 case Type::LValueReference:
5137 case Type::RValueReference:
5139 cast<ReferenceType>(T)->getPointeeType(),
5145 case Type::MemberPointer: {
5150 OnlyDeduced, Depth, Used);
5154 case Type::DependentSizedArray:
5156 cast<DependentSizedArrayType>(T)->getSizeExpr(),
5157 OnlyDeduced, Depth, Used);
5161 case Type::ConstantArray:
5162 case Type::IncompleteArray:
5164 cast<ArrayType>(T)->getElementType(),
5165 OnlyDeduced, Depth, Used);
5169 case Type::ExtVector:
5171 cast<VectorType>(T)->getElementType(),
5172 OnlyDeduced, Depth, Used);
5175 case Type::DependentSizedExtVector: {
5177 = cast<DependentSizedExtVectorType>(
T);
5185 case Type::DependentAddressSpace: {
5187 cast<DependentAddressSpaceType>(
T);
5196 case Type::FunctionProto: {
5200 for (
unsigned I = 0, N = Proto->
getNumParams(); I != N; ++I)
5208 case Type::TemplateTypeParm: {
5215 case Type::SubstTemplateTypeParmPack: {
5217 = cast<SubstTemplateTypeParmPackType>(
T);
5220 OnlyDeduced, Depth, Used);
5226 case Type::InjectedClassName:
5227 T = cast<InjectedClassNameType>(
T)->getInjectedSpecializationType();
5230 case Type::TemplateSpecialization: {
5232 = cast<TemplateSpecializationType>(
T);
5244 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5253 cast<ComplexType>(T)->getElementType(),
5254 OnlyDeduced, Depth, Used);
5260 cast<AtomicType>(T)->getValueType(),
5261 OnlyDeduced, Depth, Used);
5264 case Type::DependentName:
5267 cast<DependentNameType>(T)->getQualifier(),
5268 OnlyDeduced, Depth, Used);
5271 case Type::DependentTemplateSpecialization: {
5285 = cast<DependentTemplateSpecializationType>(
T);
5290 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5300 OnlyDeduced, Depth, Used);
5303 case Type::TypeOfExpr:
5306 cast<TypeOfExprType>(T)->getUnderlyingExpr(),
5307 OnlyDeduced, Depth, Used);
5310 case Type::Decltype:
5313 cast<DecltypeType>(T)->getUnderlyingExpr(),
5314 OnlyDeduced, Depth, Used);
5317 case Type::UnaryTransform:
5321 OnlyDeduced, Depth, Used);
5324 case Type::PackExpansion:
5326 cast<PackExpansionType>(T)->getPattern(),
5327 OnlyDeduced, Depth, Used);
5331 case Type::DeducedTemplateSpecialization:
5333 cast<DeducedType>(T)->getDeducedType(),
5334 OnlyDeduced, Depth, Used);
5339 case Type::VariableArray:
5340 case Type::FunctionNoProto:
5343 case Type::ObjCInterface:
5344 case Type::ObjCObject:
5345 case Type::ObjCObjectPointer:
5346 case Type::UnresolvedUsing:
5348 #define TYPE(Class, Base) 5349 #define ABSTRACT_TYPE(Class, Base) 5350 #define DEPENDENT_TYPE(Class, Base) 5351 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 5352 #include "clang/AST/TypeNodes.def" 5364 llvm::SmallBitVector &
Used) {
5365 switch (TemplateArg.
getKind()) {
5411 bool OnlyDeduced,
unsigned Depth,
5412 llvm::SmallBitVector &
Used) {
5421 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
5430 llvm::SmallBitVector &Deduced) {
5434 Deduced.resize(TemplateParams->
size());
5437 for (
unsigned I = 0, N = Function->
getNumParams(); I != N; ++I)
5439 true, TemplateParams->
getDepth(), Deduced);
5450 llvm::SmallBitVector Deduced(TemplateParams->
size());
5454 return Deduced.any();
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Defines the clang::ASTContext interface.
The null pointer literal (C++11 [lex.nullptr])
An instance of this class is created to represent a function declaration or definition.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y)
Verify that the given, deduced template arguments are compatible.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
const TypeClass * getTypePtr() const
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
TemplateDeductionResult
Describes the result of template argument deduction.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
bool isMemberPointerType() const
bool isLambdaConversionOperator(CXXConversionDecl *C)
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Template argument deduction was successful.
UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, TemplateSpecCandidateSet &FailedCandidates, SourceLocation Loc, const PartialDiagnostic &NoneDiag, const PartialDiagnostic &AmbigDiag, const PartialDiagnostic &CandidateDiag, bool Complain=true, QualType TargetType=QualType())
Retrieve the most specialized of the given function template specializations.
const Expr * getInit(unsigned Init) const
static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(Sema &S, TemplateDeclT *Template, bool IsDeduced, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info, SmallVectorImpl< TemplateArgument > &Builder, LocalInstantiationScope *CurrentInstantiationScope=nullptr, unsigned NumAlreadyConverted=0, bool PartialOverloading=false)
FunctionType - C99 6.7.5.3 - Function Declarators.
static Sema::TemplateDeductionResult CheckOriginalCallArgDeduction(Sema &S, TemplateDeductionInfo &Info, Sema::OriginalCallArg OriginalArg, QualType DeducedA)
Check whether the deduced argument type for a call to a function template matches the actual argument...
Provides information about an attempted template argument deduction, whose success or failure was des...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
void setObjCLifetime(ObjCLifetime type)
The template argument is an expression, and we've not resolved it to one of the other forms yet...
bool isRecordType() const
unsigned size() const
Retrieve the number of template arguments in this template argument list.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
const Type * getTypeForDecl() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
static bool IsPossiblyOpaquelyQualifiedType(QualType T)
Determines whether the given type is an opaque type that might be more qualified when instantiated...
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CanThrowResult canThrow(const ASTContext &Ctx) const
Determine whether this function type has a non-throwing exception specification.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Template argument deduction produced inconsistent deduced values for the given template parameter...
NamedDecl * getParam(unsigned Idx)
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
A container of type source information.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Partial ordering of function templates for a call to a conversion function.
bool CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, SmallVectorImpl< TemplateArgument > &Converted, bool UpdateArgsWithConversions=true)
Check that the given template arguments can be be provided to the given template, converting the argu...
TemplateDeductionResult FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, SmallVectorImpl< OriginalCallArg > const *OriginalCallArgs=nullptr, bool PartialOverloading=false, llvm::function_ref< bool()> CheckNonDependent=[]{ return false;})
Finish template argument deduction for a function template, checking the deduced template arguments f...
QualType getElementType() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static void MarkUsedTemplateParameters(ASTContext &Ctx, const TemplateArgument &TemplateArg, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark the template parameters that are used by this template argument.
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
This file provides some common utility functions for processing Lambda related AST Constructs...
unsigned getDepth() const
Get the nesting depth of the template parameter.
RAII object that enters a new expression evaluation context.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
void removeObjCLifetime()
QualType getReturnType() const
unsigned getNumParams() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
TemplateDeductionFlags
Various flags that control template argument deduction.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
SourceLocation getLAngleLoc() const
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
void clearSFINAEDiagnostic()
Discard any SFINAE diagnostics.
TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, Decl *Param, SmallVectorImpl< TemplateArgument > &Converted, bool &HasDefaultArg)
If the given template parameter has a default template argument, substitute into that default templat...
bool isParameterPack() const
Whether this declaration is a parameter pack.
Whether we are performing template argument deduction for parameters and arguments in a top-level tem...
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
TemplateParameter Param
The template parameter to which a template argument deduction failure refers.
QualType getIntegralType() const
Retrieve the type of the integral value.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
The collection of all-type qualifiers we support.
Base wrapper for a particular "section" of type source info.
QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, bool AdjustExceptionSpec=false)
Adjust the type ArgFunctionType to match the calling convention, noreturn, and optionally the excepti...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Represents a class template specialization, which refers to a class template with a given set of temp...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
static TemplateArgument getEmptyPack()
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
QualType getPointeeType() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a dependent template name that cannot be resolved prior to template instantiation.
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
static bool isVariadicFunctionTemplate(FunctionTemplateDecl *FunTmpl)
Determine whether this a function template whose parameter-type-list ends with a function parameter p...
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
bool isReferenceType() const
The iterator over UnresolvedSets.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Represents the result of substituting a set of types for a template type parameter pack...
static NonTypeTemplateParmDecl * getDeducedParameterFromExpr(TemplateDeductionInfo &Info, Expr *E)
If the given expression is of a form that permits the deduction of a non-type template parameter...
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
unsigned getTypeQualifiers() const
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(TemplateParameterList *P, TemplateDecl *AArg, SourceLocation Loc)
Within template argument deduction from overload resolution per C++ [over.over] allow matching functi...
QualType getParamTypeForDecl() const
unsigned getTypeQuals() const
ArrayRef< ParmVarDecl * > parameters() const
Within template argument deduction from a function call, we are matching with a parameter type for wh...
Describes an C or C++ initializer list.
void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, SourceLocation Loc)
Adjust the calling convention of a method to be the ABI default if it wasn't specified explicitly...
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
void setNameLoc(SourceLocation Loc)
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
bool HasFormOfMemberPointer
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
A convenient class for passing around template argument information.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
bool hasAddressSpace() const
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, sema::TemplateDeductionInfo &Info)
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
unsigned toTargetAddressSpace(LangAS AS)
bool IsFunctionConversion(QualType FromType, QualType ToType, QualType &ResultTy)
Determine whether the conversion from FromType to ToType is a valid conversion that strips "noexcept"...
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
Substitution of the deduced template argument values resulted in an error.
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
LangAS getAddressSpace() const
const TemplateArgument & getArg(unsigned Idx) const
const Type * getClass() const
void MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced)
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Scope - A scope is a transient data structure that is used while parsing the program.
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
param_type_iterator param_type_begin() const
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
const DependentSizedArrayType * getAsDependentSizedArrayType(QualType T) const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
SmallVector< DeducedTemplateArgument, 4 > New
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
const LangOptions & getLangOpts() const
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
QualType OriginalParamType
SourceLocation getTypeSpecStartLoc() const
FunctionDecl * resolveAddressOfOnlyViableOverloadCandidate(Expr *E, DeclAccessPair &FoundResult)
Given an expression that refers to an overloaded function, try to resolve that function to a single f...
Expr * getSizeExpr() const
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
QualType getElementType() const
RAII object used to change the argument pack substitution index within a Sema object.
Represents an extended vector type where either the type or size is dependent.
This object can be modified without requiring retains or releases.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
A helper class for building up ExtParameterInfos.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
static bool diagnoseAutoDeductionFailure(Sema &S, Sema::TemplateDeductionResult TDK, TemplateDeductionInfo &Info, ArrayRef< SourceRange > Ranges)
Attempt to produce an informative diagostic explaining why auto deduction failed. ...
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Expr * getAddrSpaceExpr() const
static Sema::TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, const TemplateArgument &Param, TemplateArgument Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
Sema - This implements semantic analysis and AST building for C.
static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc, FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1)
Determine whether the function template FT1 is at least as specialized as FT2.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &Converted, CheckTemplateArgumentKind CTAK=CTAK_Specified)
Check that the given template argument corresponds to the given template parameter.
Represents a prototype with parameter type info, e.g.
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
void reset(TemplateArgumentList *NewDeduced)
Provide a new template argument list that contains the results of template argument deduction...
bool isStdInitializerList(QualType Ty, QualType *Element)
Tests whether Ty is an instance of std::initializer_list and, if it is and Element is not NULL...
static bool hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate, QualType T)
Template argument deduction did not deduce a value for every template parameter.
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
static Sema::TemplateDeductionResult DeduceFromInitializerList(Sema &S, TemplateParameterList *TemplateParams, QualType AdjustedParamType, InitListExpr *ILE, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, unsigned ArgIdx, unsigned TDF)
Attempt template argument deduction from an initializer list deemed to be an argument in a function c...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
static bool isSimpleTemplateIdType(QualType T)
Determine whether the given type T is a simple-template-id type.
static std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
Represents an array type in C++ whose size is a value-dependent expression.
Allows QualTypes to be sorted and hence used in maps and sets.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static Sema::TemplateDeductionResult DeduceNullPtrTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, QualType NullPtrType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter from the given null pointer template argume...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
unsigned getNumArgs() const
Retrieve the number of template arguments.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
QualType getPointeeType() const
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
DeducedPack(unsigned Index)
static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, const DeducedTemplateArgument &NewDeduced, QualType ValueType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter as the given deduced template argument...
const FunctionProtoType * T
Declaration of a template type parameter.
unsigned getIndex() const
static DeclContext * getAsDeclContextOrEnclosing(Decl *D)
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(Sema &S, TemplateParameterList *TemplateParams, QualType Param, QualType Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned TDF, bool PartialOrdering=false, bool DeducedFromArrayBound=false)
Deduce the template arguments by comparing the parameter type and the argument type (C++ [temp...
static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType ParamType, Expr *Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, bool DecomposedParam, unsigned ArgIdx, unsigned TDF)
Perform template argument deduction per [temp.deduct.call] for a single parameter / argument pair...
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
static bool ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param, DeducedTemplateArgument Arg, NamedDecl *Template, TemplateDeductionInfo &Info, bool IsDeduced, SmallVectorImpl< TemplateArgument > &Output)
Convert the given deduced template argument and add it to the set of fully-converted template argumen...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
unsigned getNumInits() const
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
void completeExprArrayBound(Expr *E)
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
ObjCLifetime getObjCLifetime() const
DeclContext * getDeclContext()
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Represents a C++ template name within the type system.
decls_iterator decls_begin() const
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
ArrayRef< Expr * > inits()
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
FunctionDecl * ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, bool Complain=false, DeclAccessPair *Found=nullptr)
Given an expression that refers to an overloaded function, try to resolve that overloaded function ex...
bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg)
Compare types for equality with respect to possibly compatible function types (noreturn adjustment...
TemplateDeductionResult SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, TemplateArgumentListInfo &ExplicitTemplateArgs, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< QualType > &ParamTypes, QualType *FunctionType, sema::TemplateDeductionInfo &Info)
Substitute the explicitly-provided template arguments into the given function template according to C...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Data structure that captures multiple levels of template argument lists for use in template instantia...
SourceLocation getEnd() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, bool Diagnose=true)
An lvalue reference type, per C++11 [dcl.ref].
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Represents a C++ deduction guide declaration.
After substituting deduced template arguments, a dependent parameter type did not match the correspon...
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void removeCVRQualifiers(unsigned mask)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Captures a template argument whose value has been deduced via c++ template argument deduction...
static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, QualType ArgType)
Determine whether the parameter has qualifiers that are either inconsistent with or a superset of the...
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
bool hasTrailingReturn() const
RecordDecl * getDecl() const
static unsigned getPackIndexForParam(Sema &S, FunctionTemplateDecl *FunctionTemplate, const MultiLevelTemplateArgumentList &Args, unsigned ParamIdx)
Find the pack index for a particular parameter index in an instantiation of a function template with ...
SmallVector< DeducedPack *, 8 > PendingDeducedPacks
Information on packs that we're currently expanding.
There is no lifetime qualification on this type.
Assigning into this object requires the old value to be released and the new value to be retained...
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
A stack object to be created when performing template instantiation.
Stores a list of template parameters and the associated requires-clause (if any) for a TemplateDecl a...
ExtProtoInfo getExtProtoInfo() const
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
The template argument was deduced from an array bound via template argument deduction.
SourceLocation getNameLoc() const
Gets the location of the name.
const ExtParameterInfo * ExtParameterInfos
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static TemplateParameter makeTemplateParameter(Decl *D)
Helper function to build a TemplateParameter when we don't know its type statically.
QualType getReturnType() const
bool hasSameTemplateName(TemplateName X, TemplateName Y)
Determine whether the given template names refer to the same template.
LangAS getAddressSpace() const
Return the address space of this type.
Template argument deduction failed due to inconsistent cv-qualifiers on a template parameter type tha...
TemplateArgument getArgumentPack() const
static bool isSameTemplate(TemplateDecl *T1, TemplateDecl *T2)
Determine if the two templates are equivalent.
QualType getElementType() const
static QualType getUnderlyingType(const SubRegion *R)
Within template argument deduction from a function call, we are matching in a case where we ignore cv...
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const ParmVarDecl * getParamDecl(unsigned i) const
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init)
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Expr * getNoexceptExpr() const
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
Qualifiers withoutObjCLifetime() const
TypeSourceInfo * SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
bool isMemberFunctionPointerType() const
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
static unsigned getFirstInnerIndex(FunctionTemplateDecl *FTD)
Get the index of the first template parameter that was originally from the innermost template-paramet...
Within template argument deduction from a function call, we are matching in a case where we can perfo...
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
static bool isSameDeclaration(Decl *X, Decl *Y)
Determine whether two declaration pointers refer to the same declaration.
AutoTypeKeyword getKeyword() const
TypeClass getTypeClass() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
SourceLocation getRAngleLoc() const
bool isTargetAddressSpace(LangAS AS)
unsigned getDeducedDepth() const
The depth of template parameters for which deduction is being performed.
diag_iterator diag_end() const
Returns an iterator at the end of the sequence of suppressed diagnostics.
An rvalue ref-qualifier was provided (&&).
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
static bool hasPackExpansionBeforeEnd(ArrayRef< TemplateArgument > Args)
Determine whether the given set of template arguments has a pack expansion that is not the last templ...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
The injected class name of a C++ class template or class template partial specialization.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
QualType getPointeeType() const
Represents a pack expansion of types.
FunctionTemplateDecl * getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, unsigned NumCallArguments2)
Returns the more specialized function template according to the rules of function template partial or...
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
A POD class for pairing a NamedDecl* with an access specifier.
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
static QualType GetTypeOfFunction(Sema &S, const OverloadExpr::FindResult &R, FunctionDecl *Fn)
Gets the type of a function for template-argument-deducton purposes when it's considered as part of a...
static std::enable_if< IsPartialSpecialization< T >::value, Sema::TemplateDeductionResult >::type FinishTemplateArgumentDeduction(Sema &S, T *Partial, bool IsPartialOrdering, const TemplateArgumentList &TemplateArgs, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info)
Complete template argument deduction for a partial specialization.
Represents a template argument.
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
Represents a template name that was expressed as a qualified name.
Dataflow Directional Tag Classes.
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
const TemplateArgument & getArgument() const
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static QualType ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams, Expr *Arg, QualType ParamType, bool ParamWasReference)
Apply the deduction rules for overload sets.
The base class of all kinds of template declarations (e.g., class, function, etc.).
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
QualType getType() const
Get the type for which this source info wrapper provides information.
The template argument is a pack expansion of a template name that was provided for a template templat...
A non-depnedent component of the parameter did not match the corresponding component of the argument...
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
OverloadExpr * Expression
Represents a C++11 pack expansion that produces a sequence of expressions.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool hasObjCLifetime() const
void setCVRQualifiers(unsigned mask)
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool isNull() const
Determine whether this template argument has no value.
No template argument deduction flags, which indicates the strictest results for template argument ded...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Allow non-dependent types to differ, e.g., when performing template argument deduction from a functio...
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
Represents a pointer to an Objective C object.
static bool isForwardingReference(QualType Param, unsigned FirstInnerIndex)
Determine whether a type denotes a forwarding reference.
unsigned getIntWidth(QualType T) const
bool isIncompleteArrayType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
Location wrapper for a TemplateArgument.
unsigned getNumArgs() const
Retrieve the number of template arguments.
The template argument was specified in the code or was instantiated with some deduced template argume...
TemplateArgumentList * take()
Take ownership of the deduced template argument list.
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
const llvm::APInt & getSize() const
bool isFunctionType() const
ExtVectorType - Extended vector type.
Base for LValueReferenceType and RValueReferenceType.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None)
The template argument is a type.
Deduction failed; that's all we know.
The template argument is actually a parameter pack.
static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType &ParamType, QualType &ArgType, Expr *Arg, unsigned &TDF)
Perform the adjustments to the parameter and argument types described in C++ [temp.deduct.call].
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool hasObjCGCAttr() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
A template argument list.
bool isLValueReferenceType() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
ArgKind getKind() const
Return the kind of stored template argument.
unsigned getDepth() const
QualType getParamType(unsigned i) const
CallingConv getCallConv() const
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
Represents a template specialization type whose template cannot be resolved, e.g. ...
ArrayRef< TemplateArgument > template_arguments() const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
The template argument is a template name that was provided for a template template parameter...
Represents a C array with an unspecified size.
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
TPOC
The context in which partial ordering of function templates occurs.
Location information for a TemplateArgument.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
TemplateArgument SecondArg
The second template argument to which the template argument deduction failure refers.
Declaration of a class template.
Partial ordering of function templates for a function call.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
After substituting deduced template arguments, an element of a dependent parameter type did not match...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
A pack that we're currently deducing.
DeducedTemplateArgument Saved
SourceLocation getNameLoc() const
unsigned getCVRQualifiers() const
static bool isSameTemplateArg(ASTContext &Context, TemplateArgument X, const TemplateArgument &Y, bool PackExpansionMatchesPack=false)
Determine whether two template arguments are the same.
QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement)
Completely replace the auto in TypeWithAuto by Replacement.
Decl * SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
static Qualifiers fromCVRMask(unsigned CVR)
static Decl::Kind getKind(const Decl *D)
unsigned getNumElements() const
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getAsType() const
Retrieve the type for a type template argument.
A reference to a declared variable, function, enum, etc.
Represents an extended address space qualifier where the input address space value is dependent...
Represents a type template specialization; the template must be a class template, a type alias templa...
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
bool isPointerType() const
void NoteCandidates(Sema &S, SourceLocation Loc)
NoteCandidates - When no template specialization match is found, prints diagnostic messages containin...
TemplateArgument FirstArg
The first template argument to which the template argument deduction failure refers.
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, bool AllowDeducedTST=false)
Perform substitution on the type T with a given set of template arguments.
static bool hasSameExtendedValue(llvm::APSInt X, llvm::APSInt Y)
Compare two APSInts, extending and switching the sign as necessary to compare their values regardless...
static bool hasTemplateArgumentForDeduction(ArrayRef< TemplateArgument > &Args, unsigned &ArgIdx)
Determine whether there is a template argument to be used for deduction.
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
Wrapper for template type parameters.
A trivial tuple used to represent a source range.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
NamedDecl - This represents a decl with a name.
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark which template parameters can be deduced from a given template argument list.
static void AddImplicitObjectParameterType(ASTContext &Context, CXXMethodDecl *Method, SmallVectorImpl< QualType > &ArgTypes)
If this is a non-static member function,.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
The template argument was deduced via template argument deduction.
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
bool isFunctionPointerType() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
SourceLocation getLocStart() const LLVM_READONLY
void removeAddressSpace()
brief A function argument from which we performed template argument
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
const LangOptions & getLangOpts() const
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
diag_iterator diag_begin() const
Returns an iterator at the beginning of the sequence of suppressed diagnostics.
decls_iterator decls_end() const
Represents the canonical version of C arrays with a specified constant size.
ExceptionSpecInfo ExceptionSpec
Declaration of a template function.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
DeducedTemplateArgument DeferredDeduction
SourceLocation getLocation() const
QualType getPointeeType() const
Expr * getSizeExpr() const
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
param_type_iterator param_type_end() const