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;
359 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
360 ParamType = Expansion->getPattern();
378 QualType ValueType,
bool DeducedFromArrayBound, TemplateDeductionInfo &Info,
379 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
381 S, TemplateParams, NTTP,
383 DeducedFromArrayBound),
384 ValueType, Info, Deduced);
392 TemplateDeductionInfo &Info,
393 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
397 NullPtrType, CK_NullToPointer)
401 Value->
getType(), Info, Deduced);
411 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
414 Value->
getType(), Info, Deduced);
424 TemplateDeductionInfo &Info,
425 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
437 TemplateDeductionInfo &Info,
438 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
447 = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
449 if (TempParam->getDepth() != Info.getDeducedDepth())
454 Deduced[TempParam->getIndex()],
456 if (Result.isNull()) {
457 Info.Param = TempParam;
458 Info.FirstArg = Deduced[TempParam->getIndex()];
459 Info.SecondArg = NewDeduced;
463 Deduced[TempParam->getIndex()] = Result;
500 TemplateDeductionInfo &Info,
501 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
502 assert(Arg.
isCanonical() &&
"Argument type must be canonical");
506 = dyn_cast<TemplateSpecializationType>(Arg)) {
511 SpecArg->getTemplateName(),
521 SpecArg->template_arguments(), Info, Deduced,
562 case Type::TypeOfExpr:
564 case Type::DependentName:
566 case Type::UnresolvedUsing:
567 case Type::TemplateTypeParm:
570 case Type::ConstantArray:
571 case Type::IncompleteArray:
572 case Type::VariableArray:
573 case Type::DependentSizedArray:
575 cast<ArrayType>(T)->getElementType());
583 static std::pair<unsigned, unsigned>
586 return std::make_pair(TTP->getDepth(), TTP->getIndex());
589 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
596 static std::pair<unsigned, unsigned>
600 return std::make_pair(TTP->getDepth(), TTP->getIndex());
639 class PackDeductionScope {
644 :
S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
647 unsigned NumPartialPackArgs = 0;
648 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
650 if (
auto *Partial =
Scope->getPartiallySubstitutedPack(
651 &PartialPackArgs, &NumPartialPackArgs))
657 llvm::SmallBitVector SawIndices(TemplateParams->
size());
659 auto AddPack = [&](
unsigned Index) {
660 if (SawIndices[Index])
662 SawIndices[Index] =
true;
667 Pack.
Saved = Deduced[Index];
670 Packs.push_back(Pack);
676 for (
unsigned I = 0, N = Unexpanded.size();
I != N; ++
I) {
677 unsigned Depth, Index;
682 assert(!Packs.empty() &&
"Pack expansion without unexpanded packs?");
686 IsPartiallyExpanded =
688 PartialPackDepthIndex ==
692 if (IsPartiallyExpanded)
693 PackElements += NumPartialPackArgs;
699 llvm::SmallBitVector
Used(TemplateParams->
size());
702 for (
int Index =
Used.find_first(); Index != -1;
703 Index =
Used.find_next(Index))
708 for (
auto &Pack : Packs) {
715 if (PartialPackDepthIndex ==
717 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
726 if (Pack.New.size() > PackElements)
727 Deduced[Pack.Index] = Pack.New[PackElements];
732 ~PackDeductionScope() {
733 for (
auto &Pack : Packs)
739 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
742 void nextPackElement() {
746 for (
auto &Pack : Packs) {
748 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
749 while (Pack.New.size() < PackElements)
751 if (Pack.New.size() == PackElements)
752 Pack.New.push_back(DeducedArg);
754 Pack.New[PackElements] = DeducedArg;
755 DeducedArg = Pack.New.size() > PackElements + 1
756 ? Pack.New[PackElements + 1]
769 for (
auto &Pack : Packs) {
771 Deduced[Pack.Index] = Pack.Saved;
775 if (PackElements && Pack.New.empty()) {
776 if (Pack.DeferredDeduction.isNull()) {
783 NewPack = Pack.DeferredDeduction;
785 }
else if (Pack.New.empty()) {
791 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
799 Pack.New[0].wasDeducedFromArrayBound());
805 if (Pack.Outer->DeferredDeduction.isNull()) {
808 Pack.Outer->DeferredDeduction = NewPack;
811 Loc = &Pack.Outer->DeferredDeduction;
813 Loc = &Deduced[Pack.Index];
822 if (!Result.
isNull() && !Pack.DeferredDeduction.isNull()) {
824 NewPack = Pack.DeferredDeduction;
847 unsigned PackElements = 0;
848 bool IsPartiallyExpanded =
false;
887 const QualType *Params,
unsigned NumParams,
888 const QualType *Args,
unsigned NumArgs,
889 TemplateDeductionInfo &Info,
890 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
892 bool PartialOrdering =
false) {
894 if (NumParams != NumArgs &&
895 !(NumParams && isa<PackExpansionType>(Params[NumParams - 1])) &&
896 !(NumArgs && isa<PackExpansionType>(Args[NumArgs - 1])))
904 unsigned ArgIdx = 0, ParamIdx = 0;
905 for (; ParamIdx != NumParams; ++ParamIdx) {
913 if (ArgIdx >= NumArgs)
916 if (isa<PackExpansionType>(Args[ArgIdx])) {
926 Params[ParamIdx], Args[ArgIdx],
939 if (ParamIdx + 1 < NumParams)
950 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
952 for (; ArgIdx < NumArgs; ++ArgIdx) {
956 Args[ArgIdx], Info, Deduced,
957 TDF, PartialOrdering))
960 PackScope.nextPackElement();
965 if (
auto Result = PackScope.finish())
970 if (ArgIdx < NumArgs)
983 if (ParamQs == ArgQs)
1020 if (!ParamFunction || !ArgFunction)
1021 return Param == Arg;
1030 return Param == Arg;
1039 if (!Guide || !Guide->isImplicit())
1051 if (ParamRef->getPointeeType().getQualifiers())
1054 return TypeParm && TypeParm->
getIndex() >= FirstInnerIndex;
1087 TemplateDeductionInfo &Info,
1088 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1090 bool PartialOrdering,
1091 bool DeducedFromArrayBound) {
1100 = dyn_cast<PackExpansionType>(Arg))
1101 Arg = ArgExpansion->getPattern();
1103 if (PartialOrdering) {
1185 TDF &= ~TDF_TopLevelParameterTypeList;
1203 Info.getDeducedDepth() != TemplateTypeParm->getDepth())
1206 unsigned Index = TemplateTypeParm->getIndex();
1207 bool RecanonicalizeArg =
false;
1211 if (isa<ArrayType>(Arg)) {
1216 RecanonicalizeArg =
true;
1224 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1230 assert(TemplateTypeParm->getDepth() == Info.getDeducedDepth() &&
1231 "saw template type parameter with wrong depth");
1252 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1269 if (RecanonicalizeArg)
1277 Info.Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1278 Info.FirstArg = Deduced[Index];
1279 Info.SecondArg = NewDeduced;
1283 Deduced[Index] = Result;
1295 if (isa<SubstTemplateTypeParmPackType>(Param))
1329 : ParamUnqualType == ArgUnqualType;
1336 #define NON_CANONICAL_TYPE(Class, Base) \
1337 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class);
1338 #define TYPE(Class, Base)
1339 #include "clang/AST/TypeNodes.def"
1341 case Type::TemplateTypeParm:
1342 case Type::SubstTemplateTypeParmPack:
1343 llvm_unreachable(
"Type nodes handled above");
1348 case Type::VariableArray:
1350 case Type::FunctionNoProto:
1353 case Type::ObjCObject:
1354 case Type::ObjCInterface:
1355 case Type::ObjCObjectPointer: {
1359 if (TDF & TDF_IgnoreQualifiers) {
1371 cast<ComplexType>(Param)->getElementType(),
1372 ComplexArg->getElementType(),
1373 Info, Deduced, TDF);
1381 cast<AtomicType>(Param)->getValueType(),
1382 AtomicArg->getValueType(),
1383 Info, Deduced, TDF);
1388 case Type::Pointer: {
1401 cast<PointerType>(Param)->getPointeeType(),
1403 Info, Deduced, SubTDF);
1407 case Type::LValueReference: {
1414 cast<LValueReferenceType>(Param)->getPointeeType(),
1419 case Type::RValueReference: {
1426 cast<RValueReferenceType>(Param)->getPointeeType(),
1432 case Type::IncompleteArray: {
1435 if (!IncompleteArrayArg)
1442 Info, Deduced, SubTDF);
1446 case Type::ConstantArray: {
1449 if (!ConstantArrayArg)
1455 return Sema::TDK_NonDeducedMismatch;
1461 Info, Deduced, SubTDF);
1465 case Type::DependentSizedArray: {
1479 Info, Deduced, SubTDF))
1490 assert(NTTP->
getDepth() == Info.getDeducedDepth() &&
1491 "saw non-type template parameter with wrong depth");
1493 = dyn_cast<ConstantArrayType>(ArrayArg)) {
1494 llvm::APSInt Size(ConstantArrayArg->getSize());
1501 = dyn_cast<DependentSizedArrayType>(ArrayArg))
1502 if (DependentArrayArg->getSizeExpr())
1504 DependentArrayArg->getSizeExpr(),
1514 case Type::FunctionProto: {
1518 if (!FunctionProtoArg)
1522 cast<FunctionProtoType>(Param);
1529 return Sema::TDK_NonDeducedMismatch;
1542 FunctionProtoArg->
getNumParams(), Info, Deduced, SubTDF))
1555 assert(NTTP->getDepth() == Info.getDeducedDepth() &&
1556 "saw non-type template parameter with wrong depth");
1558 llvm::APSInt Noexcept(1);
1569 true, Info, Deduced);
1574 S, TemplateParams, NTTP, ArgNoexceptExpr, Info, Deduced);
1584 case Type::InjectedClassName: {
1587 Param = cast<InjectedClassNameType>(Param)
1588 ->getInjectedSpecializationType();
1589 assert(isa<TemplateSpecializationType>(Param) &&
1590 "injected class name is not a template specialization type");
1599 case Type::TemplateSpecialization: {
1601 cast<TemplateSpecializationType>(Param);
1614 S, TemplateParams, SpecParam, Arg, Info, Deduced);
1637 Deduced = DeducedOrig;
1642 llvm::SmallPtrSet<const RecordType *, 8> Visited;
1644 ToVisit.push_back(RecordT);
1645 bool Successful =
false;
1647 while (!ToVisit.empty()) {
1649 const RecordType *NextT = ToVisit.pop_back_val();
1652 if (!Visited.insert(NextT).second)
1657 if (NextT != RecordT) {
1658 TemplateDeductionInfo BaseInfo(Info.getLocation());
1661 QualType(NextT, 0), BaseInfo, Deduced);
1673 std::swap(SuccessfulDeduced, Deduced);
1675 Info.Param = BaseInfo.Param;
1676 Info.FirstArg = BaseInfo.FirstArg;
1677 Info.SecondArg = BaseInfo.SecondArg;
1680 Deduced = DeducedOrig;
1685 for (
const auto &
Base : Next->
bases()) {
1686 assert(
Base.getType()->isRecordType() &&
1687 "Base class that isn't a record?");
1693 std::swap(SuccessfulDeduced, Deduced);
1709 case Type::MemberPointer: {
1718 false, Info.getLocation());
1722 false, Info.getLocation());
1729 TDF & TDF_IgnoreQualifiers))
1734 QualType(MemPtrArg->getClass(), 0),
1736 TDF & TDF_IgnoreQualifiers);
1744 case Type::BlockPointer: {
1760 case Type::ExtVector: {
1761 const ExtVectorType *VectorParam = cast<ExtVectorType>(Param);
1762 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1764 if (VectorParam->
getNumElements() != VectorArg->getNumElements())
1765 return Sema::TDK_NonDeducedMismatch;
1770 VectorArg->getElementType(),
1771 Info, Deduced, TDF);
1775 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1783 VectorArg->getElementType(),
1784 Info, Deduced, TDF);
1793 case Type::DependentSizedExtVector: {
1795 = cast<DependentSizedExtVectorType>(Param);
1797 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1802 VectorArg->getElementType(),
1803 Info, Deduced, TDF))
1813 ArgSize = VectorArg->getNumElements();
1823 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1828 VectorArg->getElementType(),
1829 Info, Deduced, TDF))
1839 VectorArg->getSizeExpr(),
1846 case Type::TypeOfExpr:
1848 case Type::DependentName:
1849 case Type::UnresolvedUsing:
1850 case Type::Decltype:
1851 case Type::UnaryTransform:
1853 case Type::DeducedTemplateSpecialization:
1854 case Type::DependentTemplateSpecialization:
1855 case Type::PackExpansion:
1861 llvm_unreachable(
"Invalid Type Class!");
1869 TemplateDeductionInfo &Info,
1870 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
1879 llvm_unreachable(
"Null template argument in parameter list");
1887 Info.FirstArg = Param;
1888 Info.SecondArg = Arg;
1896 Info.FirstArg = Param;
1897 Info.SecondArg = Arg;
1901 llvm_unreachable(
"caller should handle pack expansions");
1908 Info.FirstArg = Param;
1909 Info.SecondArg = Arg;
1917 Info.FirstArg = Param;
1918 Info.SecondArg = Arg;
1926 Info.FirstArg = Param;
1927 Info.SecondArg = Arg;
1932 Info.FirstArg = Param;
1933 Info.SecondArg = Arg;
1937 Info.FirstArg = Param;
1938 Info.SecondArg = Arg;
1963 Info.FirstArg = Param;
1964 Info.SecondArg = Arg;
1972 llvm_unreachable(
"Argument packs should be expanded by the caller!");
1975 llvm_unreachable(
"Invalid TemplateArgument Kind!");
1988 if (ArgIdx == Args.size())
1995 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
1998 return ArgIdx < Args.size();
2004 bool FoundPackExpansion =
false;
2005 for (
const auto &A : Args) {
2006 if (FoundPackExpansion)
2012 if (A.isPackExpansion())
2013 FoundPackExpansion =
true;
2021 ArrayRef<TemplateArgument> Params,
2022 ArrayRef<TemplateArgument> Args,
2023 TemplateDeductionInfo &Info,
2024 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2025 bool NumberOfArgumentsMustMatch) {
2037 unsigned ArgIdx = 0, ParamIdx = 0;
2039 if (!Params[ParamIdx].isPackExpansion()) {
2044 return NumberOfArgumentsMustMatch
2051 if (Args[ArgIdx].isPackExpansion())
2057 Params[ParamIdx], Args[ArgIdx],
2080 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
2092 PackScope.nextPackElement();
2097 if (
auto Result = PackScope.finish())
2109 TemplateDeductionInfo &Info,
2110 SmallVectorImpl<DeducedTemplateArgument> &Deduced) {
2112 ArgList.
asArray(), Info, Deduced,
2120 bool PackExpansionMatchesPack =
false) {
2131 llvm_unreachable(
"Comparing NULL template argument");
2154 llvm::FoldingSetNodeID XID, YID;
2167 XP != XPEnd; ++XP, ++YP)
2174 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2195 llvm_unreachable(
"Can't get a NULL template argument here");
2249 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2259 TemplateDeductionInfo &Info,
2261 SmallVectorImpl<TemplateArgument> &Output) {
2263 unsigned ArgumentPackIndex) {
2291 "deduced nested pack");
2298 diag::err_template_arg_deduced_incomplete_pack)
2302 if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
2306 PackedArgsBuilder.push_back(Output.pop_back_val());
2311 if (PackedArgsBuilder.empty()) {
2316 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2320 if (Inst.isInvalid() ||
2321 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
2322 NTTP->getDeclName()).isNull())
2324 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2340 return ConvertArg(Arg, 0);
2346 template<
typename TemplateDeclT>
2348 Sema &
S, TemplateDeclT *Template,
bool IsDeduced,
2349 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2350 TemplateDeductionInfo &Info, SmallVectorImpl<TemplateArgument> &
Builder,
2352 unsigned NumAlreadyConverted = 0,
bool PartialOverloading =
false) {
2355 for (
unsigned I = 0, N = TemplateParams->
size();
I != N; ++
I) {
2358 if (!Deduced[
I].isNull()) {
2359 if (
I < NumAlreadyConverted) {
2364 CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
2367 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2374 Builder.push_back(Deduced[
I]);
2382 IsDeduced, Builder)) {
2401 unsigned NumExplicitArgs;
2402 if (CurrentInstantiationScope &&
2403 CurrentInstantiationScope->getPartiallySubstitutedPack(
2404 &ExplicitArgs, &NumExplicitArgs) == Param) {
2406 llvm::makeArrayRef(ExplicitArgs, NumExplicitArgs)));
2410 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2416 Info, IsDeduced, Builder)) {
2427 bool HasDefaultArg =
false;
2430 assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
2431 isa<VarTemplatePartialSpecializationDecl>(Template));
2442 const_cast<NamedDecl *>(TemplateParams->
getParam(
I)));
2444 if (PartialOverloading)
break;
2455 const_cast<NamedDecl *>(TemplateParams->
getParam(
I)));
2468 if (
auto *DC = dyn_cast<DeclContext>(D))
2474 static constexpr
bool value =
false;
2478 static constexpr
bool value =
true;
2482 static constexpr
bool value =
true;
2486 template <
typename T>
2487 static typename std::enable_if<IsPartialSpecialization<T>::value,
2490 Sema &
S, T *Partial,
bool IsPartialOrdering,
2492 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2493 TemplateDeductionInfo &Info) {
2506 S, Partial, IsPartialOrdering, Deduced, Info, Builder))
2513 Info.reset(DeducedArgumentList);
2521 auto *Template = Partial->getSpecializedTemplate();
2523 Partial->getTemplateArgsAsWritten();
2532 unsigned ArgIdx = InstArgs.
size(), ParamIdx = ArgIdx;
2533 if (ParamIdx >= Partial->getTemplateParameters()->size())
2534 ParamIdx = Partial->getTemplateParameters()->size() - 1;
2537 Partial->getTemplateParameters()->getParam(ParamIdx));
2539 Info.FirstArg = PartialTemplateArgs[ArgIdx].
getArgument();
2545 false, ConvertedInstArgs))
2549 for (
unsigned I = 0,
E = TemplateParams->
size();
I !=
E; ++
I) {
2553 Info.FirstArg = TemplateArgs[
I];
2554 Info.SecondArg = InstArg;
2571 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
2572 TemplateDeductionInfo &Info) {
2585 S, Template, PartialOrdering, Deduced, Info, Builder))
2590 for (
unsigned I = 0,
E = TemplateParams->
size();
I !=
E; ++
I) {
2595 Info.FirstArg = TemplateArgs[
I];
2596 Info.SecondArg = InstArg;
2635 TemplateArgs, Info, Deduced))
2641 if (Inst.isInvalid())
2648 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2676 TemplateArgs, Info, Deduced))
2682 if (Inst.isInvalid())
2689 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2696 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
2737 if (ExplicitTemplateArgs.
size() == 0) {
2741 ParamTypes.push_back(
P->getType());
2744 *FunctionType = Function->
getType();
2765 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
2767 if (Inst.isInvalid())
2771 ExplicitTemplateArgs,
true, Builder,
false) ||
2773 unsigned Index = Builder.size();
2774 if (Index >= TemplateParams->
size())
2775 Index = TemplateParams->
size() - 1;
2784 Info.
reset(ExplicitArgumentList);
2796 for (
unsigned I = 0, N = Builder.size();
I != N; ++
I) {
2809 assert(Proto &&
"Function template does not have a prototype?");
2824 ParamTypes,
nullptr, ExtParamInfos))
2837 unsigned ThisTypeQuals = 0;
2839 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
2841 ThisTypeQuals = Method->getTypeQualifiers();
2861 ParamTypes,
nullptr, ExtParamInfos))
2874 Function->
getLocation(), EPI.ExceptionSpec, ExceptionStorage,
2896 Deduced.reserve(TemplateParams->
size());
2897 for (
unsigned I = 0, N = ExplicitArgumentList->
size();
I != N; ++
I) {
2902 Deduced.push_back(Arg);
2961 if (AQuals == DeducedAQuals) {
2979 bool ObjCLifetimeConversion =
false;
2983 ObjCLifetimeConversion) ||
3026 unsigned ParamIdx) {
3029 if (PD->isParameterPack()) {
3030 unsigned NumExpansions =
3032 if (Idx + NumExpansions > ParamIdx)
3033 return ParamIdx - Idx;
3034 Idx += NumExpansions;
3036 if (Idx == ParamIdx)
3042 llvm_unreachable(
"parameter index would not be produced from template");
3054 unsigned NumExplicitlySpecified,
FunctionDecl *&Specialization,
3057 bool PartialOverloading, llvm::function_ref<
bool()> CheckNonDependent) {
3067 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3069 if (Inst.isInvalid())
3079 *
this, FunctionTemplate,
true, Deduced, Info, Builder,
3081 PartialOverloading))
3093 if (CheckNonDependent())
3099 Info.
reset(DeducedArgumentList);
3107 Specialization = cast_or_null<FunctionDecl>(
3129 if (OriginalCallArgs) {
3134 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
3135 for (
unsigned I = 0, N = OriginalCallArgs->size();
I != N; ++
I) {
3138 auto ParamIdx = OriginalArg.
ArgIdx;
3156 if (CacheEntry.
isNull()) {
3165 DeducedA = CacheEntry;
3183 SuppressedDiagnosticsMap::iterator
3203 if (Method->isInstance()) {
3223 bool ParamWasReference) {
3231 if (ParamWasReference)
3276 TemplateDeductionInfo Info(Ovl->
getNameLoc());
3278 Specialization, Info))
3286 if (ArgType.isNull())
continue;
3290 ArgType->isFunctionType())
3306 Deduced(TemplateParams->
size());
3307 TemplateDeductionInfo Info(Ovl->
getNameLoc());
3310 ArgType, Info, Deduced, TDF);
3311 if (Result)
continue;
3346 ParamRefType !=
nullptr);
3407 (isa<PointerType>(ParamType) &&
3421 QualType ParamType,
Expr *Arg, TemplateDeductionInfo &Info,
3422 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3423 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3424 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF);
3431 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3432 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
unsigned ArgIdx,
3448 ElTy = ArrTy->getElementType();
3459 S, TemplateParams, 0, ElTy,
E, Info, Deduced, OriginalCallArgs,
true,
3467 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
3478 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
3479 true, Info, Deduced))
3491 QualType ParamType,
Expr *Arg, TemplateDeductionInfo &Info,
3492 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
3493 SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
3494 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF) {
3496 QualType OrigParamType = ParamType;
3501 S, TemplateParams, FirstInnerIndex, ParamType, ArgType, Arg, TDF))
3507 Deduced, OriginalCallArgs, ArgIdx, TDF);
3514 OriginalCallArgs.push_back(
3517 ArgType, Info, Deduced, TDF);
3549 bool PartialOverloading,
3581 unsigned NumExplicitlySpecified = 0;
3582 if (ExplicitTemplateArgs) {
3585 *ExplicitTemplateArgs,
3593 NumExplicitlySpecified = Deduced.size();
3596 for (
unsigned I = 0;
I != NumParams; ++
I)
3603 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx) {
3613 *
this, TemplateParams, FirstInnerIndex, ParamType, Args[ArgIdx], Info, Deduced,
3614 OriginalCallArgs,
false, ArgIdx, 0);
3618 Deduced.resize(TemplateParams->
size());
3620 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
3621 ParamIdx != NumParamTypes; ++ParamIdx) {
3622 QualType ParamType = ParamTypes[ParamIdx];
3626 if (!ParamExpansion) {
3628 if (ArgIdx >= Args.size())
3631 ParamTypesForArgChecking.push_back(ParamType);
3632 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++))
3639 PackDeductionScope PackScope(*
this, TemplateParams, Deduced, Info,
3658 if (ParamIdx + 1 == NumParamTypes) {
3659 for (; ArgIdx < Args.size(); PackScope.nextPackElement(), ++ArgIdx) {
3660 ParamTypesForArgChecking.push_back(ParamPattern);
3661 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx))
3669 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
3670 for (
unsigned I = 0;
I != *NumExpansions && ArgIdx < Args.size();
3672 ParamTypesForArgChecking.push_back(ParamPattern);
3675 PackScope.nextPackElement();
3682 if (
auto Result = PackScope.finish())
3687 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
3688 &OriginalCallArgs, PartialOverloading,
3689 [&]() {
return CheckNonDependent(ParamTypesForArgChecking); });
3694 bool AdjustExceptionSpec) {
3695 if (ArgFunctionType.
isNull())
3696 return ArgFunctionType;
3704 bool Rebuild =
false;
3707 if (EPI.ExtInfo.getCC() != CC) {
3708 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
3713 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
3714 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
3719 ArgFunctionTypeP->hasExceptionSpec())) {
3725 return ArgFunctionType;
3728 ArgFunctionTypeP->getParamTypes(), EPI);
3763 bool IsAddressOfFunction) {
3775 unsigned NumExplicitlySpecified = 0;
3777 if (ExplicitTemplateArgs) {
3780 *ExplicitTemplateArgs,
3781 Deduced, ParamTypes,
3782 &FunctionType, Info))
3785 NumExplicitlySpecified = Deduced.size();
3791 if (!IsAddressOfFunction)
3800 Deduced.resize(TemplateParams->
size());
3806 bool HasDeducedReturnType =
false;
3807 if (
getLangOpts().CPlusPlus14 && IsAddressOfFunction &&
3810 HasDeducedReturnType =
true;
3813 if (!ArgFunctionType.
isNull()) {
3819 FunctionType, ArgFunctionType,
3820 Info, Deduced, TDF))
3826 NumExplicitlySpecified,
3827 Specialization, Info))
3832 if (HasDeducedReturnType &&
3839 auto *SpecializationFPT =
3851 if (!IsAddressOfFunction)
3858 if (!ArgFunctionType.
isNull()) {
3859 if (IsAddressOfFunction &&
3865 if (!IsAddressOfFunction &&
3883 assert(AutoResultType->getContainedAutoType());
3885 TypeToReplaceAutoWith);
3898 SmallVectorImpl<DeducedTemplateArgument> &DeducedArguments,
3899 QualType ReturnTypeOfDestFunctionPtr,
3900 TemplateDeductionInfo &TDInfo,
3907 QualType CallOpResultType = CallOpGeneric->getReturnType();
3908 const bool GenericLambdaCallOperatorHasDeducedReturnType =
3912 CallOpGeneric->getDescribedFunctionTemplate();
3920 0, CallOpSpecialized, TDInfo))
3924 if (GenericLambdaCallOperatorHasDeducedReturnType &&
3933 ReturnTypeOfDestFunctionPtr))
3942 getLambdaStaticInvoker()->getDescribedFunctionTemplate();
3948 InvokerSpecialized, TDInfo);
3950 "If the call operator succeeded so should the invoker!");
3953 if (GenericLambdaCallOperatorHasDeducedReturnType &&
3967 TypeToReplaceAutoWith, S);
3969 TypeToReplaceAutoWith, S);
4019 assert(!A->
isReferenceType() &&
"Reference types were handled above");
4056 Deduced.resize(TemplateParams->
size());
4080 P, A, Info, Deduced, TDF))
4089 ConversionSpecialized, Info);
4090 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
4102 "Can only convert from lambda to ptr-to-function");
4105 const QualType DestFunctionPtrReturnType = ToFunType->getReturnType();
4117 Specialization, Deduced, DestFunctionPtrReturnType,
4151 bool IsAddressOfFunction) {
4154 IsAddressOfFunction);
4160 class SubstituteDeducedTypeTransform :
4166 bool UseTypeSugar =
true)
4168 Replacement(Replacement), UseTypeSugar(UseTypeSugar) {}
4172 "unexpected unsugared replacement kind");
4190 return TransformDesugared(TLB, TL);
4192 QualType Result = SemaRef.Context.getAutoType(
4199 QualType TransformDeducedTemplateSpecializationType(
4202 return TransformDesugared(TLB, TL);
4204 QualType Result = SemaRef.Context.getDeducedTemplateSpecializationType(
4222 return TransformType(TLB, TL);
4231 DependentDeductionDepth);
4255 Init = NonPlaceholder.
get();
4258 if (!DependentDeductionDepth &&
4260 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4261 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4266 unsigned Depth = DependentDeductionDepth.getValueOr(0);
4272 if (AT->isDecltypeAuto()) {
4273 if (isa<InitListExpr>(Init)) {
4283 Result = SubstituteDeducedTypeTransform(*
this, Deduced).Apply(Type);
4288 if (isa<InitListExpr>(Init)) {
4305 Loc, Loc, TemplParamPtr, Loc,
nullptr);
4308 SubstituteDeducedTypeTransform(*
this, TemplArg,
false)
4310 assert(!FuncParam.
isNull() &&
4311 "substituting template parameter for 'auto' failed");
4323 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4324 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4340 for (
unsigned i = 0, e = InitList->
getNumInits(); i < e; ++i) {
4342 *
this, TemplateParamsSt.get(), 0, TemplArg, InitList->
getInit(i),
4343 Info, Deduced, OriginalCallArgs,
true,
4345 return DeductionFailed();
4349 Diag(Loc, diag::err_auto_bitfield);
4354 *
this, TemplateParamsSt.get(), 0, FuncParam, Init, Info, Deduced,
4355 OriginalCallArgs,
false, 0, 0))
4356 return DeductionFailed();
4361 return DeductionFailed();
4367 if (DeducedType.
isNull())
4371 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(Type);
4379 assert((
bool)InitList == OriginalArg.DecomposedParam &&
4380 "decomposed non-init-list in auto deduction?");
4383 return DeductionFailed();
4394 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4395 .TransformType(TypeWithAuto);
4402 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4403 .TransformType(TypeWithAuto);
4408 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
4410 .TransformType(TypeWithAuto);
4414 if (isa<InitListExpr>(Init))
4417 ? diag::err_init_capture_deduction_failure_from_init_list
4418 : diag::err_auto_var_deduction_failure_from_init_list)
4422 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
4423 : diag::err_auto_var_deduction_failure)
4437 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
4441 return StillUndeduced;
4448 SmallVectorImpl<QualType> &ArgTypes) {
4463 ArgTypes.push_back(ArgTy);
4473 unsigned NumCallArguments1) {
4479 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
4482 Deduced.resize(TemplateParams->
size());
4487 TemplateDeductionInfo Info(Loc);
4513 unsigned NumComparedArguments = NumCallArguments1;
4515 if (!Method2 && Method1 && !Method1->
isStatic()) {
4518 ++NumComparedArguments;
4519 }
else if (!Method1 && Method2 && !Method2->
isStatic()) {
4526 Args2.insert(Args2.end(), Proto2->param_type_begin(),
4527 Proto2->param_type_end());
4532 if (Args1.size() > NumComparedArguments)
4533 Args1.resize(NumComparedArguments);
4534 if (Args2.size() > NumComparedArguments)
4535 Args2.resize(NumComparedArguments);
4537 Args1.data(), Args1.size(), Info, Deduced,
4548 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
4571 unsigned ArgIdx = 0, NumArgs = Deduced.size();
4572 for (; ArgIdx != NumArgs; ++ArgIdx)
4573 if (Deduced[ArgIdx].isNull())
4580 if (ArgIdx == NumArgs) {
4587 llvm::SmallBitVector UsedParameters(TemplateParams->
size());
4590 for (
unsigned I = 0, N = Args2.size();
I != N; ++
I)
4598 TemplateParams->
getDepth(), UsedParameters);
4608 for (; ArgIdx != NumArgs; ++ArgIdx)
4611 if (Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
4630 while (--NumParams > 0) {
4661 unsigned NumCallArguments1,
4662 unsigned NumCallArguments2) {
4668 if (Better1 != Better2)
4669 return Better1 ? FT1 : FT2;
4671 if (!Better1 && !Better2)
4679 if (Variadic1 != Variadic2)
4680 return Variadic1? FT2 : FT1;
4726 bool Complain,
QualType TargetType) {
4727 if (SpecBegin == SpecEnd) {
4729 Diag(Loc, NoneDiag);
4735 if (SpecBegin + 1 == SpecEnd)
4742 = cast<FunctionDecl>(*Best)->getPrimaryTemplate();
4743 assert(BestTemplate &&
"Not a function template specialization?");
4746 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4747 assert(Challenger &&
"Not a function template specialization?");
4752 BestTemplate = Challenger;
4758 bool Ambiguous =
false;
4761 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4778 Diag(Loc, AmbigDiag);
4783 const auto *FD = cast<FunctionDecl>(*I);
4785 FD->getPrimaryTemplate()->getTemplateParameters(),
4786 *FD->getTemplateSpecializationArgs());
4787 if (!TargetType.
isNull())
4789 Diag((*I)->getLocation(), PD);
4803 template<
typename TemplateLikeDecl>
4805 TemplateLikeDecl *P2,
4806 TemplateDeductionInfo &Info) {
4834 Deduced.resize(P2->getTemplateParameters()->size());
4848 TST1->template_arguments()),
4877 if (Better1 == Better2)
4880 return Better1 ? PS1 : PS2;
4904 "the partial specializations being compared should specialize"
4905 " the same template.");
4917 if (Better1 == Better2)
4920 return Better1 ? PS1 : PS2;
4935 CanonTemplate, PrimaryArgs);
4979 for (
unsigned I = 0, N = P->
size();
I != N; ++
I) {
5017 llvm::SmallBitVector &
Used) {
5020 E = Expansion->getPattern();
5026 E = ICE->getSubExpr();
5028 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
5029 E = Subst->getReplacement();
5061 llvm::SmallBitVector &
Used) {
5068 OnlyDeduced, Depth, Used);
5078 llvm::SmallBitVector &
Used) {
5081 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
5082 if (TTP->getDepth() ==
Depth)
5083 Used[TTP->getIndex()] =
true;
5102 llvm::SmallBitVector &
Used) {
5114 cast<PointerType>(T)->getPointeeType(),
5120 case Type::BlockPointer:
5122 cast<BlockPointerType>(T)->getPointeeType(),
5128 case Type::LValueReference:
5129 case Type::RValueReference:
5131 cast<ReferenceType>(T)->getPointeeType(),
5137 case Type::MemberPointer: {
5142 OnlyDeduced, Depth, Used);
5146 case Type::DependentSizedArray:
5148 cast<DependentSizedArrayType>(T)->getSizeExpr(),
5149 OnlyDeduced, Depth, Used);
5153 case Type::ConstantArray:
5154 case Type::IncompleteArray:
5156 cast<ArrayType>(T)->getElementType(),
5157 OnlyDeduced, Depth, Used);
5161 case Type::ExtVector:
5163 cast<VectorType>(T)->getElementType(),
5164 OnlyDeduced, Depth, Used);
5167 case Type::DependentSizedExtVector: {
5169 = cast<DependentSizedExtVectorType>(T);
5177 case Type::FunctionProto: {
5189 case Type::TemplateTypeParm: {
5196 case Type::SubstTemplateTypeParmPack: {
5198 = cast<SubstTemplateTypeParmPackType>(T);
5201 OnlyDeduced, Depth, Used);
5207 case Type::InjectedClassName:
5208 T = cast<InjectedClassNameType>(T)->getInjectedSpecializationType();
5211 case Type::TemplateSpecialization: {
5213 = cast<TemplateSpecializationType>(T);
5234 cast<ComplexType>(T)->getElementType(),
5235 OnlyDeduced, Depth, Used);
5241 cast<AtomicType>(T)->getValueType(),
5242 OnlyDeduced, Depth, Used);
5245 case Type::DependentName:
5248 cast<DependentNameType>(T)->getQualifier(),
5249 OnlyDeduced, Depth, Used);
5252 case Type::DependentTemplateSpecialization: {
5266 = cast<DependentTemplateSpecializationType>(T);
5281 OnlyDeduced, Depth, Used);
5284 case Type::TypeOfExpr:
5287 cast<TypeOfExprType>(T)->getUnderlyingExpr(),
5288 OnlyDeduced, Depth, Used);
5291 case Type::Decltype:
5294 cast<DecltypeType>(T)->getUnderlyingExpr(),
5295 OnlyDeduced, Depth, Used);
5298 case Type::UnaryTransform:
5302 OnlyDeduced, Depth, Used);
5305 case Type::PackExpansion:
5307 cast<PackExpansionType>(T)->getPattern(),
5308 OnlyDeduced, Depth, Used);
5312 case Type::DeducedTemplateSpecialization:
5314 cast<DeducedType>(T)->getDeducedType(),
5315 OnlyDeduced, Depth, Used);
5319 case Type::VariableArray:
5320 case Type::FunctionNoProto:
5323 case Type::ObjCInterface:
5324 case Type::ObjCObject:
5325 case Type::ObjCObjectPointer:
5326 case Type::UnresolvedUsing:
5328 #define TYPE(Class, Base)
5329 #define ABSTRACT_TYPE(Class, Base)
5330 #define DEPENDENT_TYPE(Class, Base)
5331 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
5332 #include "clang/AST/TypeNodes.def"
5344 llvm::SmallBitVector &
Used) {
5345 switch (TemplateArg.
getKind()) {
5391 bool OnlyDeduced,
unsigned Depth,
5392 llvm::SmallBitVector &
Used) {
5401 for (
unsigned I = 0, N = TemplateArgs.
size();
I != N; ++
I)
5410 llvm::SmallBitVector &Deduced) {
5414 Deduced.resize(TemplateParams->
size());
5419 true, TemplateParams->
getDepth(), Deduced);
5430 llvm::SmallBitVector Deduced(TemplateParams->
size());
5434 return Deduced.any();
QualType BuildStdInitializerList(QualType Element, SourceLocation Loc)
Looks for the std::initializer_list template and instantiates it with Element, or emits an error if i...
unsigned getNumElements() const
bool hasObjCGCAttr() const
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
ExprResult BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
Construct a new expression that refers to the given integral template argument with the given source-...
Defines the clang::ASTContext interface.
unsigned getNumInits() const
SourceLocation getEnd() const
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
Expr * getSizeExpr() const
The null pointer literal (C++11 [lex.nullptr])
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y)
Verify that the given, deduced template arguments are compatible.
unsigned getDepth() const
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
SuppressedDiagnosticsMap SuppressedDiagnostics
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
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 isLambdaConversionOperator(CXXConversionDecl *C)
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
bool isMemberPointerType() const
Template argument deduction was successful.
const FunctionProtoType * ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT)
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.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const LangOptions & getLangOpts() const
Checking non-dependent argument conversions failed.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
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.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Provides information about an attempted template argument deduction, whose success or failure was des...
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
unsigned getNumArgs() const
Retrieve the number of template arguments.
unsigned getIntWidth(QualType T) const
bool SubstParmTypes(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const FunctionProtoType::ExtParameterInfo *ExtParamInfos, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< QualType > &ParamTypes, SmallVectorImpl< ParmVarDecl * > *OutParams, ExtParameterInfoBuilder &ParamInfos)
Substitute the given template arguments into the given set of parameters, producing the set of parame...
void setObjCLifetime(ObjCLifetime type)
The template argument is an expression, and we've not resolved it to one of the other forms yet...
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments...
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
bool isRecordType() 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...
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
QualType getPointeeType() const
The base class of the type hierarchy.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to 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...
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
NamedDecl * getParam(unsigned Idx)
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
A container of type source information.
unsigned getIndex() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
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...
void SetPartiallySubstitutedPack(NamedDecl *Pack, const TemplateArgument *ExplicitArgs, unsigned NumExplicitArgs)
Note that the given parameter pack has been partially substituted via explicit specification of templ...
const llvm::APInt & getSize() const
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.
This file provides some common utility functions for processing Lambda related AST Constructs...
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
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()
ObjCLifetime getObjCLifetime() const
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.
CallingConv getCallConv() const
AutoTypeKeyword getKeyword() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
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>".
Stores a list of template parameters for a TemplateDecl and its derived classes.
void clearSFINAEDiagnostic()
Discard any SFINAE diagnostics.
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...
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...
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.
unsigned getNumArgs() const
Retrieve the number of template arguments.
TemplateParameter Param
The template parameter to which a template argument deduction failure refers.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
The collection of all-type qualifiers we support.
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
Base wrapper for a particular "section" of type source info.
unsigned getNumParams() const
QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, bool AdjustExceptionSpec=false)
Adjust the type ArgFunctionType to match the calling convention, noreturn, and optionally the excepti...
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
QualType getElementType() const
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.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
static TemplateArgument getEmptyPack()
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
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.
ArrayRef< QualType > getParamTypes() const
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
bool isReferenceType() const
QualType getReturnType() const
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
bool isAnyPointerType() const
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.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
unsigned getCVRQualifiers() const
The iterator over UnresolvedSets.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
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...
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(TemplateParameterList *P, TemplateDecl *AArg, SourceLocation Loc)
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Within template argument deduction from overload resolution per C++ [over.over] allow matching functi...
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.
TemplateArgument getArgumentPack() const
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
SourceLocation getLAngleLoc() const
void setNameLoc(SourceLocation Loc)
const LangOptions & getLangOpts() const
bool HasFormOfMemberPointer
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
A convenient class for passing around template argument information.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
QualType getReturnType() const
unsigned getMinRequiredArguments() const
getMinRequiredArguments - Returns the minimum number of arguments needed to call this function...
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, sema::TemplateDeductionInfo &Info)
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
bool IsFunctionConversion(QualType FromType, QualType ToType, QualType &ResultTy)
Determine whether the conversion from FromType to ToType is a valid conversion that strips "noexcept"...
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
Expr * getNoexceptExpr() const
Substitution of the deduced template argument values resulted in an error.
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
RecordDecl * getDecl() const
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Template argument deduction exceeded the maximum template instantiation depth (which has already been...
void MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced)
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.
TypeClass getTypeClass() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
SmallVector< DeducedTemplateArgument, 4 > New
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
QualType OriginalParamType
detail::InMemoryDirectory::const_iterator I
const DependentSizedArrayType * getAsDependentSizedArrayType(QualType T) 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...
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.
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.
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, FunctionDecl *Function, bool Recursive=false, bool DefinitionRequired=false, bool AtEndOfTU=false)
Instantiate the definition of the given function from its template.
A helper class for building up ExtParameterInfos.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
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.
diag_iterator diag_end() const
Returns an iterator at the end of the sequence of suppressed diagnostics.
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
We are substituting explicit template arguments provided for a function template. ...
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.
QualType getParamType(unsigned i) const
Represents a prototype with parameter type info, e.g.
void reset(TemplateArgumentList *NewDeduced)
Provide a new template argument list that contains the results of template argument deduction...
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
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...
param_type_iterator param_type_begin() const
static bool hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate, QualType T)
Template argument deduction did not deduce a value for every template parameter.
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
SourceLocation getTypeSpecStartLoc() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
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...
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
bool isFunctionPointerType() const
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.
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...
const Type * getTypeForDecl() const
unsigned getTypeQualifiers() const
QualType getPointeeType() const
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Expr - This represents one expression.
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...
When performing template argument deduction for a function template, there were too many call argumen...
decls_iterator decls_end() const
Declaration of a template type parameter.
SourceLocation getNameLoc() const
Gets the location of the name.
static DeclContext * getAsDeclContextOrEnclosing(Decl *D)
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
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...
We are substituting template argument determined as part of template argument deduction for either a ...
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...
ExprResult BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc)
Given a non-type template argument that refers to a declaration and the type of its corresponding non...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
diag_iterator diag_begin() const
Returns an iterator at the beginning of the sequence of suppressed diagnostics.
const ParmVarDecl * getParamDecl(unsigned i) const
ArgKind getKind() const
Return the kind of stored template argument.
ExtProtoInfo getExtProtoInfo() const
void completeExprArrayBound(Expr *E)
DeclContext * getDeclContext()
When performing template argument deduction for a function template, there were too few call argument...
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
Represents a C++ template name within the type system.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
ArrayRef< Expr * > inits()
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...
QualType getType() const
Get the type for which this source info wrapper provides information.
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...
static bool TooManyArguments(size_t NumParams, size_t NumArgs, bool PartialOverloading=false)
To be used for checking whether the arguments being passed to function exceeds the number of paramete...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool hasTrailingReturn() const
DeclContext * getParent()
getParent - Returns the containing DeclContext.
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.
Data structure that captures multiple levels of template argument lists for use in template instantia...
bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, bool Diagnose=true)
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
An lvalue reference type, per C++11 [dcl.ref].
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
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 ...
Represents a C++ deduction guide declaration.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
After substituting deduced template arguments, a dependent parameter type did not match the correspon...
QualType getElementType() const
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
Represents a C++ conversion function within a class.
The result type of a method or function.
void removeCVRQualifiers(unsigned mask)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
const TypeClass * getTypePtr() const
Captures a template argument whose value has been deduced via c++ template argument deduction...
bool hasObjCLifetime() const
static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, QualType ArgType)
Determine whether the parameter has qualifiers that are either inconsistent with or a superset of the...
decls_iterator decls_begin() const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
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.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
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...
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.
const ExtParameterInfo * ExtParameterInfos
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
static TemplateParameter makeTemplateParameter(Decl *D)
Helper function to build a TemplateParameter when we don't know its type statically.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool hasSameTemplateName(TemplateName X, TemplateName Y)
Determine whether the given template names refer to the same template.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
unsigned getDeducedDepth() const
The depth of template parameters for which deduction is being performed.
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Template argument deduction failed due to inconsistent cv-qualifiers on a template parameter type tha...
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.
static bool isSameTemplate(TemplateDecl *T1, TemplateDecl *T2)
Determine if the two templates are equivalent.
static QualType getUnderlyingType(const SubRegion *R)
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
Within template argument deduction from a function call, we are matching in a case where we ignore cv...
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
Represents a static or instance method of a struct/union/class.
SourceLocation getNameLoc() const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
ArrayRef< ParmVarDecl * > parameters() const
The declaration was invalid; do nothing.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init)
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
TypeSourceInfo * SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
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 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.
const T * castAs() const
Member-template castAs<specific type>.
static bool isSameDeclaration(Decl *X, Decl *Y)
Determine whether two declaration pointers refer to the same declaration.
CanThrowResult canThrow(const ASTContext &Ctx) const
Determine whether this function type has a non-throwing exception specification.
static bool CheckOriginalCallArgDeduction(Sema &S, Sema::OriginalCallArg OriginalArg, QualType DeducedA)
Check whether the deduced argument type for a call to a function template matches the actual argument...
bool isMemberFunctionPointerType() const
ArrayRef< TemplateArgument > template_arguments() const
An rvalue ref-qualifier was provided (&&).
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
static bool hasPackExpansionBeforeEnd(ArrayRef< TemplateArgument > Args)
Determine whether the given set of template arguments has a pack expansion that is not the last templ...
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
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...
A POD class for pairing a NamedDecl* with an access specifier.
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...
Expr * getSizeExpr() const
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
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 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 ...
QualType getAsType() const
Retrieve the type for a type template argument.
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.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
Qualifiers withoutObjCLifetime() 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.).
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
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.
The template argument is a pack expansion of a template name that was provided for a template templat...
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
bool isInvalidDecl() const
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType)
HandleFunctionTypeMismatch - Gives diagnostic information for differeing function types...
A non-depnedent component of the parameter did not match the corresponding component of the argument...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
OverloadExpr * Expression
Represents a C++11 pack expansion that produces a sequence of expressions.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
param_type_iterator param_type_end() const
bool isNull() const
Determine whether this template argument has no value.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
void setCVRQualifiers(unsigned mask)
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isLValueReferenceType() const
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
No template argument deduction flags, which indicates the strictest results for template argument ded...
Allow non-dependent types to differ, e.g., when performing template argument deduction from a functio...
const TemplateArgument & getArg(unsigned Idx) const
unsigned getDepth() const
Get the nesting depth of the template parameter.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Represents a pointer to an Objective C object.
static bool isForwardingReference(QualType Param, unsigned FirstInnerIndex)
Determine whether a type denotes a forwarding reference.
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.
The template argument was specified in the code or was instantiated with some deduced template argume...
const T * getAs() const
Member-template getAs<specific type>'.
unsigned getTypeQuals() const
TemplateArgumentList * take()
Take ownership of the deduced template argument list.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool isFunctionType() const
ExtVectorType - Extended vector type.
QualType BuildDecltypeType(Expr *E, SourceLocation Loc, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Base for LValueReferenceType and RValueReferenceType.
unsigned getAddressSpace() const
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None)
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
The template argument is a type.
Deduction failed; that's all we know.
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
NestedNameSpecifier * getQualifier() const
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, const MultiLevelTemplateArgumentList &Args)
The template argument is actually a parameter pack.
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
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].
QualType getPointeeType() const
A template argument list.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
const Type * getClass() const
static void SubstAutoWithinFunctionReturnType(FunctionDecl *F, QualType TypeToReplaceAutoWith, Sema &S)
Given a function declaration (e.g.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
bool hasAddressSpace() const
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
Represents a template specialization type whose template cannot be resolved, e.g. ...
bool isObjCObjectPointerType() const
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
The template argument is a template name that was provided for a template template parameter...
Represents a C array with an unspecified size.
static Sema::TemplateDeductionResult SpecializeCorrespondingLambdaCallOperatorAndInvoker(CXXConversionDecl *ConversionSpecialized, SmallVectorImpl< DeducedTemplateArgument > &DeducedArguments, QualType ReturnTypeOfDestFunctionPtr, TemplateDeductionInfo &TDInfo, Sema &S)
Given a specialized conversion operator of a generic lambda create the corresponding specializations ...
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
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.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
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
QualType getParamTypeForDecl() const
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
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)
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
bool isIncompleteArrayType() const
static Decl::Kind getKind(const Decl *D)
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
A reference to a declared variable, function, enum, etc.
Represents a type template specialization; the template must be a class template, a type alias templa...
SourceLocation getRAngleLoc() const
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
QualType getElementType() const
bool hasQualifiers() const
Determine whether this type has any qualifiers.
unsigned CallArgIndex
The index of the function argument that caused a deduction failure.
const Expr * getInit(unsigned Init) 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.
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
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.
bool isParameterPack() const
Whether this declaration is a parameter pack.
SourceLocation getLocation() const
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,.
The template argument was deduced via template argument deduction.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
SourceLocation getLocStart() const LLVM_READONLY
void setType(QualType newType)
void removeAddressSpace()
const TemplateArgument & getArgument() const
brief A function argument from which we performed template argument
The explicitly-specified template arguments were not valid template arguments for the given template...
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
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
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const