42 #include "llvm/ADT/APInt.h" 43 #include "llvm/ADT/APSInt.h" 44 #include "llvm/ADT/ArrayRef.h" 45 #include "llvm/ADT/DenseMap.h" 46 #include "llvm/ADT/FoldingSet.h" 47 #include "llvm/ADT/Optional.h" 48 #include "llvm/ADT/SmallBitVector.h" 49 #include "llvm/ADT/SmallPtrSet.h" 50 #include "llvm/ADT/SmallVector.h" 51 #include "llvm/Support/Casting.h" 52 #include "llvm/Support/Compiler.h" 53 #include "llvm/Support/ErrorHandling.h" 109 using namespace clang;
110 using namespace sema;
115 if (Y.getBitWidth() > X.getBitWidth())
116 X = X.extend(Y.getBitWidth());
117 else if (Y.getBitWidth() < X.getBitWidth())
118 Y = Y.extend(X.getBitWidth());
121 if (X.isSigned() != Y.isSigned()) {
123 if ((Y.isSigned() && Y.isNegative()) || (X.isSigned() && X.isNegative()))
139 SmallVectorImpl<DeducedTemplateArgument> &Deduced);
147 SmallVectorImpl<DeducedTemplateArgument> &
151 bool DeducedFromArrayBound =
false);
155 ArrayRef<TemplateArgument> Params,
156 ArrayRef<TemplateArgument> Args,
158 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
159 bool NumberOfArgumentsMustMatch);
163 bool OnlyDeduced,
unsigned Depth,
164 llvm::SmallBitVector &
Used);
167 bool OnlyDeduced,
unsigned Level,
168 llvm::SmallBitVector &Deduced);
179 E = IC->getSubExpr();
181 E = CE->getSubExpr();
183 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
184 E = Subst->getReplacement();
190 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
200 if (
NamedDecl *NX = dyn_cast<NamedDecl>(X))
201 X = NX->getUnderlyingDecl();
202 if (
NamedDecl *NY = dyn_cast<NamedDecl>(Y))
203 Y = NY->getUnderlyingDecl();
238 llvm_unreachable(
"Non-deduced template arguments handled above");
289 llvm::FoldingSetNodeID ID1, ID2;
353 XA != XAEnd; ++XA, ++YA) {
359 NewPack.push_back(Merged);
368 llvm_unreachable(
"Invalid TemplateArgument Kind!");
378 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
380 "deducing non-type template argument with wrong depth");
384 if (Result.isNull()) {
405 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
406 ParamType = Expansion->getPattern();
425 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
427 S, TemplateParams, NTTP,
429 DeducedFromArrayBound),
430 ValueType, Info, Deduced);
439 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
443 NullPtrType, CK_NullToPointer)
447 Value->
getType(), Info, Deduced);
457 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
460 Value->
getType(), Info, Deduced);
471 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
484 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
493 = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
500 Deduced[TempParam->getIndex()],
502 if (Result.isNull()) {
503 Info.
Param = TempParam;
504 Info.
FirstArg = Deduced[TempParam->getIndex()];
509 Deduced[TempParam->getIndex()] = Result;
547 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
548 assert(Arg.
isCanonical() &&
"Argument type must be canonical");
551 if (
auto *Injected = dyn_cast<InjectedClassNameType>(Arg))
552 Arg = Injected->getInjectedSpecializationType();
556 = dyn_cast<TemplateSpecializationType>(Arg)) {
561 SpecArg->getTemplateName(),
571 SpecArg->template_arguments(), Info, Deduced,
612 case Type::TypeOfExpr:
614 case Type::DependentName:
616 case Type::UnresolvedUsing:
617 case Type::TemplateTypeParm:
620 case Type::ConstantArray:
621 case Type::IncompleteArray:
622 case Type::VariableArray:
623 case Type::DependentSizedArray:
625 cast<ArrayType>(T)->getElementType());
645 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
646 if (NTTP->isExpandedParameterPack())
647 return NTTP->getNumExpansionTypes();
649 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param))
650 if (TTP->isExpandedParameterPack())
651 return TTP->getNumExpansionTemplateParameters();
680 class PackDeductionScope {
686 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
687 unsigned NumNamedPacks = addPacks(Pattern);
688 finishConstruction(NumNamedPacks);
695 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
697 finishConstruction(1);
701 void addPack(
unsigned Index) {
705 Pack.
Saved = Deduced[Index];
713 FixedNumExpansions = ExpandedPackExpansions;
715 Packs.push_back(Pack);
721 llvm::SmallBitVector SawIndices(TemplateParams->
size());
723 auto AddPack = [&](
unsigned Index) {
724 if (SawIndices[Index])
726 SawIndices[Index] =
true;
733 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
734 unsigned Depth, Index;
739 assert(!Packs.empty() &&
"Pack expansion without unexpanded packs?");
741 unsigned NumNamedPacks = Packs.size();
747 llvm::SmallBitVector
Used(TemplateParams->
size());
750 for (
int Index =
Used.find_first(); Index != -1;
751 Index =
Used.find_next(Index))
755 return NumNamedPacks;
758 void finishConstruction(
unsigned NumNamedPacks) {
761 unsigned NumPartialPackArgs = 0;
762 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
764 if (
auto *Partial =
Scope->getPartiallySubstitutedPack(
765 &PartialPackArgs, &NumPartialPackArgs))
771 bool IsExpanded =
true;
772 for (
unsigned I = 0; I != NumNamedPacks; ++I) {
775 IsPartiallyExpanded =
false;
778 if (PartialPackDepthIndex ==
780 IsPartiallyExpanded =
true;
786 if (IsPartiallyExpanded)
787 PackElements += NumPartialPackArgs;
789 PackElements += *FixedNumExpansions;
791 for (
auto &Pack : Packs) {
798 if (PartialPackDepthIndex ==
800 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
809 if (!IsPartiallyExpanded)
810 Deduced[Pack.Index] = Pack.New[PackElements];
816 ~PackDeductionScope() {
817 for (
auto &Pack : Packs)
823 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
828 bool hasFixedArity() {
return FixedNumExpansions.hasValue(); }
833 bool hasNextElement() {
834 return !FixedNumExpansions || *FixedNumExpansions > PackElements;
838 void nextPackElement() {
842 for (
auto &Pack : Packs) {
844 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
845 while (Pack.New.size() < PackElements)
847 if (Pack.New.size() == PackElements)
848 Pack.New.push_back(DeducedArg);
850 Pack.New[PackElements] = DeducedArg;
851 DeducedArg = Pack.New.size() > PackElements + 1
852 ? Pack.New[PackElements + 1]
863 finish(
bool TreatNoDeductionsAsNonDeduced =
true) {
866 for (
auto &Pack : Packs) {
868 Deduced[Pack.Index] = Pack.Saved;
874 if (!TreatNoDeductionsAsNonDeduced)
875 Pack.New.resize(PackElements);
879 if (PackElements && Pack.New.empty()) {
880 if (Pack.DeferredDeduction.isNull()) {
887 NewPack = Pack.DeferredDeduction;
889 }
else if (Pack.New.empty()) {
895 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
903 Pack.New[0].wasDeducedFromArrayBound());
909 if (Pack.Outer->DeferredDeduction.isNull()) {
912 Pack.Outer->DeferredDeduction = NewPack;
915 Loc = &Pack.Outer->DeferredDeduction;
917 Loc = &Deduced[Pack.Index];
926 if (!Result.
isNull() && !Pack.DeferredDeduction.isNull()) {
928 NewPack = Pack.DeferredDeduction;
943 if (*Expansions != PackElements) {
961 unsigned PackElements = 0;
962 bool IsPartiallyExpanded =
false;
1004 const QualType *Params,
unsigned NumParams,
1005 const QualType *Args,
unsigned NumArgs,
1007 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1009 bool PartialOrdering =
false) {
1024 if (ArgIdx >= NumArgs)
1027 if (isa<PackExpansionType>(Args[ArgIdx])) {
1054 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
1058 if (
ParamIdx + 1 == NumParams || PackScope.hasFixedArity()) {
1059 for (; ArgIdx < NumArgs && PackScope.hasNextElement(); ++ArgIdx) {
1063 Args[ArgIdx], Info, Deduced,
1067 PackScope.nextPackElement();
1088 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
1089 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < NumArgs;
1091 PackScope.nextPackElement();
1097 if (
auto Result = PackScope.finish())
1102 if (ArgIdx < NumArgs)
1117 if (ParamQs == ArgQs)
1152 if (!ParamFunction || !ArgFunction)
1153 return Param == Arg;
1157 if (IsFunctionConversion(Param, Arg, AdjustedParam))
1162 return Param == Arg;
1171 if (!Guide || !Guide->isImplicit())
1183 if (ParamRef->getPointeeType().getQualifiers())
1186 return TypeParm && TypeParm->
getIndex() >= FirstInnerIndex;
1220 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1222 bool PartialOrdering,
1223 bool DeducedFromArrayBound) {
1232 = dyn_cast<PackExpansionType>(Arg))
1233 Arg = ArgExpansion->getPattern();
1235 if (PartialOrdering) {
1317 TDF &= ~TDF_TopLevelParameterTypeList;
1338 unsigned Index = TemplateTypeParm->getIndex();
1339 bool RecanonicalizeArg =
false;
1343 if (isa<ArrayType>(Arg)) {
1348 RecanonicalizeArg =
true;
1356 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1369 "saw template type parameter with wrong depth");
1390 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1407 if (RecanonicalizeArg)
1415 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1421 Deduced[Index] = Result;
1433 if (isa<SubstTemplateTypeParmPackType>(Param))
1479 : ParamUnqualType == ArgUnqualType;
1486 #define NON_CANONICAL_TYPE(Class, Base) \ 1487 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class); 1488 #define TYPE(Class, Base) 1489 #include "clang/AST/TypeNodes.def" 1491 case Type::TemplateTypeParm:
1492 case Type::SubstTemplateTypeParmPack:
1493 llvm_unreachable(
"Type nodes handled above");
1498 case Type::VariableArray:
1500 case Type::FunctionNoProto:
1503 case Type::ObjCObject:
1504 case Type::ObjCInterface:
1505 case Type::ObjCObjectPointer:
1509 if (TDF & TDF_IgnoreQualifiers) {
1520 cast<ComplexType>(Param)->getElementType(),
1521 ComplexArg->getElementType(),
1522 Info, Deduced, TDF);
1530 cast<AtomicType>(Param)->getValueType(),
1531 AtomicArg->getValueType(),
1532 Info, Deduced, TDF);
1537 case Type::Pointer: {
1550 cast<PointerType>(Param)->getPointeeType(),
1552 Info, Deduced, SubTDF);
1556 case Type::LValueReference: {
1563 cast<LValueReferenceType>(Param)->getPointeeType(),
1568 case Type::RValueReference: {
1575 cast<RValueReferenceType>(Param)->getPointeeType(),
1581 case Type::IncompleteArray: {
1584 if (!IncompleteArrayArg)
1591 Info, Deduced, SubTDF);
1595 case Type::ConstantArray: {
1598 if (!ConstantArrayArg)
1604 return Sema::TDK_NonDeducedMismatch;
1610 Info, Deduced, SubTDF);
1614 case Type::DependentSizedArray: {
1628 Info, Deduced, SubTDF))
1640 "saw non-type template parameter with wrong depth");
1642 = dyn_cast<ConstantArrayType>(ArrayArg)) {
1643 llvm::APSInt Size(ConstantArrayArg->getSize());
1650 = dyn_cast<DependentSizedArrayType>(ArrayArg))
1651 if (DependentArrayArg->getSizeExpr())
1653 DependentArrayArg->getSizeExpr(),
1663 case Type::FunctionProto: {
1667 if (!FunctionProtoArg)
1671 cast<FunctionProtoType>(Param);
1678 return Sema::TDK_NonDeducedMismatch;
1691 FunctionProtoArg->
getNumParams(), Info, Deduced, SubTDF))
1705 "saw non-type template parameter with wrong depth");
1707 llvm::APSInt Noexcept(1);
1708 switch (FunctionProtoArg->
canThrow()) {
1718 true, Info, Deduced);
1723 S, TemplateParams, NTTP, ArgNoexceptExpr, Info, Deduced);
1736 case Type::InjectedClassName:
1739 Param = cast<InjectedClassNameType>(Param)
1740 ->getInjectedSpecializationType();
1741 assert(isa<TemplateSpecializationType>(Param) &&
1742 "injected class name is not a template specialization type");
1750 case Type::TemplateSpecialization: {
1752 cast<TemplateSpecializationType>(Param);
1765 S, TemplateParams, SpecParam, Arg, Info, Deduced);
1788 Deduced = DeducedOrig;
1793 llvm::SmallPtrSet<const RecordType *, 8> Visited;
1795 ToVisit.push_back(RecordT);
1796 bool Successful =
false;
1798 while (!ToVisit.empty()) {
1800 const RecordType *NextT = ToVisit.pop_back_val();
1803 if (!Visited.insert(NextT).second)
1808 if (NextT != RecordT) {
1812 QualType(NextT, 0), BaseInfo, Deduced);
1824 std::swap(SuccessfulDeduced, Deduced);
1826 Info.
Param = BaseInfo.Param;
1831 Deduced = DeducedOrig;
1836 for (
const auto &
Base : Next->
bases()) {
1837 assert(
Base.getType()->isRecordType() &&
1838 "Base class that isn't a record?");
1844 std::swap(SuccessfulDeduced, Deduced);
1860 case Type::MemberPointer: {
1880 TDF & TDF_IgnoreQualifiers))
1885 QualType(MemPtrArg->getClass(), 0),
1887 TDF & TDF_IgnoreQualifiers);
1895 case Type::BlockPointer: {
1911 case Type::ExtVector: {
1912 const ExtVectorType *VectorParam = cast<ExtVectorType>(Param);
1913 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1915 if (VectorParam->
getNumElements() != VectorArg->getNumElements())
1916 return Sema::TDK_NonDeducedMismatch;
1921 VectorArg->getElementType(),
1922 Info, Deduced, TDF);
1926 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1934 VectorArg->getElementType(),
1935 Info, Deduced, TDF);
1941 case Type::DependentVector: {
1942 const auto *VectorParam = cast<DependentVectorType>(Param);
1944 if (
const auto *VectorArg = dyn_cast<VectorType>(Arg)) {
1948 S, TemplateParams, VectorParam->getElementType(),
1949 VectorArg->getElementType(), Info, Deduced, TDF))
1959 ArgSize = VectorArg->getNumElements();
1968 if (
const auto *VectorArg = dyn_cast<DependentVectorType>(Arg)) {
1972 S, TemplateParams, VectorParam->getElementType(),
1973 VectorArg->getElementType(), Info, Deduced, TDF))
1978 Info, VectorParam->getSizeExpr());
1983 S, TemplateParams, NTTP, VectorArg->getSizeExpr(), Info, Deduced);
1992 case Type::DependentSizedExtVector: {
1994 = cast<DependentSizedExtVectorType>(Param);
1996 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
2001 VectorArg->getElementType(),
2002 Info, Deduced, TDF))
2012 ArgSize = VectorArg->getNumElements();
2022 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
2027 VectorArg->getElementType(),
2028 Info, Deduced, TDF))
2038 VectorArg->getSizeExpr(),
2048 case Type::DependentAddressSpace: {
2050 cast<DependentAddressSpaceType>(Param);
2053 dyn_cast<DependentAddressSpaceType>(Arg)) {
2068 S, TemplateParams, NTTP, AddressSpaceArg->getAddrSpaceExpr(), Info,
2092 true, Info, Deduced);
2098 case Type::TypeOfExpr:
2100 case Type::DependentName:
2101 case Type::UnresolvedUsing:
2102 case Type::Decltype:
2103 case Type::UnaryTransform:
2105 case Type::DeducedTemplateSpecialization:
2106 case Type::DependentTemplateSpecialization:
2107 case Type::PackExpansion:
2113 llvm_unreachable(
"Invalid Type Class!");
2122 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
2131 llvm_unreachable(
"Null template argument in parameter list");
2153 llvm_unreachable(
"caller should handle pack expansions");
2224 llvm_unreachable(
"Argument packs should be expanded by the caller!");
2227 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2240 if (ArgIdx == Args.size())
2247 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
2250 return ArgIdx < Args.size();
2256 bool FoundPackExpansion =
false;
2257 for (
const auto &A : Args) {
2258 if (FoundPackExpansion)
2266 if (A.isPackExpansion())
2267 FoundPackExpansion =
true;
2275 ArrayRef<TemplateArgument> Params,
2276 ArrayRef<TemplateArgument> Args,
2278 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2279 bool NumberOfArgumentsMustMatch) {
2293 if (!Params[
ParamIdx].isPackExpansion()) {
2298 return NumberOfArgumentsMustMatch
2305 if (Args[ArgIdx].isPackExpansion())
2330 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
2336 PackScope.hasNextElement();
2344 PackScope.nextPackElement();
2349 if (
auto Result = PackScope.finish())
2362 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
2364 ArgList.
asArray(), Info, Deduced,
2372 bool PackExpansionMatchesPack =
false) {
2383 llvm_unreachable(
"Comparing NULL template argument");
2406 llvm::FoldingSetNodeID XID, YID;
2419 XP != XPEnd; ++XP, ++YP)
2426 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2447 llvm_unreachable(
"Can't get a NULL template argument here");
2456 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2464 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2472 BuildExpressionFromIntegralTemplateArgument(Arg, Loc).getAs<
Expr>();
2481 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
2484 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
2501 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2512 SmallVectorImpl<TemplateArgument> &Output) {
2514 unsigned ArgumentPackIndex) {
2542 "deduced nested pack");
2549 diag::err_template_arg_deduced_incomplete_pack)
2553 if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
2557 PackedArgsBuilder.push_back(Output.pop_back_val());
2562 if (PackedArgsBuilder.empty()) {
2567 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2571 if (Inst.isInvalid() ||
2572 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
2573 NTTP->getDeclName()).isNull())
2575 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2591 return ConvertArg(Arg, 0);
2597 template<
typename TemplateDeclT>
2599 Sema &S, TemplateDeclT *Template,
bool IsDeduced,
2600 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2603 unsigned NumAlreadyConverted = 0,
bool PartialOverloading =
false) {
2606 for (
unsigned I = 0, N = TemplateParams->
size(); I != N; ++I) {
2614 if (
auto Result = PackDeductionScope(S, TemplateParams, Deduced, Info, I)
2619 if (!Deduced[I].isNull()) {
2620 if (I < NumAlreadyConverted) {
2625 CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
2628 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2635 Builder.push_back(Deduced[I]);
2643 IsDeduced, Builder)) {
2654 bool HasDefaultArg =
false;
2657 assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
2658 isa<VarTemplatePartialSpecializationDecl>(Template));
2669 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2671 if (PartialOverloading)
break;
2682 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2695 if (
auto *DC = dyn_cast<DeclContext>(D))
2701 static constexpr
bool value =
false;
2705 static constexpr
bool value =
true;
2709 static constexpr
bool value =
true;
2713 template <
typename T>
2714 static typename std::enable_if<IsPartialSpecialization<T>::value,
2717 Sema &S, T *Partial,
bool IsPartialOrdering,
2719 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2733 S, Partial, IsPartialOrdering, Deduced, Info, Builder))
2740 Info.
reset(DeducedArgumentList);
2748 auto *Template = Partial->getSpecializedTemplate();
2750 Partial->getTemplateArgsAsWritten();
2760 if (
ParamIdx >= Partial->getTemplateParameters()->size())
2761 ParamIdx = Partial->getTemplateParameters()->size() - 1;
2764 Partial->getTemplateParameters()->getParam(
ParamIdx));
2772 false, ConvertedInstArgs))
2776 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2798 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2812 S, Template, PartialOrdering, Deduced, Info, Builder))
2817 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2862 TemplateArgs, Info, Deduced))
2868 if (Inst.isInvalid())
2869 return TDK_InstantiationDepth;
2875 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2903 TemplateArgs, Info, Deduced))
2909 if (Inst.isInvalid())
2910 return TDK_InstantiationDepth;
2916 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2923 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
2975 if (ExplicitTemplateArgs.
size() == 0) {
2979 ParamTypes.push_back(
P->getType());
2982 *FunctionType = Function->
getType();
3003 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3004 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info);
3005 if (Inst.isInvalid())
3006 return TDK_InstantiationDepth;
3008 if (CheckTemplateArgumentList(FunctionTemplate,
SourceLocation(),
3009 ExplicitTemplateArgs,
true, Builder,
false) ||
3011 unsigned Index = Builder.size();
3012 if (Index >= TemplateParams->
size())
3013 return TDK_SubstitutionFailure;
3015 return TDK_InvalidExplicitArguments;
3034 unsigned PartiallySubstitutedPackIndex = -1u;
3035 if (!Builder.empty()) {
3038 auto *Param = TemplateParams->
getParam(Builder.size() - 1);
3042 if (!Expansions || Arg.
pack_size() < *Expansions) {
3043 PartiallySubstitutedPackIndex = Builder.size() - 1;
3044 CurrentInstantiationScope->SetPartiallySubstitutedPack(
3052 assert(Proto &&
"Function template does not have a prototype?");
3067 ParamTypes,
nullptr, ExtParamInfos))
3068 return TDK_SubstitutionFailure;
3082 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
3084 ThisTypeQuals = Method->getMethodQualifiers();
3095 return TDK_SubstitutionFailure;
3104 ParamTypes,
nullptr, ExtParamInfos))
3105 return TDK_SubstitutionFailure;
3115 if (getLangOpts().CPlusPlus17 &&
3117 Function->
getLocation(), EPI.ExceptionSpec, ExceptionStorage,
3119 return TDK_SubstitutionFailure;
3121 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
3126 return TDK_SubstitutionFailure;
3139 Deduced.reserve(TemplateParams->
size());
3140 for (
unsigned I = 0, N = ExplicitArgumentList->
size(); I != N; ++I) {
3142 if (I == PartiallySubstitutedPackIndex)
3145 Deduced.push_back(Arg);
3213 if (AQuals == DeducedAQuals) {
3231 bool ObjCLifetimeConversion =
false;
3235 ObjCLifetimeConversion) ||
3281 if (PD->isParameterPack()) {
3282 unsigned NumExpansions =
3284 if (Idx + NumExpansions > ParamIdx)
3285 return ParamIdx - Idx;
3286 Idx += NumExpansions;
3288 if (Idx == ParamIdx)
3294 llvm_unreachable(
"parameter index would not be produced from template");
3306 unsigned NumExplicitlySpecified,
FunctionDecl *&Specialization,
3309 bool PartialOverloading, llvm::function_ref<
bool()> CheckNonDependent) {
3319 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3320 CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3321 if (Inst.isInvalid())
3322 return TDK_InstantiationDepth;
3331 *
this, FunctionTemplate,
true, Deduced, Info, Builder,
3332 CurrentInstantiationScope, NumExplicitlySpecified,
3333 PartialOverloading))
3345 if (CheckNonDependent())
3346 return TDK_NonDependentConversionFailure;
3351 Info.
reset(DeducedArgumentList);
3359 Specialization = cast_or_null<FunctionDecl>(
3362 return TDK_SubstitutionFailure;
3378 return TDK_SubstitutionFailure;
3381 if (OriginalCallArgs) {
3386 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
3387 for (
unsigned I = 0, N = OriginalCallArgs->size(); I != N; ++I) {
3408 if (CacheEntry.
isNull()) {
3417 DeducedA = CacheEntry;
3431 SuppressedDiagnosticsMap::iterator
3433 if (Pos == SuppressedDiagnostics.end())
3451 if (Method->isInstance()) {
3472 bool ParamWasReference) {
3480 if (ParamWasReference)
3527 Specialization, Info))
3535 if (ArgType.isNull())
continue;
3539 ArgType->isFunctionType())
3555 Deduced(TemplateParams->
size());
3559 ArgType, Info, Deduced, TDF);
3560 if (Result)
continue;
3596 ParamRefType !=
nullptr);
3657 (isa<PointerType>(ParamType) &&
3672 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3673 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3674 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF);
3681 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3682 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
unsigned ArgIdx,
3698 ElTy = ArrTy->getElementType();
3709 S, TemplateParams, 0, ElTy, E, Info, Deduced, OriginalCallArgs,
true,
3717 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
3728 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
3729 true, Info, Deduced))
3742 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3743 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3744 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF) {
3746 QualType OrigParamType = ParamType;
3751 S, TemplateParams, FirstInnerIndex, ParamType, ArgType, Arg, TDF))
3757 Deduced, OriginalCallArgs, ArgIdx, TDF);
3764 OriginalCallArgs.push_back(
3767 ArgType, Info, Deduced, TDF);
3799 bool PartialOverloading,
3814 return TDK_TooFewArguments;
3815 else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
3821 return TDK_TooManyArguments;
3831 unsigned NumExplicitlySpecified = 0;
3832 if (ExplicitTemplateArgs) {
3834 SubstituteExplicitTemplateArguments(FunctionTemplate,
3835 *ExplicitTemplateArgs,
3843 NumExplicitlySpecified = Deduced.size();
3846 for (
unsigned I = 0; I != NumParams; ++I)
3853 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx) {
3863 *
this, TemplateParams, FirstInnerIndex, ParamType, Args[ArgIdx], Info, Deduced,
3864 OriginalCallArgs,
false, ArgIdx, 0);
3868 Deduced.resize(TemplateParams->
size());
3870 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
3876 if (!ParamExpansion) {
3878 if (ArgIdx >= Args.size())
3881 ParamTypesForArgChecking.push_back(ParamType);
3882 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++))
3889 PackDeductionScope PackScope(*
this, TemplateParams, Deduced, Info,
3908 if (
ParamIdx + 1 == NumParamTypes || PackScope.hasFixedArity()) {
3909 for (; ArgIdx < Args.size() && PackScope.hasNextElement();
3910 PackScope.nextPackElement(), ++ArgIdx) {
3911 ParamTypesForArgChecking.push_back(ParamPattern);
3912 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx))
3920 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
3921 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
3923 ParamTypesForArgChecking.push_back(ParamPattern);
3926 PackScope.nextPackElement();
3933 if (
auto Result = PackScope.finish())
3942 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
3943 &OriginalCallArgs, PartialOverloading, [&, CallingCtx]() {
3945 return CheckNonDependent(ParamTypesForArgChecking);
3951 bool AdjustExceptionSpec) {
3952 if (ArgFunctionType.
isNull())
3953 return ArgFunctionType;
3961 bool Rebuild =
false;
3964 if (EPI.ExtInfo.getCC() != CC) {
3965 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
3970 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
3971 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
3976 ArgFunctionTypeP->hasExceptionSpec())) {
3982 return ArgFunctionType;
3985 ArgFunctionTypeP->getParamTypes(), EPI);
4020 bool IsAddressOfFunction) {
4032 unsigned NumExplicitlySpecified = 0;
4034 if (ExplicitTemplateArgs) {
4036 = SubstituteExplicitTemplateArguments(FunctionTemplate,
4037 *ExplicitTemplateArgs,
4038 Deduced, ParamTypes,
4039 &FunctionType, Info))
4042 NumExplicitlySpecified = Deduced.size();
4048 if (!IsAddressOfFunction)
4049 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, FunctionType,
4057 Deduced.resize(TemplateParams->
size());
4063 bool HasDeducedReturnType =
false;
4064 if (getLangOpts().CPlusPlus14 && IsAddressOfFunction &&
4066 FunctionType = SubstAutoType(FunctionType, Context.
DependentTy);
4067 HasDeducedReturnType =
true;
4070 if (!ArgFunctionType.
isNull()) {
4076 FunctionType, ArgFunctionType,
4077 Info, Deduced, TDF))
4083 NumExplicitlySpecified,
4084 Specialization, Info))
4089 if (HasDeducedReturnType &&
4091 DeduceReturnType(Specialization, Info.
getLocation(),
false))
4092 return TDK_MiscellaneousDeductionFailure;
4096 auto *SpecializationFPT =
4098 if (getLangOpts().CPlusPlus17 &&
4100 !ResolveExceptionSpec(Info.
getLocation(), SpecializationFPT))
4101 return TDK_MiscellaneousDeductionFailure;
4108 if (!IsAddressOfFunction)
4109 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, SpecializationType,
4115 if (!ArgFunctionType.
isNull()) {
4116 if (IsAddressOfFunction &&
4117 !isSameOrCompatibleFunctionType(
4120 return TDK_MiscellaneousDeductionFailure;
4122 if (!IsAddressOfFunction &&
4123 !Context.
hasSameType(SpecializationType, ArgFunctionType))
4124 return TDK_MiscellaneousDeductionFailure;
4173 assert(!A->
isReferenceType() &&
"Reference types were handled above");
4210 Deduced.resize(TemplateParams->
size());
4234 P, A, Info, Deduced, TDF))
4243 ConversionSpecialized, Info);
4244 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
4276 bool IsAddressOfFunction) {
4279 IsAddressOfFunction);
4283 struct DependentAuto {
bool IsPack; };
4287 class SubstituteDeducedTypeTransform :
4290 bool ReplacementIsPack;
4294 SubstituteDeducedTypeTransform(
Sema &SemaRef, DependentAuto DA)
4296 ReplacementIsPack(DA.IsPack), UseTypeSugar(
true) {}
4298 SubstituteDeducedTypeTransform(
Sema &SemaRef,
QualType Replacement,
4299 bool UseTypeSugar =
true)
4301 Replacement(Replacement), ReplacementIsPack(
false),
4302 UseTypeSugar(UseTypeSugar) {}
4305 assert(isa<TemplateTypeParmType>(Replacement) &&
4306 "unexpected unsugared replacement kind");
4324 return TransformDesugared(TLB, TL);
4334 QualType TransformDeducedTemplateSpecializationType(
4337 return TransformDesugared(TLB, TL);
4341 Replacement, Replacement.
isNull());
4357 return TransformType(TLB, TL);
4366 return DeduceAutoType(Type->
getTypeLoc(), Init, Result,
4367 DependentDeductionDepth);
4376 ArrayRef<SourceRange> Ranges) {
4380 auto D = S.
Diag(Info.
getLocation(), diag::err_auto_inconsistent_deduction);
4382 for (
auto R : Ranges)
4413 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
4415 return DAR_FailedAlreadyDiagnosed;
4416 Init = NonPlaceholder.
get();
4419 DependentAuto DependentResult = {
4422 if (!DependentDeductionDepth &&
4424 Result = SubstituteDeducedTypeTransform(*
this, DependentResult).Apply(Type);
4425 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4426 return DAR_Succeeded;
4430 unsigned Depth = DependentDeductionDepth.getValueOr(0);
4436 if (AT->isDecltypeAuto()) {
4437 if (isa<InitListExpr>(Init)) {
4439 return DAR_FailedAlreadyDiagnosed;
4444 return DAR_FailedAlreadyDiagnosed;
4448 return DAR_FailedAlreadyDiagnosed;
4451 Result = SubstituteDeducedTypeTransform(*
this, Deduced).Apply(Type);
4453 return DAR_FailedAlreadyDiagnosed;
4454 return DAR_Succeeded;
4455 }
else if (!getLangOpts().CPlusPlus) {
4456 if (isa<InitListExpr>(Init)) {
4458 return DAR_FailedAlreadyDiagnosed;
4469 Context,
nullptr,
SourceLocation(), Loc, Depth, 0,
nullptr,
false,
false);
4473 Loc, Loc, TemplParamPtr, Loc,
nullptr);
4476 SubstituteDeducedTypeTransform(*
this, TemplArg,
false)
4478 assert(!FuncParam.
isNull() &&
4479 "substituting template parameter for 'auto' failed");
4493 SubstituteDeducedTypeTransform(*
this, DependentResult).Apply(Type);
4494 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4495 return DAR_Succeeded;
4498 return DAR_FailedAlreadyDiagnosed;
4517 *
this, TemplateParamsSt.get(), 0, TemplArg, Init,
4518 Info, Deduced, OriginalCallArgs,
true,
4520 return DeductionFailed(TDK, {DeducedFromInitRange,
4521 Init->getSourceRange()});
4525 DeducedFromInitRange = Init->getSourceRange();
4529 Diag(Loc, diag::err_auto_bitfield);
4530 return DAR_FailedAlreadyDiagnosed;
4534 *
this, TemplateParamsSt.get(), 0, FuncParam, Init, Info, Deduced,
4535 OriginalCallArgs,
false, 0, 0))
4536 return DeductionFailed(TDK, {});
4541 return DeductionFailed(TDK_Incomplete, {});
4546 DeducedType = BuildStdInitializerList(DeducedType, Loc);
4547 if (DeducedType.isNull())
4548 return DAR_FailedAlreadyDiagnosed;
4551 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(Type);
4553 return DAR_FailedAlreadyDiagnosed;
4557 QualType DeducedA = InitList ? Deduced[0].getAsType() : Result;
4559 assert((
bool)InitList == OriginalArg.DecomposedParam &&
4560 "decomposed non-init-list in auto deduction?");
4564 return DeductionFailed(TDK, {});
4568 return DAR_Succeeded;
4574 return SubstituteDeducedTypeTransform(
4575 *
this, DependentAuto{
4577 .TransformType(TypeWithAuto);
4578 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4579 .TransformType(TypeWithAuto);
4585 return SubstituteDeducedTypeTransform(
4589 .TransformType(TypeWithAuto);
4590 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4591 .TransformType(TypeWithAuto);
4596 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
4598 .TransformType(TypeWithAuto);
4602 if (isa<InitListExpr>(Init))
4605 ? diag::err_init_capture_deduction_failure_from_init_list
4606 : diag::err_auto_var_deduction_failure_from_init_list)
4610 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
4611 : diag::err_auto_var_deduction_failure)
4623 CXXRecordDecl *Lambda = cast<CXXMethodDecl>(FD)->getParent();
4628 CallOp = InstantiateFunctionDeclaration(
4636 InstantiateFunctionDefinition(Loc, CallOp);
4642 "failed to deduce lambda return type");
4645 QualType RetType = getLambdaConversionFunctionResultType(
4658 InstantiateFunctionDefinition(Loc, FD);
4662 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
4666 return StillUndeduced;
4673 SmallVectorImpl<QualType> &ArgTypes) {
4687 ArgTypes.push_back(ArgTy);
4697 unsigned NumCallArguments1) {
4703 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
4706 Deduced.resize(TemplateParams->
size());
4737 unsigned NumComparedArguments = NumCallArguments1;
4739 if (!Method2 && Method1 && !Method1->
isStatic()) {
4742 ++NumComparedArguments;
4743 }
else if (!Method1 && Method2 && !Method2->
isStatic()) {
4750 Args2.insert(Args2.end(), Proto2->param_type_begin(),
4751 Proto2->param_type_end());
4756 if (Args1.size() > NumComparedArguments)
4757 Args1.resize(NumComparedArguments);
4758 if (Args2.size() > NumComparedArguments)
4759 Args2.resize(NumComparedArguments);
4761 Args1.data(), Args1.size(), Info, Deduced,
4772 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
4795 unsigned ArgIdx = 0, NumArgs = Deduced.size();
4796 for (; ArgIdx != NumArgs; ++ArgIdx)
4797 if (Deduced[ArgIdx].isNull())
4804 if (ArgIdx == NumArgs) {
4811 llvm::SmallBitVector UsedParameters(TemplateParams->
size());
4814 for (
unsigned I = 0, N = Args2.size(); I != N; ++I)
4822 TemplateParams->
getDepth(), UsedParameters);
4832 for (; ArgIdx != NumArgs; ++ArgIdx)
4835 if (Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
4854 while (--NumParams > 0) {
4885 unsigned NumCallArguments1,
4886 unsigned NumCallArguments2) {
4892 if (Better1 != Better2)
4893 return Better1 ? FT1 : FT2;
4895 if (!Better1 && !Better2)
4903 if (Variadic1 != Variadic2)
4904 return Variadic1? FT2 : FT1;
4950 bool Complain,
QualType TargetType) {
4951 if (SpecBegin == SpecEnd) {
4953 Diag(Loc, NoneDiag);
4959 if (SpecBegin + 1 == SpecEnd)
4966 = cast<FunctionDecl>(*Best)->getPrimaryTemplate();
4967 assert(BestTemplate &&
"Not a function template specialization?");
4970 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4971 assert(Challenger &&
"Not a function template specialization?");
4972 if (
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4976 BestTemplate = Challenger;
4982 bool Ambiguous =
false;
4985 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4987 !
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
5002 Diag(Loc, AmbigDiag);
5007 const auto *FD = cast<FunctionDecl>(*I);
5008 PD << FD << getTemplateArgumentBindingsText(
5009 FD->getPrimaryTemplate()->getTemplateParameters(),
5010 *FD->getTemplateSpecializationArgs());
5011 if (!TargetType.
isNull())
5012 HandleFunctionTypeMismatch(PD, FD->getType(), TargetType);
5013 Diag((*I)->getLocation(), PD);
5027 template<
typename TemplateLikeDecl>
5029 TemplateLikeDecl *P2,
5058 Deduced.resize(P2->getTemplateParameters()->size());
5072 TST1->template_arguments()),
5101 if (Better1 == Better2)
5104 return Better1 ? PS1 : PS2;
5128 "the partial specializations being compared should specialize" 5129 " the same template.");
5141 if (Better1 == Better2)
5144 return Better1 ? PS1 : PS2;
5159 CanonTemplate, PrimaryArgs);
5203 for (
unsigned I = 0, N = P->
size(); I != N; ++I) {
5211 PArgList.addArgument(getTrivialTemplateArgumentLoc(
5219 if (CheckTemplateArgumentList(AArg, Loc, PArgList,
false, PArgs) ||
5241 llvm::SmallBitVector &
Used) {
5244 E = Expansion->getPattern();
5250 E = ICE->getSubExpr();
5251 else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(E))
5252 E = CE->getSubExpr();
5254 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
5255 E = Subst->getReplacement();
5287 llvm::SmallBitVector &
Used) {
5294 OnlyDeduced, Depth, Used);
5304 llvm::SmallBitVector &
Used) {
5307 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
5308 if (TTP->getDepth() ==
Depth)
5309 Used[TTP->getIndex()] =
true;
5328 llvm::SmallBitVector &
Used) {
5340 cast<PointerType>(T)->getPointeeType(),
5346 case Type::BlockPointer:
5348 cast<BlockPointerType>(T)->getPointeeType(),
5354 case Type::LValueReference:
5355 case Type::RValueReference:
5357 cast<ReferenceType>(T)->getPointeeType(),
5363 case Type::MemberPointer: {
5368 OnlyDeduced, Depth, Used);
5372 case Type::DependentSizedArray:
5374 cast<DependentSizedArrayType>(T)->getSizeExpr(),
5375 OnlyDeduced, Depth, Used);
5379 case Type::ConstantArray:
5380 case Type::IncompleteArray:
5382 cast<ArrayType>(T)->getElementType(),
5383 OnlyDeduced, Depth, Used);
5387 case Type::ExtVector:
5389 cast<VectorType>(T)->getElementType(),
5390 OnlyDeduced, Depth, Used);
5393 case Type::DependentVector: {
5394 const auto *VecType = cast<DependentVectorType>(T);
5401 case Type::DependentSizedExtVector: {
5403 = cast<DependentSizedExtVectorType>(T);
5411 case Type::DependentAddressSpace: {
5413 cast<DependentAddressSpaceType>(T);
5422 case Type::FunctionProto: {
5426 for (
unsigned I = 0, N = Proto->
getNumParams(); I != N; ++I) {
5431 if (!OnlyDeduced || I + 1 == N ||
5449 case Type::TemplateTypeParm: {
5456 case Type::SubstTemplateTypeParmPack: {
5458 = cast<SubstTemplateTypeParmPackType>(T);
5461 OnlyDeduced, Depth, Used);
5467 case Type::InjectedClassName:
5468 T = cast<InjectedClassNameType>(T)->getInjectedSpecializationType();
5471 case Type::TemplateSpecialization: {
5473 = cast<TemplateSpecializationType>(T);
5485 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5494 cast<ComplexType>(T)->getElementType(),
5495 OnlyDeduced, Depth, Used);
5501 cast<AtomicType>(T)->getValueType(),
5502 OnlyDeduced, Depth, Used);
5505 case Type::DependentName:
5508 cast<DependentNameType>(T)->getQualifier(),
5509 OnlyDeduced, Depth, Used);
5512 case Type::DependentTemplateSpecialization: {
5526 = cast<DependentTemplateSpecializationType>(T);
5531 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5541 OnlyDeduced, Depth, Used);
5544 case Type::TypeOfExpr:
5547 cast<TypeOfExprType>(T)->getUnderlyingExpr(),
5548 OnlyDeduced, Depth, Used);
5551 case Type::Decltype:
5554 cast<DecltypeType>(T)->getUnderlyingExpr(),
5555 OnlyDeduced, Depth, Used);
5558 case Type::UnaryTransform:
5562 OnlyDeduced, Depth, Used);
5565 case Type::PackExpansion:
5567 cast<PackExpansionType>(T)->getPattern(),
5568 OnlyDeduced, Depth, Used);
5572 case Type::DeducedTemplateSpecialization:
5574 cast<DeducedType>(T)->getDeducedType(),
5575 OnlyDeduced, Depth, Used);
5580 case Type::VariableArray:
5581 case Type::FunctionNoProto:
5584 case Type::ObjCInterface:
5585 case Type::ObjCObject:
5586 case Type::ObjCObjectPointer:
5587 case Type::UnresolvedUsing:
5589 #define TYPE(Class, Base) 5590 #define ABSTRACT_TYPE(Class, Base) 5591 #define DEPENDENT_TYPE(Class, Base) 5592 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 5593 #include "clang/AST/TypeNodes.def" 5605 llvm::SmallBitVector &
Used) {
5606 switch (TemplateArg.
getKind()) {
5652 bool OnlyDeduced,
unsigned Depth,
5653 llvm::SmallBitVector &
Used) {
5662 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
5671 llvm::SmallBitVector &Deduced) {
5675 Deduced.resize(TemplateParams->
size());
5678 for (
unsigned I = 0, N = Function->
getNumParams(); I != N; ++I)
5680 true, TemplateParams->
getDepth(), Deduced);
5691 llvm::SmallBitVector Deduced(TemplateParams->
size());
5695 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])
Represents a function declaration or definition.
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...
C Language Family Type Representation.
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...
bool isVariadic() const
Whether this function prototype is variadic.
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.
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.
Represents 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...
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
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.
SourceLocation getBeginLoc() const LLVM_READONLY
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...
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
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.
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
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
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
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"...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
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
Provides definitions for the various language-specific address spaces.
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...
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
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.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
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.
void setExplicitArgs(TemplateArgumentList *NewDeduced)
Provide an initial template argument list that contains the explicitly-specified arguments.
Represents an array type in C++ whose size is a value-dependent expression.
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...
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
unsigned getNumArgs() const
Retrieve the number of template arguments.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Defines the clang::LangOptions interface.
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...
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.
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...
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
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
Defines the clang::TypeLoc interface and its subclasses.
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 the argument lacks.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
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)
Template argument deduction did not deduce a value for every expansion of an expanded template parame...
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...
Qualifiers getMethodQuals() const
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
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.
Defines various enumerations that describe declaration and type specifiers.
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...
Qualifiers getMethodQualifiers() const
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
Return 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 isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack...
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.
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
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.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
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
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
CallingConv getCallConv() const
Defines the clang::SourceLocation class and associated facilities.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Within template argument deduction for a conversion function, we are matching with an argument type f...
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...
unsigned getNumExplicitArgs() const
Get the number of explicitly-specified arguments.
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 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
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false) const
C++11 deduced auto type.
unsigned CallArgIndex
The index of the function argument that caused a deduction failure.
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.
This represents a decl that may have a name.
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
static Optional< unsigned > getExpandedPackSize(NamedDecl *Param)
If Param is an expanded parameter pack, get the number of expansions.
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.
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
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
CanQualType UnsignedIntTy
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