45#include "llvm/ADT/APInt.h"
46#include "llvm/ADT/APSInt.h"
47#include "llvm/ADT/ArrayRef.h"
48#include "llvm/ADT/DenseMap.h"
49#include "llvm/ADT/FoldingSet.h"
50#include "llvm/ADT/SmallBitVector.h"
51#include "llvm/ADT/SmallPtrSet.h"
52#include "llvm/ADT/SmallVector.h"
53#include "llvm/Support/Casting.h"
54#include "llvm/Support/Compiler.h"
55#include "llvm/Support/ErrorHandling.h"
56#include "llvm/Support/SaveAndRestore.h"
114using namespace clang;
126 bool *HasDeducedAnyParam);
142 bool OnlyDeduced,
unsigned Depth,
143 llvm::SmallBitVector &
Used);
146 bool OnlyDeduced,
unsigned Level,
147 llvm::SmallBitVector &
Deduced);
153 if (
const auto *IC = dyn_cast<ImplicitCastExpr>(E))
154 E = IC->getSubExpr();
155 else if (
const auto *CE = dyn_cast<ConstantExpr>(E))
156 E = CE->getSubExpr();
157 else if (
const auto *Subst = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
158 E = Subst->getReplacement();
159 else if (
const auto *CCE = dyn_cast<CXXConstructExpr>(E)) {
161 if (CCE->getParenOrBraceRange().isValid())
164 assert(CCE->getNumArgs() >= 1 &&
"implicit construct expr should have 1 arg");
185 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
186 return NTTP->getType();
193 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
194 return NTTP->getDepth();
199 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
200 return NTTP->getIndex();
213 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
219 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
220 return NTTP->isExpandedParameterPack();
225 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Template))
226 return NTTP->getLocation();
230 operator bool()
const {
return Template; }
244 if (
const auto *DRE = dyn_cast<DeclRefExpr>(E))
245 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
246 if (!Depth || NTTP->getDepth() == *Depth)
250 if (
const auto *DTI = dyn_cast<DependentTemplateIdExpr>(E))
251 if (!DTI->getTemplateName().getAsPackIndexingTemplate() &&
252 (!Depth || DTI->getParameter()->getDepth() == *Depth))
253 return DTI->getParameter();
262 return NTTP.getType();
275 X = NX->getUnderlyingDecl();
276 if (
NamedDecl *NY = dyn_cast<NamedDecl>(Y))
277 Y = NY->getUnderlyingDecl();
290 bool AggregateCandidateDeduction =
false) {
303 QualType XType =
X.getNonTypeTemplateArgumentType();
306 if (YType.
isNull() || !Context.hasSameType(XType, YType))
311 switch (
X.getKind()) {
313 llvm_unreachable(
"Non-deduced template arguments handled above");
320 X.wasDeducedFromArrayBound() ||
326 return X.wasDeducedFromArrayBound() ? Y :
X;
340 return X.wasDeducedFromArrayBound() ? Y :
X;
349 X.structurallyEquals(Y)))
357 Context.hasSameTemplateName(
X.getAsTemplate(), Y.
getAsTemplate()))
365 Context.hasSameTemplateName(
X.getAsTemplateOrTemplatePattern(),
377 llvm::FoldingSetNodeID ID1, ID2;
378 X.getAsExpr()->Profile(ID1, Context,
true);
381 return X.wasDeducedFromArrayBound() ? Y :
X;
388 assert(!
X.wasDeducedFromArrayBound());
401 X.getParamTypeForDecl());
438 (!AggregateCandidateDeduction &&
X.pack_size() != Y.
pack_size()))
450 if (Merged.isNull() && !(XA->isNull() && YA->isNull()))
452 NewPack.push_back(Merged);
455 NewPack.push_back(*XA);
465 llvm_unreachable(
"Invalid TemplateArgument Kind!");
478 bool *HasDeducedAnyParam) {
480 "deducing non-type template argument with wrong depth");
504 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
505 ParamType = Expansion->getPattern();
511 ValueType = ValueType.getNonReferenceType();
518 S, TemplateParams, ParamType, ValueType, Info,
Deduced,
532 bool *HasDeducedAnyParam) {
534 S, TemplateParams, NTTP,
536 DeducedFromArrayBound),
548 bool *HasDeducedAnyParam) {
570 bool *HasDeducedAnyParam) {
586 bool *HasDeducedAnyParam) {
598 bool *HasDeducedAnyParam) {
606 if (
auto *TempParam = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
613 unsigned StartPos = 0;
630 Arg, {StartPos, DefaultArguments.drop_front(StartPos)}))
636 Info.
Param = TempParam;
643 if (HasDeducedAnyParam)
644 *HasDeducedAnyParam =
true;
679 const TemplateSpecializationType *LastTST =
nullptr;
681 const TemplateSpecializationType *TST =
682 T->getAs<TemplateSpecializationType>();
685 if (!TST->isSugared())
688 T = TST->desugar().getTypePtr();
697 bool *HasDeducedAnyParam) {
702 TNP = TP->getTemplateName();
711 TP->castAsCanonical<TemplateSpecializationType>()->template_arguments();
713 const auto *TT = P->
castAs<InjectedClassNameType>();
714 TNP = TT->getTemplateName(S.
Context);
715 PResolved = TT->getTemplateArgs(S.
Context);
737 SA->getCanonicalTypeInternal()
738 ->castAs<TemplateSpecializationType>()
739 ->template_arguments();
753 S, TemplateParams, PResolved, AResolved, Info,
Deduced,
761 const auto *TA = A->
getAs<TagType>();
767 TNA = TST->getTemplateName();
769 TNA = TA->getTemplateName(S.
Context);
788 S, TemplateParams, PResolved, AResolved, Info,
Deduced,
794 assert(T->isCanonicalUnqualified());
796 switch (T->getTypeClass()) {
797 case Type::TypeOfExpr:
799 case Type::DependentName:
801 case Type::PackIndexing:
802 case Type::UnresolvedUsing:
803 case Type::TemplateTypeParm:
807 case Type::ConstantArray:
808 case Type::IncompleteArray:
809 case Type::VariableArray:
810 case Type::DependentSizedArray:
823 T->getCanonicalTypeInternal().getTypePtr());
861class PackDeductionScope {
869 bool DeducePackIfNotAlreadyDeduced =
false,
870 bool FinishingDeduction =
false)
871 : S(S), TemplateParams(TemplateParams),
Deduced(
Deduced), Info(Info),
872 DeducePackIfNotAlreadyDeduced(DeducePackIfNotAlreadyDeduced),
873 FinishingDeduction(FinishingDeduction) {
874 unsigned NumNamedPacks = addPacks(Pattern);
875 finishConstruction(NumNamedPacks);
879 PackDeductionScope(Sema &S, TemplateParameterList *TemplateParams,
880 SmallVectorImpl<DeducedTemplateArgument> &
Deduced,
881 TemplateDeductionInfo &Info,
unsigned Index)
882 : S(S), TemplateParams(TemplateParams),
Deduced(
Deduced), Info(Info) {
884 finishConstruction(1);
888 void addPack(
unsigned Index) {
891 DeducedFromEarlierParameter = !
Deduced[Index].isNull();
892 DeducedPack Pack(Index);
893 if (!FinishingDeduction) {
895 Deduced[Index] = TemplateArgument();
903 FixedNumExpansions = ExpandedPackExpansions;
905 Packs.push_back(Pack);
908 unsigned addPacks(TemplateArgument Pattern) {
911 llvm::SmallBitVector SawIndices(TemplateParams->size());
912 llvm::SmallVector<TemplateArgument, 4> ExtraDeductions;
914 auto AddPack = [&](
unsigned Index) {
915 if (SawIndices[Index])
917 SawIndices[Index] =
true;
924 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
925 TemplateParams->getParam(Index))) {
926 if (!NTTP->isExpandedParameterPack())
929 if (
auto *Expansion = dyn_cast<PackExpansionType>(
930 S.Context.getUnconstrainedType(NTTP->getType())))
931 ExtraDeductions.push_back(Expansion->getPattern());
937 auto Collect = [&](TemplateArgument Pattern) {
938 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
939 S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
940 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
941 unsigned Depth, Index;
944 if (isa_and_present<ParmVarDecl>(
945 dyn_cast<NamedDecl *>(Unexpanded[I].first)))
948 std::tie(Depth, Index) = *DI;
952 if (Depth == Info.getDeducedDepth())
960 unsigned NumNamedPacks = Packs.size();
964 while (!ExtraDeductions.empty())
965 Collect(ExtraDeductions.pop_back_val());
967 return NumNamedPacks;
970 void finishConstruction(
unsigned NumNamedPacks) {
972 const TemplateArgument *PartialPackArgs =
nullptr;
973 unsigned NumPartialPackArgs = 0;
974 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
975 if (
auto *Scope = S.CurrentInstantiationScope)
976 if (
auto *Partial = Scope->getPartiallySubstitutedPack(
977 &PartialPackArgs, &NumPartialPackArgs))
983 bool IsExpanded =
true;
984 for (
unsigned I = 0; I != NumNamedPacks; ++I) {
985 if (Packs[I].Index >= Info.getNumExplicitArgs()) {
987 IsPartiallyExpanded =
false;
990 if (PartialPackDepthIndex ==
991 std::make_pair(Info.getDeducedDepth(), Packs[I].Index)) {
992 IsPartiallyExpanded =
true;
1000 if (IsPartiallyExpanded)
1001 PackElements += NumPartialPackArgs;
1002 else if (IsExpanded && FixedNumExpansions)
1003 PackElements += *FixedNumExpansions;
1005 for (
auto &Pack : Packs) {
1006 if (Info.PendingDeducedPacks.size() > Pack.Index)
1007 Pack.Outer = Info.PendingDeducedPacks[Pack.Index];
1009 Info.PendingDeducedPacks.resize(Pack.Index + 1);
1010 Info.PendingDeducedPacks[Pack.Index] = &Pack;
1012 if (PartialPackDepthIndex ==
1013 std::make_pair(Info.getDeducedDepth(), Pack.Index)) {
1014 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
1020 ~PackDeductionScope() {
1021 for (
auto &Pack : Packs)
1022 Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
1027 unsigned PackSize = Packs[0].Saved.pack_size();
1029 if (std::all_of(Packs.begin() + 1, Packs.end(), [&PackSize](
const auto &P) {
1030 return P.Saved.pack_size() == PackSize;
1033 return std::nullopt;
1038 bool isDeducedFromEarlierParameter()
const {
1039 return DeducedFromEarlierParameter;
1044 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
1049 bool hasFixedArity() {
return static_cast<bool>(FixedNumExpansions); }
1054 bool hasNextElement() {
1055 return !FixedNumExpansions || *FixedNumExpansions > PackElements;
1059 void nextPackElement() {
1063 if (!FinishingDeduction) {
1064 for (
auto &Pack : Packs) {
1065 DeducedTemplateArgument &DeducedArg =
Deduced[Pack.Index];
1066 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
1067 while (Pack.New.size() < PackElements)
1068 Pack.New.push_back(DeducedTemplateArgument());
1069 if (Pack.New.size() == PackElements)
1070 Pack.New.push_back(DeducedArg);
1072 Pack.New[PackElements] = DeducedArg;
1073 DeducedArg = Pack.New.size() > PackElements + 1
1074 ? Pack.New[PackElements + 1]
1075 : DeducedTemplateArgument();
1086 if (FinishingDeduction)
1087 return TemplateDeductionResult::Success;
1090 for (
auto &Pack : Packs) {
1092 if (!FinishingDeduction)
1093 Deduced[Pack.Index] = Pack.Saved;
1108 Pack.New.resize(PackElements);
1111 DeducedTemplateArgument NewPack;
1112 if (Pack.New.empty()) {
1116 TemplateArgument *ArgumentPack =
1117 new (S.Context) TemplateArgument[Pack.New.size()];
1118 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
1119 NewPack = DeducedTemplateArgument(
1120 TemplateArgument(llvm::ArrayRef(ArgumentPack, Pack.New.size())),
1126 Pack.New[0].wasDeducedFromArrayBound());
1130 DeducedTemplateArgument *Loc;
1132 if (Pack.Outer->DeferredDeduction.isNull()) {
1135 Pack.Outer->DeferredDeduction = NewPack;
1138 Loc = &Pack.Outer->DeferredDeduction;
1144 DeducedTemplateArgument OldPack = *Loc;
1146 S.Context, OldPack, NewPack, DeducePackIfNotAlreadyDeduced);
1148 Info.AggregateDeductionCandidateHasMismatchedArity =
1154 if (!
Result.isNull() && !Pack.DeferredDeduction.isNull()) {
1156 NewPack = Pack.DeferredDeduction;
1160 NamedDecl *Param = TemplateParams->getParam(Pack.Index);
1163 Info.FirstArg = OldPack;
1164 Info.SecondArg = NewPack;
1165 return TemplateDeductionResult::Inconsistent;
1171 if (*Expansions != PackElements) {
1174 return TemplateDeductionResult::IncompletePack;
1181 return TemplateDeductionResult::Success;
1186 TemplateParameterList *TemplateParams;
1187 SmallVectorImpl<DeducedTemplateArgument> &
Deduced;
1188 TemplateDeductionInfo &Info;
1189 unsigned PackElements = 0;
1190 bool IsPartiallyExpanded =
false;
1191 bool DeducePackIfNotAlreadyDeduced =
false;
1192 bool DeducedFromEarlierParameter =
false;
1193 bool FinishingDeduction =
false;
1197 SmallVector<DeducedPack, 2> Packs;
1207 bool FinishingDeduction, T &&DeductFunc) {
1216 const PackExpansionType *Expansion
1217 = dyn_cast<PackExpansionType>(Params[
ParamIdx]);
1222 if (ArgIdx >= Args.size())
1234 DeductFunc(S, TemplateParams,
ParamIdx, ArgIdx,
1235 Params[
ParamIdx].getUnqualifiedType(),
1236 Args[ArgIdx].getUnqualifiedType(), Info,
Deduced, POK);
1251 QualType Pattern = Expansion->getPattern();
1252 PackDeductionScope PackScope(S, TemplateParams,
Deduced, Info, Pattern,
1254 FinishingDeduction);
1258 if (
ParamIdx + 1 == Params.size() || PackScope.hasFixedArity()) {
1259 for (; ArgIdx < Args.size() && PackScope.hasNextElement(); ++ArgIdx) {
1262 S, TemplateParams,
ParamIdx, ArgIdx,
1267 PackScope.nextPackElement();
1288 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
1289 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
1291 PackScope.nextPackElement();
1297 if (
auto Result = PackScope.finish();
1313 if (ArgIdx < Args.size())
1356 llvm::SmallBitVector *HasDeducedParam) {
1357 return ::DeduceForEachType(
1358 S, TemplateParams, Params, Args, Info,
Deduced, POK,
1364 bool HasDeducedAnyParamCopy =
false;
1366 S, TemplateParams, P, A, Info,
Deduced, TDF, POK,
1367 false, &HasDeducedAnyParamCopy);
1368 if (HasDeducedAnyParam && HasDeducedAnyParamCopy)
1369 *HasDeducedAnyParam =
true;
1370 if (HasDeducedParam && HasDeducedAnyParamCopy)
1371 (*HasDeducedParam)[
ParamIdx] =
true;
1385 if (ParamQs == ArgQs)
1413 return Context.hasSameType(P, A);
1420 return Context.hasSameFunctionTypeIgnoringExceptionSpec(P, A);
1429 if (!Guide || !Guide->isImplicit())
1431 return Guide->getDeducedTemplate()->getTemplateParameters()->size();
1441 if (ParamRef->getPointeeType().getQualifiers())
1444 ParamRef->getPointeeType()->getAsCanonical<TemplateTypeParmType>();
1445 return TypeParm && TypeParm->getIndex() >= FirstInnerIndex;
1473 bool *HasDeducedAnyParam) {
1499 bool HasDeducedAnyParam;
1501 llvm::MapVector<const CXXRecordDecl *, MatchValue> Matches;
1503 auto AddBases = [&Visited, &ToVisit](
const CXXRecordDecl *RD) {
1506 assert(T->isRecordType() &&
"Base class that isn't a record?");
1507 if (Visited.insert(T->getAsCXXRecordDecl()).second)
1508 ToVisit.push_back(T);
1517 while (!ToVisit.empty()) {
1518 QualType NextT = ToVisit.pop_back_val();
1523 bool HasDeducedAnyParamCopy =
false;
1526 &HasDeducedAnyParamCopy);
1532 Matches.insert({RD, {DeducedCopy, HasDeducedAnyParamCopy}});
1543 if (Matches.size() > 1) {
1545 for (
const auto &
Match : Matches)
1546 AddBases(
Match.first);
1550 while (Matches.size() > 1 && !ToVisit.empty()) {
1551 const CXXRecordDecl *RD = ToVisit.pop_back_val()->getAsCXXRecordDecl();
1560 if (Matches.empty())
1562 if (Matches.size() > 1)
1565 std::swap(Matches.front().second.Deduced,
Deduced);
1566 if (
bool HasDeducedAnyParamCopy = Matches.front().second.HasDeducedAnyParam;
1567 HasDeducedAnyParamCopy && HasDeducedAnyParam)
1568 *HasDeducedAnyParam = HasDeducedAnyParamCopy;
1609 bool *HasDeducedAnyParam) {
1613 if (
const auto *AExp = dyn_cast<PackExpansionType>(A))
1614 A = AExp->getPattern();
1709 if (
const auto *TTP = P->
getAsCanonical<TemplateTypeParmType>()) {
1715 unsigned Index = TTP->getIndex();
1742 "saw template type parameter with wrong depth");
1744 "Unresolved overloaded function");
1787 case Decl::TemplateTypeParm:
1790 case Decl::NonTypeTemplateParm:
1793 case Decl::TemplateTemplateParm:
1797 llvm_unreachable(
"unexpected kind");
1805 if (HasDeducedAnyParam)
1806 *HasDeducedAnyParam =
true;
1818 if (P->
getAs<SubstTemplateTypeParmPackType>())
1864#define NON_CANONICAL_TYPE(Class, Base) \
1865 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class);
1866#define TYPE(Class, Base)
1867#include "clang/AST/TypeNodes.inc"
1869 case Type::TemplateTypeParm:
1870 case Type::SubstTemplateTypeParmPack:
1871 case Type::SubstBuiltinTemplatePack:
1872 llvm_unreachable(
"Type nodes handled above");
1884 case Type::VariableArray:
1886 case Type::FunctionNoProto:
1889 case Type::ObjCObject:
1890 case Type::ObjCInterface:
1891 case Type::ObjCObjectPointer:
1901 case Type::Complex: {
1906 S, TemplateParams, CP->getElementType(), CA->getElementType(), Info,
1908 false, HasDeducedAnyParam);
1912 case Type::Atomic: {
1917 S, TemplateParams, PA->getValueType(), AA->getValueType(), Info,
1919 false, HasDeducedAnyParam);
1923 case Type::Pointer: {
1937 false, HasDeducedAnyParam);
1941 case Type::LValueReference: {
1948 S, TemplateParams, RP->getPointeeType(), RA->getPointeeType(), Info,
1950 false, HasDeducedAnyParam);
1954 case Type::RValueReference: {
1961 S, TemplateParams, RP->getPointeeType(), RA->getPointeeType(), Info,
1963 false, HasDeducedAnyParam);
1967 case Type::IncompleteArray: {
1973 assert(IAP &&
"Template parameter not of incomplete array type");
1976 S, TemplateParams, IAP->getElementType(), IAA->getElementType(), Info,
1979 false, HasDeducedAnyParam);
1983 case Type::ConstantArray: {
1987 if (!CAA || CAA->getSize() != CAP->getSize())
1991 S, TemplateParams, CAP->getElementType(), CAA->getElementType(), Info,
1994 false, HasDeducedAnyParam);
1998 case Type::DependentSizedArray: {
2007 S, TemplateParams, DAP->getElementType(), AA->getElementType(),
2010 false, HasDeducedAnyParam);
2023 "saw non-type template parameter with wrong depth");
2024 if (
const auto *CAA = dyn_cast<ConstantArrayType>(AA)) {
2025 llvm::APSInt Size(CAA->getSize());
2031 if (
const auto *DAA = dyn_cast<DependentSizedArrayType>(AA))
2032 if (DAA->getSizeExpr())
2034 S, TemplateParams, NTTP, DAA->getSizeExpr(), Info,
2044 case Type::FunctionProto: {
2050 if (FPP->getMethodQuals() != FPA->getMethodQuals() ||
2051 FPP->getRefQualifier() != FPA->getRefQualifier() ||
2052 FPP->isVariadic() != FPA->isVariadic())
2057 S, TemplateParams, FPP->getReturnType(), FPA->getReturnType(),
2059 false, HasDeducedAnyParam);
2065 S, TemplateParams, FPP->param_types(), FPA->param_types(), Info,
2078 Expr *NoexceptExpr = FPP->getNoexceptExpr();
2083 "saw non-type template parameter with wrong depth");
2086 switch (FPA->canThrow()) {
2100 if (
Expr *ArgNoexceptExpr = FPA->getNoexceptExpr())
2102 S, TemplateParams, NTTP, ArgNoexceptExpr, Info,
2116 case Type::InjectedClassName:
2125 case Type::TemplateSpecialization: {
2172 case Type::MemberPointer: {
2189 S, TemplateParams, PPT, APT, Info,
Deduced, SubTDF,
2191 false, HasDeducedAnyParam);
2198 :
QualType(MPP->getQualifier().getAsType(), 0);
2199 assert(!TP.
isNull() &&
"member pointer with non-type class");
2204 :
QualType(MPA->getQualifier().getAsType(), 0)
2206 assert(!TA.
isNull() &&
"member pointer with non-type class");
2209 S, TemplateParams, TP, TA, Info,
Deduced, SubTDF,
2211 false, HasDeducedAnyParam);
2219 case Type::BlockPointer: {
2225 S, TemplateParams, BPP->getPointeeType(), BPA->getPointeeType(), Info,
2227 false, HasDeducedAnyParam);
2233 case Type::ExtVector: {
2238 if (VP->getNumElements() != VA->getNumElements())
2240 ElementType = VA->getElementType();
2245 ElementType = VA->getElementType();
2251 S, TemplateParams, VP->getElementType(), ElementType, Info,
Deduced,
2253 false, HasDeducedAnyParam);
2256 case Type::DependentVector: {
2262 S, TemplateParams, VP->getElementType(), VA->getElementType(),
2264 false, HasDeducedAnyParam);
2275 ArgSize = VA->getNumElements();
2282 HasDeducedAnyParam);
2288 S, TemplateParams, VP->getElementType(), VA->getElementType(),
2290 false, HasDeducedAnyParam);
2301 S, TemplateParams, NTTP, VA->getSizeExpr(), Info,
2311 case Type::DependentSizedExtVector: {
2317 S, TemplateParams, VP->getElementType(), VA->getElementType(),
2319 false, HasDeducedAnyParam);
2330 ArgSize = VA->getNumElements();
2335 S, TemplateParams, NTTP, ArgSize, S.
Context.
IntTy,
true, Info,
2342 S, TemplateParams, VP->getElementType(), VA->getElementType(),
2344 false, HasDeducedAnyParam);
2355 S, TemplateParams, NTTP, VA->getSizeExpr(), Info,
2366 case Type::ConstantMatrix: {
2373 if (MP->getNumRows() != MA->getNumRows() ||
2374 MP->getNumColumns() != MA->getNumColumns()) {
2379 S, TemplateParams, MP->getElementType(), MA->getElementType(), Info,
2381 false, HasDeducedAnyParam);
2384 case Type::DependentSizedMatrix: {
2394 false, HasDeducedAnyParam);
2399 auto DeduceMatrixArg =
2400 [&S, &Info, &
Deduced, &TemplateParams, &HasDeducedAnyParam, POK](
2404 const auto *ACM = dyn_cast<ConstantMatrixType>(A);
2405 const auto *ADM = dyn_cast<DependentSizedMatrixType>(A);
2406 if (!ParamExpr->isValueDependent()) {
2407 std::optional<llvm::APSInt> ParamConst =
2408 ParamExpr->getIntegerConstantExpr(S.
Context);
2413 if ((ACM->*GetArgDimension)() == *ParamConst)
2418 Expr *ArgExpr = (ADM->*GetArgDimensionExpr)();
2419 if (std::optional<llvm::APSInt> ArgConst =
2421 if (*ArgConst == *ParamConst)
2432 llvm::APSInt ArgConst(
2434 ArgConst = (ACM->*GetArgDimension)();
2442 S, TemplateParams, NTTP, (ADM->*GetArgDimensionExpr)(), Info,
2446 if (
auto Result = DeduceMatrixArg(MP->getRowExpr(), MA,
2452 return DeduceMatrixArg(MP->getColumnExpr(), MA,
2463 case Type::CooperativeMatrix: {
2470 if (MP->getScope() != MA->getScope() ||
2471 MP->getNumRows() != MA->getNumRows() ||
2472 MP->getNumColumns() != MA->getNumColumns() ||
2473 MP->getUse() != MA->getUse()) {
2478 S, TemplateParams, MP->getElementType(), MA->getElementType(), Info,
2480 false, HasDeducedAnyParam);
2486 case Type::DependentAddressSpace: {
2492 S, TemplateParams, ASP->getPointeeType(), ASA->getPointeeType(),
2494 false, HasDeducedAnyParam);
2505 S, TemplateParams, NTTP, ASA->getAddrSpaceExpr(), Info,
2516 S, TemplateParams, ASP->getPointeeType(),
2519 false, HasDeducedAnyParam);
2530 S, TemplateParams, NTTP, ArgAddressSpace, S.
Context.
IntTy,
true,
2532 HasDeducedAnyParam);
2537 case Type::DependentBitInt: {
2541 if (IP->isUnsigned() != IA->isUnsigned())
2552 ArgSize = IA->getNumBits();
2555 S, TemplateParams, NTTP, ArgSize, T,
true, Info,
2560 if (IP->isUnsigned() != IA->isUnsigned())
2568 case Type::TypeOfExpr:
2570 case Type::DependentName:
2571 case Type::UnresolvedUsing:
2572 case Type::Decltype:
2573 case Type::UnaryTransform:
2574 case Type::DeducedTemplateSpecialization:
2575 case Type::PackExpansion:
2577 case Type::ArrayParameter:
2578 case Type::HLSLAttributedResource:
2579 case Type::HLSLInlineSpirv:
2580 case Type::OverflowBehavior:
2584 case Type::PackIndexing:
2589 assert(!P->
getAs<PackIndexingType>()->hasSelectedType() &&
2590 "a pack-index-specifier with a selected type canonicalizes to "
2591 "the selected type and should not dispatch here");
2595 llvm_unreachable(
"Invalid Type Class!");
2617 bool *HasDeducedAnyParam) {
2626 llvm_unreachable(
"Null template argument in parameter list");
2634 false, HasDeducedAnyParam);
2646 HasDeducedAnyParam);
2652 llvm_unreachable(
"caller should handle pack expansions");
2706 HasDeducedAnyParam);
2727 llvm_unreachable(
"Unknown template argument kind");
2732 llvm_unreachable(
"Argument packs should be expanded by the caller!");
2735 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2748 if (ArgIdx == Args.size())
2755 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
2758 return ArgIdx < Args.size();
2764 bool FoundPackExpansion =
false;
2765 for (
const auto &A : Args) {
2766 if (FoundPackExpansion)
2774 if (A.isPackExpansion())
2775 FoundPackExpansion =
true;
2805 for (
unsigned ArgIdx = 0,
ParamIdx = 0; ; ) {
2811 if (!Ps[
ParamIdx].isPackExpansion()) {
2816 return !FoldPackArgument && NumberOfArgumentsMustMatch
2820 if (As[ArgIdx].isPackExpansion()) {
2825 if (!FoldPackArgument)
2832 S, TemplateParams, Ps[
ParamIdx], Pattern, Info,
2840 if (Ps[
ParamIdx].isPackExpansion())
2846 S, TemplateParams, Ps[
ParamIdx], As[ArgIdx], Info,
2867 PackDeductionScope PackScope(S, TemplateParams,
Deduced, Info, Pattern);
2873 PackScope.hasNextElement();
2875 if (!As[ArgIdx].isPackExpansion()) {
2876 if (!FoldPackParameter)
2878 if (FoldPackArgument)
2888 PackScope.nextPackElement();
2893 return PackScope.finish();
2901 bool NumberOfArgumentsMustMatch) {
2902 return ::DeduceTemplateArguments(
2903 *
this, TemplateParams, Ps, As, Info,
Deduced, NumberOfArgumentsMustMatch,
2913 llvm_unreachable(
"Can't get a NULL template argument here");
2961 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2979 unsigned ArgumentPackIndex) {
2991 Template->getSourceRange().getEnd(), ArgumentPackIndex, CTAI,
3005 CanonicalPackedArgsBuilder;
3013 "deduced nested pack");
3019 S.
Diag(Param->getLocation(),
3020 diag::err_template_arg_deduced_incomplete_pack)
3024 if (ConvertArg(InnerArg, SugaredPackedArgsBuilder.size()))
3029 CanonicalPackedArgsBuilder.push_back(
3035 if (SugaredPackedArgsBuilder.empty()) {
3041 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
3046 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
3047 NTTP->getDeclName()).isNull())
3049 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
3065 S.
Context, CanonicalPackedArgsBuilder));
3069 return ConvertArg(Arg, 0);
3081 unsigned NumAlreadyConverted,
bool *IsIncomplete) {
3082 for (
unsigned I = 0, N = TemplateParams->
size(); I != N; ++I) {
3089 if (
Deduced[I].isNull() && Param->isTemplateParameterPack()) {
3091 PackDeductionScope(S, TemplateParams,
Deduced, Info, I).finish();
3097 if (I < NumAlreadyConverted) {
3101 if (Param->isParameterPack() && CurrentInstantiationScope &&
3141 *IsIncomplete =
true;
3148 bool HasDefaultArg =
false;
3161 if (Rec->isLambda())
3162 if (
auto *Method = dyn_cast<CXXMethodDecl>(Rec->getDeclContext())) {
3164 ThisTypeQuals = Method->getMethodQualifiers();
3209 if (
auto *DC = dyn_cast<DeclContext>(D))
3232 bool DeducedArgsNeedReplacement =
false;
3233 if (
auto *TD = dyn_cast<ClassTemplatePartialSpecializationDecl>(
Template)) {
3234 TD->getAssociatedConstraints(AssociatedConstraints);
3235 DeducedArgsNeedReplacement = !TD->isClassScopeExplicitSpecialization();
3236 }
else if (
auto *TD =
3237 dyn_cast<VarTemplatePartialSpecializationDecl>(
Template)) {
3238 TD->getAssociatedConstraints(AssociatedConstraints);
3239 DeducedArgsNeedReplacement = !TD->isClassScopeExplicitSpecialization();
3242 AssociatedConstraints);
3245 std::optional<ArrayRef<TemplateArgument>> Innermost;
3248 if (!DeducedArgsNeedReplacement)
3249 Innermost = SugaredDeducedArgs;
3288 Info.
FirstArg = Ps[ArgIdx].getArgument();
3295 {},
false, InstCTAI,
3308 while (!Stack.empty()) {
3309 auto &Xs = Stack.back();
3314 auto &
X = Xs.front();
3316 Stack.emplace_back(
X.getPackAsArray());
3317 Xs = Xs.drop_front();
3320 assert(!
X.isNull());
3327 auto [Ps, P] = take(PsStack);
3328 auto [As, A] = take(AsStack);
3329 if (P.isNull() && A.isNull())
3332 PA = A.isPackExpansion() ? A.getPackExpansionPattern() : A;
3334 if (!P.isPackExpansion() && !A.isPackExpansion()) {
3336 (AsStack.empty() ? As.end() : AsStack.back().begin()) -
3342 if (P.isPackExpansion()) {
3343 Ps = Ps.drop_front();
3346 if (A.isPackExpansion()) {
3347 As = As.drop_front();
3351 Ps = Ps.drop_front(P.isPackExpansion() ? 0 : 1);
3352 As = As.drop_front(A.isPackExpansion() && !P.isPackExpansion() ? 0 : 1);
3354 assert(PsStack.empty());
3355 assert(AsStack.empty());
3380 if (CopyDeducedArgs) {
3386 Info.
reset(SugaredDeducedArgumentList, CanonicalDeducedArgumentList);
3414 for (
unsigned I = 0, N = Ps.size(); I != N; ++I)
3419 Info, CopyDeducedArgs);
3450template <
typename T>
3451static std::enable_if_t<IsPartialSpecialization<T>::value,
3456 if (Partial->isInvalidDecl())
3475 Deduced.resize(Partial->getTemplateParameters()->size());
3477 S, Partial->getTemplateParameters(),
3478 Partial->getTemplateArgs().asArray(), TemplateArgs, Info,
Deduced,
3492 Result = ::FinishTemplateArgumentDeduction(
3493 S, Partial, Partial->getTemplateParameters(),
3494 Partial->getSpecializedTemplate(),
3496 Partial->getTemplateArgsAsWritten()->arguments(), TemplateArgs, Deduced,
3513 return ::DeduceTemplateArguments(*
this, Partial, TemplateArgs, Info);
3519 return ::DeduceTemplateArguments(*
this, Partial, TemplateArgs, Info);
3529 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
3531 PType =
Context.getCanonicalTagType(CTD->getTemplatedDecl());
3532 }
else if (
const auto *
AliasTemplate = dyn_cast<TypeAliasTemplateDecl>(TD)) {
3533 PType =
AliasTemplate->getTemplatedDecl()->getUnderlyingType();
3535 assert(
false &&
"Expected a class or alias template");
3554 return DeducedResult;
3564 Result = ::FinishTemplateArgumentDeduction(*this, TD, Deduced, Info);
3578 if (
const TemplateSpecializationType *Spec
3579 = T->getAs<TemplateSpecializationType>())
3580 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
3609 if (ExplicitTemplateArgs.
size() == 0) {
3612 for (
auto *P :
Function->parameters())
3613 ParamTypes.push_back(P->getType());
3638 ExplicitTemplateArgs, {},
3642 if (Index >= TemplateParams->
size())
3655 CanonicalExplicitArgumentList);
3667 unsigned PartiallySubstitutedPackIndex = -1u;
3675 if (!Expansions || Arg.
pack_size() < *Expansions) {
3685 assert(Proto &&
"Function template does not have a prototype?");
3693 SugaredExplicitArgumentList->
asArray(),
3703 nullptr, ExtParamInfos))
3719 ThisContext =
Method->getParent();
3720 ThisTypeQuals =
Method->getMethodQualifiers();
3734 Diag(
Function->getLocation(), diag::err_kern_type_not_void_return)
3745 nullptr, ExtParamInfos))
3770 for (
unsigned I = 0, N = SugaredExplicitArgumentList->
size(); I != N; ++I) {
3772 if (I == PartiallySubstitutedPackIndex)
3845 if (AQuals == DeducedAQuals) {
3863 bool ObjCLifetimeConversion =
false;
3866 ObjCLifetimeConversion) ||
3888 if (Context.hasSameUnqualifiedType(A, DeducedA))
3912 if (PD->isParameterPack()) {
3915 unsigned NumExpansions = NumArgs ? *NumArgs : 1;
3916 if (Idx + NumExpansions >
ParamIdx)
3918 Idx += NumExpansions;
3921 return std::nullopt;
3926 llvm_unreachable(
"parameter index would not be produced from template");
3981 bool ForOverloadSetAddressResolution,
3982 llvm::function_ref<
bool(
bool)> CheckNonDependent) {
3997 bool IsIncomplete =
false;
4002 NumExplicitlySpecified, PartialOverloading ? &IsIncomplete :
nullptr);
4011 Info.
reset(SugaredDeducedArgumentList, CanonicalDeducedArgumentList);
4020 if (CheckNonDependent(
true))
4032 if (!IsLambda && !IsIncomplete) {
4052 if (CheckNonDependent(
false))
4069 CanonicalDeducedArgumentList)
4080 if (IsLambda && !IsIncomplete) {
4103 if (OriginalCallArgs) {
4108 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
4109 for (
unsigned I = 0, N = OriginalCallArgs->size(); I != N; ++I) {
4113 unsigned ExplicitOffset =
4115 !ForOverloadSetAddressResolution)
4136 if (CacheEntry.
isNull()) {
4145 DeducedA = CacheEntry;
4160 auto [Pos, Inserted] =
4177 if (Candidate.Specialization &&
4208 DeducedArgLists.reserve(TPLs.size());
4214 Params, PatternArgs, CandidateArgs, Info,
Deduced,
4218 bool IsIncomplete =
false;
4221 *
this, PatternCTD, Params,
false,
Deduced, Info, CTAI,
4222 &InstantiationScope, 0, &IsIncomplete);
4224 for (
unsigned I = 0, N =
Deduced.size(); I != N; ++I) {
4243 DeducedArgLists.push_back(
4255 return Params->hasAssociatedConstraints();
4260 PatternArgLocs.reserve(PatternArgs.size());
4262 PatternArgLocs.push_back(
4269 *
this, CandidateCTD, PatternArgLocs, CandidateArgs, DeducedArgs, Info);
4282 if (Constraints.empty())
4293 CanonicalCandidateArgs.reserve(CandidateArgs.size());
4295 CanonicalCandidateArgs.push_back(
4296 Context.getCanonicalTemplateArgument(Arg));
4301 *
this, PatternCTD, Info,
4315 if (S.
getLangOpts().CPlusPlus14 && Fn->getReturnType()->isUndeducedType() &&
4320 if (Method->isImplicitObjectMemberFunction()) {
4323 if (!R.HasFormOfMemberPointer)
4327 Fn->getType(), std::nullopt, Method->getParent());
4330 if (!R.IsAddressOfOperand)
return Fn->getType();
4341 bool ParamWasReference,
4350 if (ParamWasReference)
4352 if (R.IsAddressOfOperand)
4409 if (ArgType.isNull())
continue;
4413 ArgType->isFunctionType())
4432 S, TemplateParams, ParamType, ArgType, Info,
Deduced, TDF,
4476 assert(Arg &&
"expected a non-null arg expression");
4478 ParamRefType !=
nullptr, FailedTSC);
4479 if (ArgType.isNull())
4485 if (ArgType->isIncompleteArrayType()) {
4486 assert(Arg &&
"expected a non-null arg expression");
4495 if (S.
getLangOpts().OpenCL && !ArgType.hasAddressSpace())
4509 if (ArgType->canDecayToPointerType())
4514 ArgType = ArgType.getUnqualifiedType();
4532 if (ArgType->isPointerType() || ArgType->isMemberPointerType() ||
4533 ArgType->isObjCObjectPointerType())
4560 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF,
4585 ElTy = ArrTy->getElementType();
4602 S, TemplateParams, 0, ElTy, E->getType(),
4604 OriginalCallArgs,
true, ArgIdx, TDF);
4612 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
4624 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
4644 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF,
4647 QualType OrigParamType = ParamType;
4652 S, TemplateParams, FirstInnerIndex, ParamType, ArgType,
4653 ArgClassification, Arg, TDF, FailedTSC))
4657 if (
InitListExpr *ILE = dyn_cast_if_present<InitListExpr>(Arg))
4659 Deduced, OriginalCallArgs, ArgIdx, TDF);
4667 OriginalCallArgs.push_back(
4670 S, TemplateParams, ParamType, ArgType, Info,
Deduced, TDF,
4679 bool PartialOverloading,
bool AggregateDeductionCandidate,
4682 bool ForOverloadSetAddressResolution,
4688 unsigned NumParams =
Function->getNumParams();
4689 bool HasExplicitObject =
false;
4690 int ExplicitObjectOffset = 0;
4698 if (!ForOverloadSetAddressResolution &&
4699 Function->hasCXXExplicitFunctionObjectParameter()) {
4700 HasExplicitObject =
true;
4701 ExplicitObjectOffset = 1;
4710 if (Args.size() <
Function->getMinRequiredExplicitArguments() &&
4711 !PartialOverloading)
4714 PartialOverloading)) {
4716 if (Proto->isTemplateVariadic())
4718 else if (!Proto->isVariadic())
4733 unsigned NumExplicitlySpecified = 0;
4734 if (ExplicitTemplateArgs) {
4737 Result = SubstituteExplicitTemplateArguments(
4738 FunctionTemplate, *ExplicitTemplateArgs, Deduced, ParamTypes, nullptr,
4746 NumExplicitlySpecified =
Deduced.size();
4749 for (
unsigned I = 0; I != NumParams; ++I)
4750 ParamTypes.push_back(
Function->getParamDecl(I)->getType());
4756 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx,
4757 bool ExplicitObjectArgument) {
4765 if (ExplicitObjectArgument) {
4768 *
this, TemplateParams, FirstInnerIndex, ParamType, ObjectType,
4769 ObjectClassification,
4770 nullptr, Info,
Deduced, OriginalCallArgs,
4776 *
this, TemplateParams, FirstInnerIndex, ParamType,
4778 Args[ArgIdx], Info,
Deduced, OriginalCallArgs,
false,
4785 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
4789 const PackExpansionType *ParamExpansion =
4790 dyn_cast<PackExpansionType>(ParamType);
4791 if (!ParamExpansion) {
4793 if (ArgIdx >= Args.size() && !(HasExplicitObject &&
ParamIdx == 0))
4796 ParamTypesForArgChecking.push_back(ParamType);
4798 if (
ParamIdx == 0 && HasExplicitObject) {
4802 if (
auto Result = DeduceCallArgument(ParamType, 0,
4809 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++,
4817 bool IsTrailingPack =
ParamIdx + 1 == NumParamTypes;
4819 QualType ParamPattern = ParamExpansion->getPattern();
4820 PackDeductionScope PackScope(*
this, TemplateParams,
Deduced, Info,
4822 AggregateDeductionCandidate && IsTrailingPack);
4840 if (IsTrailingPack || PackScope.hasFixedArity()) {
4841 for (; ArgIdx < Args.size() && PackScope.hasNextElement();
4842 PackScope.nextPackElement(), ++ArgIdx) {
4843 ParamTypesForArgChecking.push_back(ParamPattern);
4844 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
4853 UnsignedOrNone NumExpansions = ParamExpansion->getNumExpansions();
4854 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
4855 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
4857 ParamTypesForArgChecking.push_back(ParamPattern);
4860 PackScope.nextPackElement();
4862 }
else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
4863 PackScope.isDeducedFromEarlierParameter()) {
4877 PackScope.getSavedPackSizeIfAllEqual();
4878 if (!ArgPosAfterSubstitution)
4881 unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
4882 for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
4883 ParamTypesForArgChecking.push_back(ParamPattern);
4885 DeduceCallArgument(ParamPattern, ArgIdx,
4890 PackScope.nextPackElement();
4897 if (
auto Result = PackScope.finish();
4908 Result = FinishTemplateArgumentDeduction(
4909 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
4910 &OriginalCallArgs, PartialOverloading, PartialOrdering,
4911 ForOverloadSetAddressResolution,
4912 [&, CallingCtx](bool OnlyInitializeNonUserDefinedConversions) {
4913 ContextRAII SavedContext(*this, CallingCtx);
4914 return CheckNonDependent(ParamTypesForArgChecking,
4915 OnlyInitializeNonUserDefinedConversions);
4918 if (Trap.hasErrorOccurred()) {
4928 bool AdjustExceptionSpec) {
4929 if (ArgFunctionType.
isNull())
4930 return ArgFunctionType;
4935 bool Rebuild =
false;
4938 if (EPI.ExtInfo.getCC() != CC) {
4939 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
4943 bool NoReturn = FunctionTypeP->getNoReturnAttr();
4944 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
4945 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
4949 if (AdjustExceptionSpec && (FunctionTypeP->hasExceptionSpec() ||
4951 EPI.ExceptionSpec = FunctionTypeP->getExtProtoInfo().ExceptionSpec;
4956 return ArgFunctionType;
4966 bool IsAddressOfFunction) {
4986 unsigned NumExplicitlySpecified = 0;
4988 if (ExplicitTemplateArgs) {
4991 Result = SubstituteExplicitTemplateArguments(
4992 FunctionTemplate, *ExplicitTemplateArgs, Deduced, ParamTypes,
4993 &FunctionType, Info);
5000 NumExplicitlySpecified =
Deduced.size();
5006 if (!IsAddressOfFunction)
5014 bool HasDeducedReturnType =
false;
5016 Function->getReturnType()->getContainedAutoType()) {
5018 HasDeducedReturnType =
true;
5039 Result = FinishTemplateArgumentDeduction(
5040 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
5042 true, IsAddressOfFunction);
5085 if (HasDeducedReturnType && IsAddressOfFunction &&
5105 if (!IsAddressOfFunction) {
5111 if (HasDeducedReturnType) {
5120 if (!ArgFunctionType.
isNull()) {
5122 SpecializationType, ArgFunctionType)
5123 : !
Context.hasSameFunctionTypeIgnoringExceptionSpec(
5124 SpecializationType, ArgFunctionType)) {
5162 if (!IsReferenceP) {
5171 assert(!A->
isReferenceType() &&
"Reference types were handled above");
5177 P =
Context.getArrayDecayedType(P);
5182 P =
Context.getPointerType(P);
5237 ParamType, ObjectType, ObjectClassification,
5238 nullptr, Info,
Deduced, OriginalCallArgs,
5245 *
this, TemplateParams, P, A, Info,
Deduced, TDF,
5257 Result = FinishTemplateArgumentDeduction(
5258 ConversionTemplate, Deduced, 0, ConversionSpecialized, Info,
5259 &OriginalCallArgs, false,
5262 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
5271 bool IsAddressOfFunction) {
5274 IsAddressOfFunction);
5278 struct DependentAuto {
bool IsPack; };
5282 class SubstituteDeducedTypeTransform :
5290 SubstituteDeducedTypeTransform(
Sema &SemaRef, DependentAuto DA)
5294 UseTypeSugar(
true) {}
5296 SubstituteDeducedTypeTransform(Sema &SemaRef, QualType Replacement,
5297 bool UseTypeSugar =
true)
5298 : TreeTransform<SubstituteDeducedTypeTransform>(SemaRef),
5301 Replacement(Replacement), UseTypeSugar(UseTypeSugar) {
5302 assert((!Replacement.isNull() || UseTypeSugar) &&
5303 "An undeduced auto type is never type sugar");
5306 QualType TransformDesugared(TypeLocBuilder &TLB, DeducedTypeLoc TL) {
5308 "unexpected unsugared replacement kind");
5309 QualType
Result = Replacement;
5310 TemplateTypeParmTypeLoc NewTL = TLB.
push<TemplateTypeParmTypeLoc>(
Result);
5315 QualType TransformAutoType(TypeLocBuilder &TLB, AutoTypeLoc TL) {
5326 return TransformDesugared(TLB, TL);
5329 DK, Replacement, TL.
getTypePtr()->getKeyword(),
5331 TL.
getTypePtr()->getTypeConstraintArguments());
5337 QualType TransformDeducedTemplateSpecializationType(
5338 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5340 return TransformDesugared(TLB, TL);
5343 DK, Replacement, TL.
getTypePtr()->getKeyword(),
5345 auto NewTL = TLB.
push<DeducedTemplateSpecializationTypeLoc>(
Result);
5352 QualType TransformAtomicType(TypeLocBuilder &TLB, AtomicTypeLoc TL) {
5365 if (isa_and_nonnull<TemplateTypeParmType>(Replacement) &&
5367 return getDerived().TransformType(TLB, TL.
getValueLoc());
5368 return inherited::TransformAtomicType(TLB, TL);
5375 bool TransformExceptionSpec(SourceLocation Loc,
5376 FunctionProtoType::ExceptionSpecInfo &ESI,
5377 SmallVectorImpl<QualType> &Exceptions,
5383 return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
5386 QualType Apply(TypeLoc TL) {
5391 return TransformType(TLB, TL);
5409 for (
unsigned I = 0,
C =
TypeLoc.getNumArgs(); I !=
C; ++I)
5425 llvm::raw_string_ostream OS(Buf);
5426 OS <<
"'" <<
Concept->getName();
5427 if (
TypeLoc.hasExplicitTemplateArgs()) {
5428 printTemplateArgumentList(OS,
Type.getTypeConstraintArguments(),
5430 Type.getTypeConstraintConcept()
5431 .getAsTemplateDecl()
5432 ->getTemplateParameters());
5436 diag::err_placeholder_constraints_not_satisfied)
5447 bool IgnoreConstraints,
5450 if (
Init->containsErrors())
5456 if (
Init->getType()->isNonOverloadPlaceholderType() || AT->isDecltypeAuto()) {
5463 DependentAuto DependentResult = {
5466 if (!DependentDeduction &&
5468 Init->containsUnexpandedParameterPack())) {
5469 Result = SubstituteDeducedTypeTransform(*
this, DependentResult).Apply(
Type);
5470 assert(!
Result.isNull() &&
"substituting DependentTy can't fail");
5474 auto *InitList = dyn_cast<InitListExpr>(
Init);
5477 Diag(
Init->getBeginLoc(), diag::err_auto_init_list_from_c)
5478 << (int)AT->getKeyword() << IsArrayType;
5484 Diag(
Type.getBeginLoc(), diag::ext_c23_auto_non_plain_identifier);
5495 if (AT->isDecltypeAuto()) {
5497 Diag(
Init->getBeginLoc(), diag::err_decltype_auto_initializer_list);
5502 assert(!DeducedType.
isNull());
5510 nullptr,
false,
false,
false);
5514 Context, Loc, Loc, TemplParamPtr, Loc,
nullptr);
5520 if (!
Type.getType().getNonReferenceType()->
getAs<AutoType>())
5524 for (
Expr *
Init : InitList->inits()) {
5530 *
this, TemplateParamsSt.get(), 0, TemplArg,
Init->getType(),
5539 <<
Init->getSourceRange();
5547 DeducedFromInitRange =
Init->getSourceRange();
5552 Diag(Loc, diag::err_auto_bitfield);
5556 SubstituteDeducedTypeTransform(*
this, TemplArg).Apply(
Type);
5557 assert(!FuncParam.
isNull() &&
5558 "substituting template parameter for 'auto' failed");
5560 *
this, TemplateParamsSt.get(), 0, FuncParam,
Init->getType(),
5563 false, 0, 0, FailedTSC);
5571 DeducedType =
Deduced[0].getAsType();
5575 if (DeducedType.
isNull())
5586 DeducedType =
Context.getCommonSugaredType(
Result, DeducedType);
5589 if (AT->isConstrained() && !IgnoreConstraints &&
5591 *
this, *AT,
Type.getContainedAutoTypeLoc(), DeducedType))
5594 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(
Type);
5602 assert((
bool)InitList == OriginalArg.DecomposedParam &&
5603 "decomposed non-init-list in auto deduction?");
5617 assert(TypeToReplaceAuto !=
Context.DependentTy);
5618 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
5619 .TransformType(TypeWithAuto);
5624 assert(TypeToReplaceAuto !=
Context.DependentTy);
5625 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
5626 .TransformType(TypeWithAuto);
5630 return SubstituteDeducedTypeTransform(
5633 .TransformType(TypeWithAuto);
5638 return SubstituteDeducedTypeTransform(
5641 .TransformType(TypeWithAuto);
5646 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
5648 .TransformType(TypeWithAuto);
5653 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
5655 .TransformType(TypeWithAuto);
5663 ? diag::err_init_capture_deduction_failure_from_init_list
5664 : diag::err_auto_var_deduction_failure_from_init_list)
5668 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
5669 : diag::err_auto_var_deduction_failure)
5671 <<
Init->getSourceRange();
5703 "failed to deduce lambda return type");
5713 RetType =
Context.getPointerType(RetType);
5716 RetType =
Context.getBlockPointerType(RetType);
5718 Context.adjustDeducedFunctionResultType(FD, RetType);
5730 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
5734 return StillUndeduced;
5777 assert(Method && !Method->isExplicitObjectMemberFunction() &&
5778 "expected a member function with no explicit object parameter");
5780 RawType = Context.getQualifiedType(RawType, Method->getMethodQualifiers());
5781 if (Method->getRefQualifier() ==
RQ_RValue ||
5782 (IsOtherRvr && Method->getRefQualifier() ==
RQ_None))
5783 return Context.getRValueReferenceType(RawType);
5784 return Context.getLValueReferenceType(RawType);
5795 bool IsIncompleteSubstitution =
false;
5804 if (IsDeductionGuide) {
5806 P = Injected->getDecl()->getCanonicalTemplateSpecializationType(
5811 if (InstP.
isNull() && !IsIncompleteSubstitution)
5813 if (!CheckConsistency)
5815 if (IsIncompleteSubstitution)
5820 if (
auto *PA = dyn_cast<PackExpansionType>(A);
5822 A = PA->getPattern();
5825 if (IsDeductionGuide) {
5826 if (
auto *Injected = T1->getAsCanonical<InjectedClassNameType>())
5827 T1 = Injected->getDecl()->getCanonicalTemplateSpecializationType(
5829 if (
auto *Injected = T2->getAsCanonical<InjectedClassNameType>())
5830 T2 = Injected->getDecl()->getCanonicalTemplateSpecializationType(
5848 bool IsIncomplete =
false;
5864 Info.
reset(SugaredDeducedArgumentList, CanonicalDeducedArgumentList);
5883 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
5899 Proto1->
isVariadic() == Proto2->isVariadic() &&
5900 "shouldn't partial order functions with different qualifiers in a "
5901 "context where the function type is used");
5903 assert(Args1.empty() && Args2.empty() &&
5904 "Only call context should have arguments");
5906 Args2 = Proto2->getParamTypes();
5913 bool HasDeducedAnyParamFromReturnType =
false;
5916 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
5919 &HasDeducedAnyParamFromReturnType) !=
5924 llvm::SmallBitVector HasDeducedParam;
5926 HasDeducedParam.resize(Args2.size());
5930 &HasDeducedParam) !=
5945 bool AtLeastAsSpecialized;
5947 AtLeastAsSpecialized =
5948 ::FinishTemplateArgumentDeduction(
5949 S, FT2, Deduced, Info,
5950 [&](Sema &S, FunctionTemplateDecl *FTD,
5951 ArrayRef<TemplateArgument> DeducedArgs) {
5956 if (TPOC != TPOC_Call) {
5957 if (auto TDR = ::CheckDeductionConsistency(
5958 S, FTD, std::nullopt,
5959 Proto2->getReturnType(), Proto1->getReturnType(),
5961 HasDeducedAnyParamFromReturnType);
5962 TDR != TemplateDeductionResult::Success)
5966 if (TPOC == TPOC_Conversion)
5967 return TemplateDeductionResult::Success;
5969 return ::DeduceForEachType(
5970 S, TemplateParams, Args2, Args1, Info, Deduced,
5971 PartialOrderingKind::Call, true,
5972 [&](Sema &S, TemplateParameterList *, int ParamIdx,
5973 UnsignedOrNone ArgIdx, QualType P, QualType A,
5974 TemplateDeductionInfo &Info,
5975 SmallVectorImpl<DeducedTemplateArgument> &Deduced,
5976 PartialOrderingKind) {
5977 if (ArgIdx && *ArgIdx >= static_cast<unsigned>(Args1Offset))
5978 ArgIdx = *ArgIdx - Args1Offset;
5980 ArgIdx = std::nullopt;
5981 return ::CheckDeductionConsistency(
5982 S, FTD, ArgIdx, P, A, DeducedArgs,
5983 HasDeducedParam[ParamIdx]);
5987 if (!AtLeastAsSpecialized || Trap.hasErrorOccurred())
5996 unsigned ArgIdx = 0, NumArgs =
Deduced.size();
5997 for (; ArgIdx != NumArgs; ++ArgIdx)
6001 if (ArgIdx == NumArgs) {
6008 llvm::SmallBitVector UsedParameters(TemplateParams->size());
6011 for (
unsigned I = 0, N = Args2.size(); I != N; ++I)
6013 TemplateParams->getDepth(), UsedParameters);
6019 TemplateParams->getDepth(), UsedParameters);
6044 S.Context.getFunctionTypeWithExceptionSpec(FD2->getType(),
EST_None),
6045 false, TemplateParams->getDepth(), UsedParameters);
6049 for (; ArgIdx != NumArgs; ++ArgIdx)
6052 if (
Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
6064 const TemplateSpecializationType *TST1,
6065 const TemplateSpecializationType *TST2) {
6067 As2 = TST2->template_arguments();
6077 if (IsPack1 != IsPack2)
6080 if (!IsPack1 || As1.size() != As2.size())
6083 unsigned PackSize1 = TA1.
pack_size(), PackSize2 = TA2.pack_size();
6084 bool IsPackExpansion1 =
6086 bool IsPackExpansion2 =
6087 PackSize2 && TA2.pack_elements().back().isPackExpansion();
6088 if (PackSize1 == PackSize2 && IsPackExpansion1 == IsPackExpansion2)
6090 if (PackSize1 > PackSize2 && IsPackExpansion1)
6092 if (PackSize1 < PackSize2 && IsPackExpansion2)
6101 bool PartialOverloading) {
6106 bool ShouldConvert1 =
false;
6107 bool ShouldConvert2 =
false;
6108 bool Args1Offset =
false;
6109 bool Args2Offset =
false;
6120 const CXXMethodDecl *Method1 = dyn_cast<CXXMethodDecl>(FD1);
6121 const CXXMethodDecl *Method2 = dyn_cast<CXXMethodDecl>(FD2);
6132 bool NonStaticMethod1 = Method1 && !Method1->isStatic(),
6133 NonStaticMethod2 = Method2 && !Method2->
isStatic();
6136 Params2Begin = Proto2->param_type_begin();
6138 size_t NumComparedArguments = NumCallArguments1;
6141 (NonStaticMethod1 && NonStaticMethod2) ||
6142 (OO !=
OO_None && OO != OO_Call && OO != OO_Subscript)) {
6144 NonStaticMethod1 && !Method1->hasCXXExplicitFunctionObjectParameter();
6147 NumComparedArguments += 1;
6149 if (ShouldConvert1) {
6153 : Proto2->param_type_begin()[0]->isRValueReferenceType();
6156 RawObj1Ty, IsRValRef2);
6157 Args1.push_back(Obj1Ty);
6160 if (ShouldConvert2) {
6163 ? Method1->getRefQualifier() ==
RQ_RValue
6167 RawObj2Ty, IsRValRef1);
6168 Args2.push_back(Obj2Ty);
6172 if (NonStaticMethod1 && Method1->hasCXXExplicitFunctionObjectParameter())
6177 Args1.insert(Args1.end(), Params1Begin, Proto1->
param_type_end());
6178 Args2.insert(Args2.end(), Params2Begin, Proto2->param_type_end());
6183 Args1.resize(std::min(Args1.size(), NumComparedArguments));
6184 Args2.resize(std::min(Args2.size(), NumComparedArguments));
6187 std::reverse(Args2.begin(), Args2.end());
6189 assert(!
Reversed &&
"Only call context could have reversed arguments");
6192 Args2, Args2Offset);
6194 Args1, Args1Offset);
6198 if (Better1 != Better2)
6199 return Better1 ? FT1 : FT2;
6201 if (!Better1 && !Better2)
6210 Param1.reserve(FD1->
param_size() + ShouldConvert1);
6212 Param1.push_back(Obj1Ty);
6214 Param1.push_back(P->getType());
6217 Param2.reserve(FD2->
param_size() + ShouldConvert2);
6219 Param2.push_back(Obj2Ty);
6221 Param2.push_back(P->getType());
6223 unsigned NumParams1 = Param1.size();
6224 unsigned NumParams2 = Param2.size();
6230 if (Variadic1 != Variadic2) {
6231 if (Variadic1 && NumParams1 > NumParams2)
6233 if (Variadic2 && NumParams2 > NumParams1)
6240 for (
int i = 0, e = std::min(NumParams1, NumParams2);
6241 !PartialOverloading && i < e; ++i) {
6242 QualType T1 = Param1[i].getCanonicalType();
6243 QualType T2 = Param2[i].getCanonicalType();
6244 auto *TST1 = dyn_cast<TemplateSpecializationType>(T1);
6245 auto *TST2 = dyn_cast<TemplateSpecializationType>(T2);
6257 "unknown MoreSpecializedTrailingPackTieBreakerResult value");
6260 if (!
Context.getLangOpts().CPlusPlus20)
6276 if (TPL1->
size() != TPL2->
size() || NumParams1 != NumParams2)
6292 for (
unsigned i = 0; i < NumParams1; ++i)
6293 if (!
Context.hasSameUnqualifiedType(Param1[i], Param2[i]))
6308 bool AtLeastAsConstrained1, AtLeastAsConstrained2;
6313 if (AtLeastAsConstrained1 == AtLeastAsConstrained2)
6315 return AtLeastAsConstrained1 ? FT1 : FT2;
6323 bool Complain,
QualType TargetType) {
6324 if (SpecBegin == SpecEnd) {
6326 Diag(Loc, NoneDiag);
6332 if (SpecBegin + 1 == SpecEnd)
6340 assert(BestTemplate &&
"Not a function template specialization?");
6344 assert(Challenger &&
"Not a function template specialization?");
6349 BestTemplate = Challenger;
6375 Diag(Loc, AmbigDiag);
6382 FD->getPrimaryTemplate()->getTemplateParameters(),
6383 *FD->getTemplateSpecializationArgs());
6384 if (!TargetType.
isNull())
6386 Diag((*I)->getLocation(), PD);
6396 "not for function templates");
6413 bool AtLeastAsConstrained1, AtLeastAsConstrained2;
6418 if (AtLeastAsConstrained1 == AtLeastAsConstrained2)
6420 return AtLeastAsConstrained1 ? FD1 : FD2;
6432template <
typename TemplateLikeDecl>
6434 TemplateLikeDecl *P2,
6464 Deduced.resize(P2->getTemplateParameters()->size());
6485 Result = ::FinishTemplateArgumentDeduction(
6486 S, P2, P2->getTemplateParameters(), Template,
6487 true, Ps, As, Deduced, Info,
6497 template <
typename T1,
typename T2,
6498 std::enable_if_t<std::is_same_v<T1, T2>,
bool> =
true>
6499 T2 *operator()(T1 *, T2 *P2) {
6502 template <
typename T1,
typename T2,
6503 std::enable_if_t<!std::is_same_v<T1, T2>,
bool> =
true>
6504 T1 *operator()(T1 *, T2 *) {
6510struct TemplateArgumentListAreEqual {
6512 TemplateArgumentListAreEqual(ASTContext &Ctx) : Ctx(Ctx) {}
6514 template <
typename T1,
typename T2,
6515 std::enable_if_t<std::is_same_v<T1, T2>,
bool> =
true>
6516 bool operator()(T1 *PS1, T2 *PS2) {
6517 ArrayRef<TemplateArgument> Args1 = PS1->getTemplateArgs().asArray(),
6518 Args2 = PS2->getTemplateArgs().asArray();
6520 for (
unsigned I = 0, E = Args1.size(); I < E; ++I) {
6524 llvm::FoldingSetNodeID IDA, IDB;
6525 Args1[I].Profile(IDA, Ctx);
6526 Args2[I].Profile(IDB, Ctx);
6533 template <
typename T1,
typename T2,
6534 std::enable_if_t<!std::is_same_v<T1, T2>,
bool> =
true>
6535 bool operator()(T1 *Spec, T2 *Primary) {
6536 ArrayRef<TemplateArgument> Args1 = Spec->getTemplateArgs().asArray(),
6537 Args2 = Primary->getInjectedTemplateArgs(Ctx);
6539 for (
unsigned I = 0, E = Args1.size(); I < E; ++I) {
6543 llvm::FoldingSetNodeID IDA, IDB;
6544 Args1[I].Profile(IDA, Ctx);
6578template <
typename TemplateLikeDecl,
typename PrimaryDel>
6579static TemplateLikeDecl *
6582 constexpr bool IsMoreSpecialThanPrimaryCheck =
6583 !std::is_same_v<TemplateLikeDecl, PrimaryDel>;
6586 if constexpr (IsMoreSpecialThanPrimaryCheck)
6589 P2T = P2->getSpecializedTemplate();
6592 if (IsMoreSpecialThanPrimaryCheck && !Better1)
6596 P1->getSpecializedTemplate(), Info);
6597 if (IsMoreSpecialThanPrimaryCheck && !Better2)
6603 if (Better1 != Better2)
6604 return Better1 ? P1 : GetP2()(P1, P2);
6606 if (!Better1 && !Better2)
6615 return GetP2()(P1, P2);
6644 if (!TemplateArgumentListAreEqual(S.
getASTContext())(P1, P2))
6648 P1->getAssociatedConstraints(AC1);
6649 P2->getAssociatedConstraints(AC2);
6650 bool AtLeastAsConstrained1, AtLeastAsConstrained2;
6652 (IsMoreSpecialThanPrimaryCheck && !AtLeastAsConstrained1))
6656 if (AtLeastAsConstrained1 == AtLeastAsConstrained2)
6658 return AtLeastAsConstrained1 ? P1 : GetP2()(P1, P2);
6693 "the partial specializations being compared should specialize"
6694 " the same template.");
6712 Context.canonicalizeTemplateArguments(PrimaryCanonArgs);
6764 for (
unsigned I = 0, N = P->
size(); I != N; ++I) {
6789 if (StrictPackMatch)
6810 *
this, A, AArgs, PArgs, Info,
Deduced,
6816 *StrictPackMatch =
true;
6820 Diag(AArg->
getLocation(), diag::err_template_param_list_different_arity)
6830 diag::err_inconsistent_deduction)
6851 llvm_unreachable(
"Unexpected Result");
6856 TDK = ::FinishTemplateArgumentDeduction(
6857 *this, AArg, AArg->getTemplateParameters(), AArg, PartialOrdering,
6858 AArgs, PArgs, Deduced, Info, false);
6868 assert(PArg->
isInvalidDecl() &&
"Unexpected NonDeducedMismatch");
6892 llvm_unreachable(
"Unexpected Result");
6894 llvm_unreachable(
"Unexpected TDK");
6899 llvm::SmallBitVector &
Used;
6901 bool VisitDeclRefTypes =
true;
6903 MarkUsedTemplateParameterVisitor(llvm::SmallBitVector &
Used,
unsigned Depth,
6904 bool VisitDeclRefTypes =
true)
6905 :
Used(
Used), Depth(Depth), VisitDeclRefTypes(VisitDeclRefTypes) {}
6907 bool VisitTemplateTypeParmType(TemplateTypeParmType *T)
override {
6908 if (T->getDepth() == Depth)
6909 Used[T->getIndex()] =
true;
6914 bool TraverseQualifier)
override {
6915 if (
auto *TTP = llvm::dyn_cast_or_null<TemplateTemplateParmDecl>(
6917 if (TTP->getDepth() == Depth)
6918 Used[TTP->getIndex()] =
true;
6924 bool VisitDeclRefExpr(DeclRefExpr *E)
override {
6925 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(E->
getDecl()))
6926 if (NTTP->getDepth() == Depth)
6927 Used[NTTP->getIndex()] =
true;
6928 if (VisitDeclRefTypes)
6933 bool VisitDependentTemplateIdExpr(DependentTemplateIdExpr *E)
override {
6940 bool VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *NTTP)
override {
6946 bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE)
override {
6947 return TraverseDecl(SOPE->
getPack());
6959 llvm::SmallBitVector &
Used) {
6961 MarkUsedTemplateParameterVisitor(
Used, Depth)
6962 .TraverseStmt(
const_cast<Expr *
>(E));
6968 E = Expansion->getPattern();
6972 if (
const auto *DTI = dyn_cast<DependentTemplateIdExpr>(E)) {
6973 Used[DTI->getParameter()->getIndex()] =
true;
6974 for (
const auto &TLoc : DTI->template_arguments())
6995 bool OnlyDeduced,
unsigned Depth,
6996 llvm::SmallBitVector &
Used) {
7010 llvm::SmallBitVector &
Used) {
7013 = dyn_cast<TemplateTemplateParmDecl>(
Template)) {
7034 llvm::SmallBitVector &
Used) {
7039 if (!T->isDependentType())
7043 switch (T->getTypeClass()) {
7052 case Type::BlockPointer:
7060 case Type::LValueReference:
7061 case Type::RValueReference:
7069 case Type::MemberPointer: {
7075 OnlyDeduced, Depth,
Used);
7079 case Type::DependentSizedArray:
7082 OnlyDeduced, Depth,
Used);
7086 case Type::ConstantArray:
7087 case Type::IncompleteArray:
7088 case Type::ArrayParameter:
7091 OnlyDeduced, Depth,
Used);
7094 case Type::ExtVector:
7097 OnlyDeduced, Depth,
Used);
7100 case Type::DependentVector: {
7108 case Type::DependentSizedExtVector: {
7118 case Type::DependentAddressSpace: {
7122 OnlyDeduced, Depth,
Used);
7125 OnlyDeduced, Depth,
Used);
7129 case Type::ConstantMatrix: {
7136 case Type::CooperativeMatrix: {
7143 case Type::DependentSizedMatrix: {
7154 case Type::FunctionProto: {
7158 for (
unsigned I = 0, N = Proto->
getNumParams(); I != N; ++I) {
7163 if (!OnlyDeduced || I + 1 == N ||
7181 case Type::TemplateTypeParm: {
7183 if (TTP->getDepth() == Depth)
7184 Used[TTP->getIndex()] =
true;
7188 case Type::SubstTemplateTypeParmPack: {
7189 const SubstTemplateTypeParmPackType *Subst
7191 if (Subst->getReplacedParameter()->getDepth() == Depth)
7192 Used[Subst->getIndex()] =
true;
7197 case Type::SubstBuiltinTemplatePack: {
7199 OnlyDeduced, Depth,
Used);
7203 case Type::InjectedClassName:
7206 ->getCanonicalTemplateSpecializationType(Ctx);
7209 case Type::TemplateSpecialization: {
7210 const TemplateSpecializationType *Spec
7227 for (
const auto &Arg : Spec->template_arguments())
7236 OnlyDeduced, Depth,
Used);
7243 OnlyDeduced, Depth,
Used);
7246 case Type::DependentName:
7250 OnlyDeduced, Depth,
Used);
7256 OnlyDeduced, Depth,
Used);
7259 case Type::TypeOfExpr:
7263 OnlyDeduced, Depth,
Used);
7266 case Type::Decltype:
7270 OnlyDeduced, Depth,
Used);
7273 case Type::PackIndexing:
7276 OnlyDeduced, Depth,
Used);
7278 OnlyDeduced, Depth,
Used);
7282 case Type::UnaryTransform:
7285 auto Next = UTT->getUnderlyingType();
7287 Next = UTT->getBaseType();
7292 case Type::PackExpansion:
7295 OnlyDeduced, Depth,
Used);
7299 case Type::DeducedTemplateSpecialization:
7302 OnlyDeduced, Depth,
Used);
7304 case Type::DependentBitInt:
7307 OnlyDeduced, Depth,
Used);
7310 case Type::HLSLAttributedResource:
7317 OnlyDeduced, Depth,
Used);
7322 case Type::VariableArray:
7323 case Type::FunctionNoProto:
7326 case Type::ObjCInterface:
7327 case Type::ObjCObject:
7328 case Type::ObjCObjectPointer:
7329 case Type::UnresolvedUsing:
7332 case Type::HLSLInlineSpirv:
7333 case Type::OverflowBehavior:
7334#define TYPE(Class, Base)
7335#define ABSTRACT_TYPE(Class, Base)
7336#define DEPENDENT_TYPE(Class, Base)
7337#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
7338#include "clang/AST/TypeNodes.inc"
7350 llvm::SmallBitVector &
Used) {
7368 OnlyDeduced, Depth,
Used);
7386 llvm::SmallBitVector &
Used) {
7391 const Expr *E,
unsigned Depth, llvm::SmallBitVector &
Used) {
7392 MarkUsedTemplateParameterVisitor(
Used, Depth,
false)
7393 .TraverseStmt(
const_cast<Expr *
>(E));
7398 bool OnlyDeduced,
unsigned Depth,
7399 llvm::SmallBitVector &
Used) {
7408 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
7414 bool OnlyDeduced,
unsigned Depth,
7415 llvm::SmallBitVector &
Used) {
7419 for (
unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
7426 llvm::SmallBitVector &
Used) {
7427 for (
unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
7429 false, Depth,
Used);
7434 llvm::SmallBitVector &
Deduced) {
7441 for (
unsigned I = 0, N =
Function->getNumParams(); I != N; ++I)
7449 if (!T->isDependentType())
7454 llvm::SmallBitVector
Deduced(TemplateParams->
size());
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Provides definitions for the various language-specific address spaces.
static Decl::Kind getKind(const Decl *D)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static AccessResult DeduceTemplateArguments(Sema &S, FriendTemplateDecl *FTD, DeclContext *DC, const TemplateSpecializationType *TST, ArrayRef< TemplateParameterList * > TPLs, TemplateSpecCandidateSet *FailedTSC, MultiLevelTemplateArgumentList &DeducedArgs)
static TemplateDeductionResult DeduceNullPtrTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeOrVarTemplateParmDecl NTTP, QualType NullPtrType, TemplateDeductionInfo &Info, bool PartialOrdering, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool *HasDeducedAnyParam)
Deduce the value of the given non-type template parameter from the given null pointer template argume...
static bool ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param, DeducedTemplateArgument Arg, NamedDecl *Template, TemplateDeductionInfo &Info, bool IsDeduced, Sema::CheckTemplateArgumentInfo &CTAI)
Convert the given deduced template argument and add it to the set of fully-converted template argumen...
static TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, ArrayRef< TemplateArgument > Ps, ArrayRef< TemplateArgument > As, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool NumberOfArgumentsMustMatch, bool PartialOrdering, PackFold PackFold, bool *HasDeducedAnyParam)
static TemplateDeductionResult DeduceTemplateSpecArguments(Sema &S, TemplateParameterList *TemplateParams, const QualType P, QualType A, TemplateDeductionInfo &Info, bool PartialOrdering, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool *HasDeducedAnyParam)
static TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(Sema &S, TemplateParameterList *TemplateParams, QualType Param, QualType Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned TDF, PartialOrderingKind POK, bool DeducedFromArrayBound, bool *HasDeducedAnyParam)
Deduce the template arguments by comparing the parameter type and the argument type (C++ [temp....
static TemplateDeductionResult CheckDeductionConsistency(Sema &S, FunctionTemplateDecl *FTD, UnsignedOrNone ArgIdx, QualType P, QualType A, ArrayRef< TemplateArgument > DeducedArgs, bool CheckConsistency)
static PartialOrderingKind degradeCallPartialOrderingKind(PartialOrderingKind POK)
When propagating a partial ordering kind into a NonCall context, this is used to downgrade a 'Call' i...
static MoreSpecializedTrailingPackTieBreakerResult getMoreSpecializedTrailingPackTieBreaker(const TemplateSpecializationType *TST1, const TemplateSpecializationType *TST2)
static TemplateLikeDecl * getMoreSpecialized(Sema &S, QualType T1, QualType T2, TemplateLikeDecl *P1, PrimaryDel *P2, TemplateDeductionInfo &Info)
Returns the more specialized template specialization between T1/P1 and T2/P2.
static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y, bool AggregateCandidateDeduction=false)
Verify that the given, deduced template arguments are compatible.
static const Expr * unwrapExpressionForDeduction(const Expr *E)
static bool isSameDeclaration(Decl *X, Decl *Y)
Determine whether two declaration pointers refer to the same declaration.
static TemplateDeductionResult DeduceForEachType(Sema &S, TemplateParameterList *TemplateParams, ArrayRef< QualType > Params, ArrayRef< QualType > Args, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, PartialOrderingKind POK, bool FinishingDeduction, T &&DeductFunc)
static void AddFriendTemplateDeductionCandidate(Sema &S, TemplateDecl *TD, TemplateDeductionInfo &Info, TemplateDeductionResult Result, TemplateSpecCandidateSet *FailedTSC)
static TemplateDeductionResult DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD, TemplateParameterList *TemplateParams, QualType P, TemplateDeductionInfo &Info, bool PartialOrdering, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool *HasDeducedAnyParam)
Attempt to deduce the template arguments by checking the base types according to (C++20 [temp....
static bool hasTemplateArgumentForDeduction(ArrayRef< TemplateArgument > &Args, unsigned &ArgIdx)
Determine whether there is a template argument to be used for deduction.
static DeclContext * getAsDeclContextOrEnclosing(Decl *D)
static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, QualType ArgType)
Determine whether the parameter has qualifiers that the argument lacks.
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.
static UnsignedOrNone 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 ...
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 bool hasPackExpansionBeforeEnd(ArrayRef< TemplateArgument > Args)
Determine whether the given set of template arguments has a pack expansion that is not the last templ...
static bool isSimpleTemplateIdType(QualType T)
Determine whether the given type T is a simple-template-id type.
PartialOrderingKind
The kind of PartialOrdering we're performing template argument deduction for (C++11 [temp....
static NonTypeOrVarTemplateParmDecl getNTTParameterFromExpr(const Expr *E, UnsignedOrNone Depth)
If the given expression is of a form that names a non-type template parameter, return the declaration...
MoreSpecializedTrailingPackTieBreakerResult
static TemplateParameter makeTemplateParameter(Decl *D)
Helper function to build a TemplateParameter when we don't know its type statically.
static 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...
static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType &ParamType, QualType &ArgType, Expr::Classification ArgClassification, Expr *Arg, unsigned &TDF, TemplateSpecCandidateSet *FailedTSC=nullptr)
Perform the adjustments to the parameter and argument types described in C++ [temp....
static TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType ParamType, QualType ArgType, Expr::Classification ArgClassification, Expr *Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, bool DecomposedParam, unsigned ArgIdx, unsigned TDF, TemplateSpecCandidateSet *FailedTSC=nullptr)
Perform template argument deduction per [temp.deduct.call] for a single parameter / argument pair.
static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc, FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, TemplatePartialOrderingContext TPOC, ArrayRef< QualType > Args1, ArrayRef< QualType > Args2, bool Args1Offset)
Determine whether the function template FT1 is at least as specialized as FT2.
static QualType GetImplicitObjectParameterType(ASTContext &Context, const CXXMethodDecl *Method, QualType RawType, bool IsOtherRvr)
static 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...
static unsigned getFirstInnerIndex(FunctionTemplateDecl *FTD)
Get the index of the first template parameter that was originally from the innermost template-paramet...
static TemplateDeductionResult CheckDeducedTemplateArgumentList(Sema &S, TemplateDecl *Template, ArrayRef< TemplateArgumentLoc > Ps, ArrayRef< TemplateArgument > As, const MultiLevelTemplateArgumentList &MLTAL, TemplateDeductionInfo &Info)
PackFold
What directions packs are allowed to match non-packs.
static QualType getTypeOfTemplateArgumentValue(TemplateDeductionInfo &Info, const TemplateArgument &A)
C++26 [temp.deduct.type]p13: When the value of the argument corresponding to a constant template para...
static TemplateDeductionResult ConvertDeducedTemplateArguments(Sema &S, NamedDecl *Template, TemplateParameterList *TemplateParams, bool IsDeduced, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info, Sema::CheckTemplateArgumentInfo &CTAI, LocalInstantiationScope *CurrentInstantiationScope, unsigned NumAlreadyConverted, bool *IsIncomplete)
static QualType ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams, Expr *Arg, QualType ParamType, bool ParamWasReference, TemplateSpecCandidateSet *FailedTSC=nullptr)
Apply the deduction rules for overload sets.
static bool IsPossiblyOpaquelyQualifiedType(QualType T)
Determines whether the given type is an opaque type that might be more qualified when instantiated.
static TemplateDeductionResult CheckDeducedArgumentConstraints(Sema &S, NamedDecl *Template, ArrayRef< TemplateArgument > SugaredDeducedArgs, ArrayRef< TemplateArgument > CanonicalDeducedArgs, TemplateDeductionInfo &Info)
static const TemplateSpecializationType * getLastTemplateSpecType(QualType QT)
Deduce the template arguments by comparing the template parameter type (which is a template-id) with ...
static TemplateDeductionResult instantiateExplicitSpecifierDeferred(Sema &S, FunctionDecl *Specialization, const MultiLevelTemplateArgumentList &SubstArgs, TemplateDeductionInfo &Info, FunctionTemplateDecl *FunctionTemplate, ArrayRef< TemplateArgument > DeducedArgs)
static bool CheckDeducedPlaceholderConstraints(Sema &S, const AutoType &Type, AutoTypeLoc TypeLoc, QualType Deduced)
static TemplateDeductionResult DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, const NonTypeOrVarTemplateParmDecl NTTP, const DeducedTemplateArgument &NewDeduced, QualType ValueType, TemplateDeductionInfo &Info, bool PartialOrdering, SmallVectorImpl< DeducedTemplateArgument > &Deduced, bool *HasDeducedAnyParam)
Deduce the value of the given non-type template parameter as the given deduced template argument.
static bool IsPossiblyOpaquelyQualifiedTypeInternal(const Type *T)
static bool hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate, QualType T)
static bool isForwardingReference(QualType Param, unsigned FirstInnerIndex)
Determine whether a type denotes a forwarding reference.
static TemplateDeductionResult FinishTemplateArgumentDeduction(Sema &S, NamedDecl *Entity, TemplateParameterList *EntityTPL, TemplateDecl *Template, bool PartialOrdering, ArrayRef< TemplateArgumentLoc > Ps, ArrayRef< TemplateArgument > As, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info, bool CopyDeducedArgs)
Complete template argument deduction.
static bool isParameterPack(Expr *PackExpression)
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::TemplateNameKind enum.
Defines the clang::TypeLoc interface and its subclasses.
static const TemplateArgument & getArgument(const TemplateArgument &A)
C Language Family Type Representation.
SourceLocation getLocation() const
const TemplateTemplateParmDecl * getTemplate() const
bool isExpandedParameterPack() const
const NonTypeTemplateParmDecl * getNTTP() const
unsigned getIndex() const
NonTypeOrVarTemplateParmDecl(const NamedDecl *Template)
TemplateParameter asTemplateParam() const
unsigned getDepth() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
unsigned getIntWidth(QualType T) const
QualType getAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, TemplateName TypeConstraintConcept=TemplateName(), ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) const
Retrieve the "canonical" template argument.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
const LangOptions & getLangOpts() const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedIntTy
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
bool hasSameTemplateName(const TemplateName &X, const TemplateName &Y, bool IgnoreDeduced=false) const
Determine whether the given template names refer to the same template.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
bool isSameTemplateArgument(const TemplateArgument &Arg1, const TemplateArgument &Arg2) const
Determine whether the given template arguments Arg1 and Arg2 are equivalent.
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals) const
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals.
TemplateName getDeducedTemplateName(TemplateName Underlying, DefaultArguments DefaultArgs) const
Represents a TemplateName which had some of its default arguments deduced.
QualType getDeducedTemplateSpecializationType(DeducedKind DK, QualType DeducedAsType, ElaboratedTypeKeyword Keyword, TemplateName Template) const
C++17 deduced class template specialization type.
const DependentSizedArrayType * getAsDependentSizedArrayType(QualType T) const
TypeLoc getValueLoc() const
A fixed int type of a specified bitwidth.
Represents a C++ conversion function within a class.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Represents a static or instance method of a struct/union/class.
bool isExplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An explicit object member function is a non-static member function with an explic...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
The null pointer literal (C++11 [lex.nullptr])
Represents a C++ struct/union/class.
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Declaration of a class template.
CanQualType getCanonicalInjectedSpecializationType(const ASTContext &Ctx) const
Retrieve the canonical template specialization type of the injected-class-name for this class templat...
CanQualType getCanonicalInjectedSpecializationType(const ASTContext &Ctx) const
Retrieves the canonical injected specialization type for this partial specialization.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Complex values, per C99 6.2.5p11.
Declaration of a C++20 concept.
const TypeClass * getTypePtr() const
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Represents an opaque OpenCL cooperative matrix type.
QualType getElementType() const
Returns the element type.
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Decl - This represents one declaration (or definition), e.g.
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
ASTContext & getASTContext() const LLVM_READONLY
bool isInvalidDecl() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Captures a template argument whose value has been deduced via c++ template argument deduction.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
SourceLocation getElaboratedKeywordLoc() const
NestedNameSpecifierLoc getQualifierLoc() const
Represents an extended address space qualifier where the input address space value is dependent.
Expr * getAddrSpaceExpr() const
QualType getPointeeType() const
Represents an extended vector type where either the type or size is dependent.
Expr * getSizeExpr() const
QualType getElementType() const
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Expr * getColumnExpr() const
Expr * getRowExpr() const
TemplateTemplateParmDecl * getParameter() const
Represents a vector type where either the type or size is dependent.
virtual bool TraverseTemplateName(TemplateName Template, bool TraverseQualifier=true)
virtual bool TraverseType(QualType T, bool TraverseQualifier=true)
RAII object that enters a new expression evaluation context.
Store information needed for an explicit specifier.
bool isInvalid() const
Determine if the explicit specifier is invalid.
const Expr * getExpr() const
The return type of classify().
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
ExtVectorType - Extended vector type.
Stores a list of template parameters and the associated requires-clause (if any) for a TemplateDecl a...
Declaration of a friend template.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool hasCXXExplicitFunctionObjectParameter() const
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
void getAssociatedConstraints(SmallVectorImpl< AssociatedConstraint > &ACs) const
Get the associated-constraints of this function declaration.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isImmediateEscalating() const
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
size_t param_size() const
Represents a prototype with parameter type info, e.g.
param_type_iterator param_type_begin() const
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
unsigned getNumParams() const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Qualifiers getMethodQuals() const
QualType getParamType(unsigned i) const
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
param_type_iterator param_type_end() const
ArrayRef< QualType > getParamTypes() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
Describes an C or C++ initializer list.
unsigned getNumInits() const
unsigned getNumInitsWithEmbedExpanded() const
getNumInits but if the list has an EmbedExpr inside includes full length of embedded data.
ArrayRef< Expr * > inits() const
An lvalue reference type, per C++11 [dcl.ref].
A stack-allocated class that identifies which local variable declaration instantiations are present i...
NamedDecl * getPartiallySubstitutedPack(const TemplateArgument **ExplicitArgs=nullptr, unsigned *NumExplicitArgs=nullptr) const
Retrieve the partially-substitued template parameter pack.
void ResetPartiallySubstitutedPack()
Reset the partially-substituted pack when it is no longer of interest.
Represents a matrix type, as defined in the Matrix Types clang extensions.
QualType getElementType() const
Returns type of the elements being stored in the matrix.
A pointer to member type per C++ 8.3.3 - Pointers to members.
NestedNameSpecifier getQualifier() const
QualType getPointeeType() const
Data structure that captures multiple levels of template argument lists for use in template instantia...
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args, bool Final)
Add a new outmost level to the multi-level template argument list.
void addOuterRetainedLevels(unsigned Num)
bool isAnyArgInstantiationDependent() const
void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args, bool Final=false)
Replaces the current 'innermost' level with the provided argument list.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const Type * getAsType() const
@ Type
A type, stored as a Type*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Represents a pointer to an Objective C object.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
SourceLocation getNameLoc() const
Gets the location of the name.
decls_iterator decls_begin() const
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
decls_iterator decls_end() const
Represents a C++11 pack expansion that produces a sequence of expressions.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Represents a template name as written in source code.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
void removeCVRQualifiers(unsigned mask)
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
void removeObjCLifetime()
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers,...
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const
Determines if these qualifiers compatibly include another set.
bool hasAddressSpace() const
void removeAddressSpace()
bool hasObjCGCAttr() const
void setCVRQualifiers(unsigned mask)
bool hasObjCLifetime() const
ObjCLifetime getObjCLifetime() const
Qualifiers withoutObjCLifetime() const
LangAS getAddressSpace() const
void setObjCLifetime(ObjCLifetime type)
An rvalue reference type, per C++11 [dcl.ref].
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context) const
Retrieve the "injected" template arguments that correspond to the template parameters of this templat...
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeType() const
Scope - A scope is a transient data structure that is used while parsing the program.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
RAII object used to change the argument pack substitution index within a Sema object.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
A helper class for building up ExtParameterInfos.
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Sema - This implements semantic analysis and AST building for C.
bool TryFunctionConversion(QualType FromType, QualType ToType, QualType &ResultTy) const
Same as IsFunctionConversion, but if this would return true, it sets ResultTy to ToType.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
TemplateDeductionResult DeduceTemplateArgumentsFromType(TemplateDecl *TD, QualType FromType, sema::TemplateDeductionInfo &Info)
Deduce the template arguments of the given template from FromType.
QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement)
Completely replace the auto in TypeWithAuto by Replacement.
bool TemplateParameterListsAreEqual(const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New, const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc=SourceLocation())
Determine whether the given template parameter lists are equivalent.
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
FunctionDecl * getMoreConstrainedFunction(FunctionDecl *FD1, FunctionDecl *FD2)
Returns the more constrained function according to the rules of partial ordering by constraints (C++ ...
FunctionDecl * InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, const TemplateArgumentList *Args, SourceLocation Loc, CodeSynthesisContext::SynthesisKind CSC=CodeSynthesisContext::ExplicitTemplateArgumentSubstitution)
Instantiate (or find existing instantiation of) a function template with a given set of template argu...
QualType BuildStdInitializerList(QualType Element, SourceLocation Loc)
Looks for the std::initializer_list template and instantiates it with Element, or emits an error if i...
TemplateDeductionResult FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, SmallVectorImpl< OriginalCallArg > const *OriginalCallArgs, bool PartialOverloading, bool PartialOrdering, bool ForOverloadSetAddressResolution, llvm::function_ref< bool(bool)> CheckNonDependent=[](bool) { return false;})
Finish template argument deduction for a function template, checking the deduced template arguments f...
@ CTAK_DeducedFromArrayBound
The template argument was deduced from an array bound via template argument deduction.
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
@ CTAK_Deduced
The template argument was deduced via template argument deduction.
bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, bool Diagnose=true)
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
void MarkUsedTemplateParametersForSubsumptionParameterMapping(const Expr *E, unsigned Depth, llvm::SmallBitVector &Used)
Mark which template parameters are named in a given expression.
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
ExprResult BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, SourceLocation Loc)
ASTContext & getASTContext() const
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.
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.
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg, const DefaultArguments &DefaultArgs, SourceLocation ArgLoc, bool PartialOrdering, bool *StrictPackMatch)
PrintingPolicy getPrintingPolicy() const
Retrieve a suitable printing policy for diagnostics.
bool SubstTemplateArguments(ArrayRef< TemplateArgumentLoc > Args, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgumentListInfo &Outputs)
bool CheckConstraintSatisfaction(ConstrainedDeclOrNestedRequirement Entity, ArrayRef< AssociatedConstraint > AssociatedConstraints, const MultiLevelTemplateArgumentList &TemplateArgLists, SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction, const ConceptReference *TopLevelConceptId=nullptr, Expr **ConvertedExpr=nullptr)
Check whether the given list of constraint expressions are satisfied (as if in a 'conjunction') given...
@ TPL_TemplateParamsEquivalent
We are determining whether the template-parameters are equivalent according to C++ [temp....
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg)
Compare types for equality with respect to possibly compatible function types (noreturn adjustment,...
const LangOptions & getLangOpts() const
UnsignedOrNone getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location.
ExplicitSpecifier instantiateExplicitSpecifier(const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES)
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...
FunctionDecl * resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult)
Given an expression that refers to an overloaded function, try to resolve that function to a single f...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const DeclContext *DC=nullptr, bool Final=false, std::optional< ArrayRef< TemplateArgument > > Innermost=std::nullopt, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false, bool ForDefaultArgumentSubstitution=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
SuppressedDiagnosticsMap SuppressedDiagnostics
void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, SourceLocation Loc={}, bool First=true)
Emit diagnostics explaining why a constraint expression was deemed unsatisfied.
bool IsDerivedFrom(SourceLocation Loc, CXXRecordDecl *Derived, CXXRecordDecl *Base, CXXBasePaths &Paths)
Determine whether the type Derived is a C++ class that is derived from the type Base.
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
FunctionDecl * ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, bool Complain=false, DeclAccessPair *Found=nullptr, TemplateSpecCandidateSet *FailedTSC=nullptr, bool ForTypeDeduction=false)
Given an expression that refers to an overloaded function, try to resolve that overloaded function ex...
QualType getDecltypeForExpr(Expr *E)
getDecltypeForExpr - Given an expr, will return the decltype for that expression, according to the ru...
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Decl * SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
bool SubstParmTypes(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const FunctionProtoType::ExtParameterInfo *ExtParamInfos, const MultiLevelTemplateArgumentList &TemplateArgs, SmallVectorImpl< QualType > &ParamTypes, SmallVectorImpl< ParmVarDecl * > *OutParams, ExtParameterInfoBuilder &ParamInfos, const QualType *OldParamTypes=nullptr, bool EvaluateConstraints=true, const FunctionDecl *Fn=nullptr, LateInstantiatedAttrVec *ParamAttrs=nullptr)
Substitute the given template arguments into the given set of parameters, producing the set of parame...
TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, SourceLocation RAngleLoc, Decl *Param, ArrayRef< TemplateArgument > SugaredConverted, ArrayRef< TemplateArgument > CanonicalConverted, bool &HasDefaultArg)
If the given template parameter has a default template argument, substitute into that default templat...
TypeSourceInfo * SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto)
TypeSourceInfo * ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
TemplateParameterList * SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs, bool EvaluateConstraints=true)
bool isSFINAEContext() const
bool isCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind=CompleteTypeKind::Default)
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,...
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.
void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark which template parameters are used in a given expression.
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
QualType getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, CallingConv CC)
Get the return type to use for a lambda's conversion function(s) to function pointer type,...
static QualType getTypeOfConstantTemplateParameter(const TemplateArgument &Arg)
Determine the declared type of the constant template parameter that Arg names, if any.
QualType getCompletedType(Expr *E)
Get the type of expression E, triggering instantiation to complete the type if necessary – that is,...
TypeSourceInfo * SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
bool IsAtLeastAsConstrained(const NamedDecl *D1, MutableArrayRef< AssociatedConstraint > AC1, const NamedDecl *D2, MutableArrayRef< AssociatedConstraint > AC2, bool &Result)
Check whether the given declaration's associated constraints are at least as constrained than another...
void DiagnoseAutoDeductionFailure(const VarDecl *VDecl, const Expr *Init)
TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, SourceLocation Location)
Get a template argument mapping the given template parameter to itself, e.g.
bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD, SourceLocation Loc)
QualType SubstAutoTypeDependent(QualType TypeWithAuto)
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, ArrayRef< TemplateArgument > TemplateArgs, sema::TemplateDeductionInfo &Info)
bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation, FunctionDecl *Decl, ArrayRef< TemplateArgument > TemplateArgs, ConstraintSatisfaction &Satisfaction)
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
Run some code with "sufficient" stack space.
bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, sema::TemplateDeductionInfo &Info)
bool IsFunctionConversion(QualType FromType, QualType ToType) const
Determine whether the conversion from FromType to ToType is a valid conversion of ExtInfo/ExtProtoInf...
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
bool CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, const DefaultArguments &DefaultArgs, bool PartialTemplateArgs, CheckTemplateArgumentInfo &CTAI, bool UpdateArgsWithConversions=true, bool *ConstraintsNotSatisfied=nullptr)
Check that the given template arguments can be provided to the given template, converting the argumen...
void adjustMemberFunctionCC(QualType &T, bool HasThisPointer, bool IsCtorOrDtor, SourceLocation Loc)
Adjust the calling convention of a method to be the ABI default if it wasn't specified explicitly.
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...
@ Diagnose
Diagnose issues that are non-constant or that are extensions.
TemplateDeductionResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, sema::TemplateDeductionInfo &Info, bool DependentDeduction=false, bool IgnoreConstraints=false, TemplateSpecCandidateSet *FailedTSC=nullptr)
Deduce the type for an auto type-specifier (C++11 [dcl.spec.auto]p6)
QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, bool AdjustExceptionSpec=false)
Adjust the type ArgFunctionType to match the calling convention, noreturn, and optionally the excepti...
void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType)
HandleFunctionTypeMismatch - Gives diagnostic information for differeing function types.
FunctionTemplateDecl * getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, QualType RawObj1Ty={}, QualType RawObj2Ty={}, bool Reversed=false, bool PartialOverloading=false)
Returns the more specialized function template according to the rules of function template partial or...
void MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced)
NamedDecl * getPack() const
Retrieve the parameter pack.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
A template argument list.
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.
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
Represents a template argument.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) const
Used to insert TemplateArguments into FoldingSets.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
bool isNull() const
Determine whether this template argument has no value.
static TemplateArgument getEmptyPack()
unsigned pack_size() const
The number of template arguments in the given template argument pack.
bool structurallyEquals(const TemplateArgument &Other) const
Determines whether two template arguments are superficially the same.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
The base class of all kinds of template declarations (e.g., class, function, etc.).
void getAssociatedConstraints(llvm::SmallVectorImpl< AssociatedConstraint > &AC) const
Get the total constraint-expression associated with this template, including constraint-expressions d...
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
ArrayRef< TemplateArgument > getInjectedTemplateArgs(const ASTContext &Context)
Get the template argument list of the template parameter list.
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
void getAssociatedConstraints(llvm::SmallVectorImpl< AssociatedConstraint > &AC) const
All associated constraints derived from this template parameter list, including the requires clause a...
ArrayRef< NamedDecl * > asArray()
SourceLocation getTemplateLoc() const
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
void NoteCandidates(Sema &S, SourceLocation Loc)
NoteCandidates - When no template specialization match is found, prints diagnostic messages containin...
TemplateSpecCandidate & addCandidate()
Add a new candidate with NumConversions conversion sequence slots to the overload set.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
TemplateNameKind templateParameterKind() const
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
unsigned getDepth() const
Get the nesting depth of the template parameter.
bool isExpandedParameterPack() const
Whether this parameter is a template template parameter pack that has a known list of different templ...
Declaration of a template type parameter.
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, int D, int P, IdentifierInfo *Id, bool Typename, bool ParameterPack, bool HasTypeConstraint=false, UnsignedOrNone NumExpanded=std::nullopt)
const Type * getTypeForDecl() const
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
SourceRange getLocalSourceRange() const
Get the local source range.
unsigned getFullDataSize() const
Returns the size of the type source info data block.
void copy(TypeLoc other)
Copies the other type loc into this one.
A container of type source information.
QualType getType() const
Return the type wrapped by this type source info.
SourceLocation getNameLoc() const
void setNameLoc(SourceLocation Loc)
The base class of the type hierarchy.
const TemplateSpecializationType * getAsNonAliasTemplateSpecializationType() const
Look through sugar for an instance of TemplateSpecializationType which is not a type alias,...
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
bool isRValueReferenceType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isFunctionPointerType() const
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isLValueReferenceType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getCanonicalTypeInternal() const
bool isMemberPointerType() const
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool isFunctionType() const
bool isMemberFunctionPointerType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isAnyPointerType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
The iterator over UnresolvedSets.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
Declaration of a variable template.
VarTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Represents a GCC generic vector type.
Provides information about an attempted template argument deduction, whose success or failure was des...
void setExplicitArgs(TemplateArgumentList *NewDeducedSugared, TemplateArgumentList *NewDeducedCanonical)
Provide an initial template argument list that contains the explicitly-specified arguments.
TemplateArgumentList * takeCanonical()
TemplateArgumentList * takeSugared()
Take ownership of the deduced template argument lists.
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
void clearSFINAEDiagnostic()
Discard any SFINAE diagnostics.
TemplateArgument SecondArg
The second template argument to which the template argument deduction failure refers.
void setStrictPackMatch()
TemplateParameter Param
The template parameter to which a template argument deduction failure refers.
diag_iterator diag_end() const
Returns an iterator at the end of the sequence of suppressed diagnostics.
void reset(TemplateArgumentList *NewDeducedSugared, TemplateArgumentList *NewDeducedCanonical)
Provide a new template argument list that contains the results of template argument deduction.
unsigned getDeducedDepth() const
The depth of template parameters for which deduction is being performed.
diag_iterator diag_begin() const
Returns an iterator at the beginning of the sequence of suppressed diagnostics.
TemplateArgument FirstArg
The first template argument to which the template argument deduction failure refers.
ConstraintSatisfaction AssociatedConstraintsSatisfaction
The constraint satisfaction details resulting from the associated constraints satisfaction tests.
unsigned CallArgIndex
The index of the function argument that caused a deduction failure.
bool hasStrictPackMatch() const
__inline void unsigned int _2
Top level wrappers for InstallAPI frontend operations.
@ OO_None
Not an overloaded operator.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
bool isa(CodeGen::Address addr)
@ GNUAutoType
__auto_type (GNU extension)
bool isTargetAddressSpace(LangAS AS)
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
@ Both
Look for allocation functions in both the global scope and in the scope of the allocated class.
@ RQ_None
No ref-qualifier was provided.
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
NamedDecl * getAsNamedDecl(TemplateParameter P)
bool isPackProducingBuiltinTemplateName(TemplateName N)
UnsignedOrNone getExpandedPackSize(const NamedDecl *Param)
Check whether the template parameter is a pack expansion, and if so, determine the number of paramete...
unsigned toTargetAddressSpace(LangAS AS)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
std::pair< unsigned, unsigned > getDepthAndIndex(const NamedDecl *ND)
Retrieve the depth and index of a template parameter.
OptionalUnsigned< unsigned > UnsignedOrNone
@ Template
We are parsing a template declaration.
ActionResult< CXXBaseSpecifier * > BaseResult
DeductionFailureInfo MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, sema::TemplateDeductionInfo &Info)
Convert from Sema's representation of template deduction information to the form used in overload-can...
@ FunctionTemplate
The name was classified as a function template name.
@ Concept
The name was classified as a concept name.
bool isLambdaConversionOperator(CXXConversionDecl *C)
@ Deduced
The normal deduced case.
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
@ DeducedAsPack
Same as above, but additionally this represents a case where the deduced entity itself is a pack.
@ DeducedAsDependent
This is a special case where the initializer is dependent, so we can't deduce a type yet.
@ TNK_Var_template
The name refers to a variable template whose specialization produces a variable.
@ TNK_Concept_template
The name refers to a concept.
llvm::PointerUnion< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
TPOC
The context in which partial ordering of function templates occurs.
@ TPOC_Conversion
Partial ordering of function templates for a call to a conversion function.
@ TPOC_Other
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
@ TPOC_Call
Partial ordering of function templates for a function call.
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
TemplateDeductionResult
Describes the result of template argument deduction.
@ MiscellaneousDeductionFailure
Deduction failed; that's all we know.
@ NonDependentConversionFailure
Checking non-dependent argument conversions failed.
@ ConstraintsNotSatisfied
The deduced arguments did not satisfy the constraints associated with the template.
@ Underqualified
Template argument deduction failed due to inconsistent cv-qualifiers on a template parameter type tha...
@ InstantiationDepth
Template argument deduction exceeded the maximum template instantiation depth (which has already been...
@ InvalidExplicitArguments
The explicitly-specified template arguments were not valid template arguments for the given template.
@ CUDATargetMismatch
CUDA Target attributes do not match.
@ TooFewArguments
When performing template argument deduction for a function template, there were too few call argument...
@ Incomplete
Template argument deduction did not deduce a value for every template parameter.
@ Invalid
The declaration was invalid; do nothing.
@ Success
Template argument deduction was successful.
@ SubstitutionFailure
Substitution of the deduced template argument values resulted in an error.
@ IncompletePack
Template argument deduction did not deduce a value for every expansion of an expanded template parame...
@ DeducedMismatch
After substituting deduced template arguments, a dependent parameter type did not match the correspon...
@ Inconsistent
Template argument deduction produced inconsistent deduced values for the given template parameter.
@ TooManyArguments
When performing template argument deduction for a function template, there were too many call argumen...
@ AlreadyDiagnosed
Some error which was already diagnosed.
@ DeducedMismatchNested
After substituting deduced template arguments, an element of a dependent parameter type did not match...
@ NonDeducedMismatch
A non-depnedent component of the parameter did not match the corresponding component of the argument.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Noexcept
Condition in a noexcept(bool) specifier.
@ PackIndex
Index of a pack indexing expression or specifier.
@ None
No keyword precedes the qualified type name.
ActionResult< Expr * > ExprResult
@ EST_Uninstantiated
not instantiated yet
@ EST_None
no exception specification
TemplateDeductionFlags
Various flags that control template argument deduction.
@ TDF_None
No template argument deduction flags, which indicates the strictest results for template argument ded...
@ TDF_DerivedClass
Within template argument deduction from a function call, we are matching in a case where we can perfo...
@ TDF_TopLevelParameterTypeList
Whether we are performing template argument deduction for parameters and arguments in a top-level tem...
@ TDF_IgnoreQualifiers
Within template argument deduction from a function call, we are matching in a case where we ignore cv...
@ TDF_ParamWithReferenceType
Within template argument deduction from a function call, we are matching with a parameter type for wh...
@ TDF_SkipNonDependent
Allow non-dependent types to differ, e.g., when performing template argument deduction from a functio...
@ TDF_AllowCompatibleFunctionType
Within template argument deduction from overload resolution per C++ [over.over] allow matching functi...
@ TDF_ArgWithReferenceType
Within template argument deduction for a conversion function, we are matching with an argument type f...
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
static constexpr bool value
static constexpr bool value
static constexpr bool value
A pack that we're currently deducing.
DeducedPack(unsigned Index)
SmallVector< DeducedTemplateArgument, 4 > New
DeducedTemplateArgument Saved
DeducedTemplateArgument DeferredDeduction
ExceptionSpecificationType Type
The kind of exception specification this is.
Extra information about a function prototype.
const ExtParameterInfo * ExtParameterInfos
bool StrictPackMatch
Is set to true when, in the context of TTP matching, a pack parameter matches non-pack arguments.
bool MatchingTTP
If true, assume these template arguments are the injected template arguments for a template template ...
bool PartialOrdering
The check is being performed in the context of partial ordering.
SmallVector< TemplateArgument, 4 > SugaredConverted
The checked, converted argument will be added to the end of these vectors.
SmallVector< TemplateArgument, 4 > CanonicalConverted
@ ExplicitTemplateArgumentSubstitution
We are substituting explicit template arguments provided for a function template.
@ DeducedTemplateArgumentSubstitution
We are substituting template argument determined as part of template argument deduction for either a ...
bool isPotentiallyEvaluated() const
A stack object to be created when performing template instantiation.
bool isInvalid() const
Determines whether we have exceeded the maximum recursive template instantiations.
brief A function argument from which we performed template argument
QualType OriginalParamType
Location information for a TemplateArgument.
TemplateSpecCandidate - This is a generalization of OverloadCandidate which keeps track of template a...
void set(DeclAccessPair Found, Decl *Spec, DeductionFailureInfo Info)