43 #include "llvm/ADT/APInt.h" 44 #include "llvm/ADT/APSInt.h" 45 #include "llvm/ADT/ArrayRef.h" 46 #include "llvm/ADT/DenseMap.h" 47 #include "llvm/ADT/FoldingSet.h" 48 #include "llvm/ADT/Optional.h" 49 #include "llvm/ADT/SmallBitVector.h" 50 #include "llvm/ADT/SmallPtrSet.h" 51 #include "llvm/ADT/SmallVector.h" 52 #include "llvm/Support/Casting.h" 53 #include "llvm/Support/Compiler.h" 54 #include "llvm/Support/ErrorHandling.h" 110 using namespace clang;
111 using namespace sema;
116 if (Y.getBitWidth() > X.getBitWidth())
117 X = X.extend(Y.getBitWidth());
118 else if (Y.getBitWidth() < X.getBitWidth())
119 Y = Y.extend(X.getBitWidth());
122 if (X.isSigned() != Y.isSigned()) {
124 if ((Y.isSigned() && Y.isNegative()) || (X.isSigned() && X.isNegative()))
152 bool DeducedFromArrayBound =
false);
160 bool NumberOfArgumentsMustMatch);
164 bool OnlyDeduced,
unsigned Depth,
165 llvm::SmallBitVector &
Used);
168 bool OnlyDeduced,
unsigned Level,
169 llvm::SmallBitVector &Deduced);
180 E = IC->getSubExpr();
182 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
183 E = Subst->getReplacement();
189 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
199 if (
NamedDecl *NX = dyn_cast<NamedDecl>(X))
200 X = NX->getUnderlyingDecl();
201 if (
NamedDecl *NY = dyn_cast<NamedDecl>(Y))
202 Y = NY->getUnderlyingDecl();
237 llvm_unreachable(
"Non-deduced template arguments handled above");
288 llvm::FoldingSetNodeID ID1, ID2;
352 XA != XAEnd; ++XA, ++YA) {
358 NewPack.push_back(Merged);
367 llvm_unreachable(
"Invalid TemplateArgument Kind!");
379 "deducing non-type template argument with wrong depth");
383 if (Result.isNull()) {
404 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
405 ParamType = Expansion->getPattern();
426 S, TemplateParams, NTTP,
428 DeducedFromArrayBound),
429 ValueType, Info, Deduced);
442 NullPtrType, CK_NullToPointer)
446 Value->
getType(), Info, Deduced);
459 Value->
getType(), Info, Deduced);
492 = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
499 Deduced[TempParam->getIndex()],
501 if (Result.isNull()) {
502 Info.
Param = TempParam;
503 Info.
FirstArg = Deduced[TempParam->getIndex()];
508 Deduced[TempParam->getIndex()] = Result;
547 assert(Arg.
isCanonical() &&
"Argument type must be canonical");
550 if (
auto *Injected = dyn_cast<InjectedClassNameType>(Arg))
551 Arg = Injected->getInjectedSpecializationType();
555 = dyn_cast<TemplateSpecializationType>(Arg)) {
560 SpecArg->getTemplateName(),
570 SpecArg->template_arguments(), Info, Deduced,
611 case Type::TypeOfExpr:
613 case Type::DependentName:
615 case Type::UnresolvedUsing:
616 case Type::TemplateTypeParm:
619 case Type::ConstantArray:
620 case Type::IncompleteArray:
621 case Type::VariableArray:
622 case Type::DependentSizedArray:
624 cast<ArrayType>(T)->getElementType());
644 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
645 if (NTTP->isExpandedParameterPack())
646 return NTTP->getNumExpansionTypes();
648 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param))
649 if (TTP->isExpandedParameterPack())
650 return TTP->getNumExpansionTemplateParameters();
679 class PackDeductionScope {
685 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
686 unsigned NumNamedPacks = addPacks(Pattern);
687 finishConstruction(NumNamedPacks);
694 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
696 finishConstruction(1);
700 void addPack(
unsigned Index) {
704 Pack.
Saved = Deduced[Index];
712 FixedNumExpansions = ExpandedPackExpansions;
714 Packs.push_back(Pack);
720 llvm::SmallBitVector SawIndices(TemplateParams->
size());
722 auto AddPack = [&](
unsigned Index) {
723 if (SawIndices[Index])
725 SawIndices[Index] =
true;
732 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
733 unsigned Depth, Index;
738 assert(!Packs.empty() &&
"Pack expansion without unexpanded packs?");
740 unsigned NumNamedPacks = Packs.size();
746 llvm::SmallBitVector
Used(TemplateParams->
size());
749 for (
int Index =
Used.find_first(); Index != -1;
750 Index =
Used.find_next(Index))
754 return NumNamedPacks;
757 void finishConstruction(
unsigned NumNamedPacks) {
760 unsigned NumPartialPackArgs = 0;
761 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
763 if (
auto *Partial =
Scope->getPartiallySubstitutedPack(
764 &PartialPackArgs, &NumPartialPackArgs))
770 bool IsExpanded =
true;
771 for (
unsigned I = 0; I != NumNamedPacks; ++I) {
774 IsPartiallyExpanded =
false;
777 if (PartialPackDepthIndex ==
779 IsPartiallyExpanded =
true;
785 if (IsPartiallyExpanded)
786 PackElements += NumPartialPackArgs;
788 PackElements += *FixedNumExpansions;
790 for (
auto &Pack : Packs) {
797 if (PartialPackDepthIndex ==
799 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
808 if (!IsPartiallyExpanded)
809 Deduced[Pack.Index] = Pack.New[PackElements];
815 ~PackDeductionScope() {
816 for (
auto &Pack : Packs)
822 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
827 bool hasFixedArity() {
return FixedNumExpansions.hasValue(); }
832 bool hasNextElement() {
833 return !FixedNumExpansions || *FixedNumExpansions > PackElements;
837 void nextPackElement() {
841 for (
auto &Pack : Packs) {
843 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
844 while (Pack.New.size() < PackElements)
846 if (Pack.New.size() == PackElements)
847 Pack.New.push_back(DeducedArg);
849 Pack.New[PackElements] = DeducedArg;
850 DeducedArg = Pack.New.size() > PackElements + 1
851 ? Pack.New[PackElements + 1]
862 finish(
bool TreatNoDeductionsAsNonDeduced =
true) {
865 for (
auto &Pack : Packs) {
867 Deduced[Pack.Index] = Pack.Saved;
873 if (!TreatNoDeductionsAsNonDeduced)
874 Pack.New.resize(PackElements);
878 if (PackElements && Pack.New.empty()) {
879 if (Pack.DeferredDeduction.isNull()) {
886 NewPack = Pack.DeferredDeduction;
888 }
else if (Pack.New.empty()) {
894 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
902 Pack.New[0].wasDeducedFromArrayBound());
908 if (Pack.Outer->DeferredDeduction.isNull()) {
911 Pack.Outer->DeferredDeduction = NewPack;
914 Loc = &Pack.Outer->DeferredDeduction;
916 Loc = &Deduced[Pack.Index];
925 if (!Result.
isNull() && !Pack.DeferredDeduction.isNull()) {
927 NewPack = Pack.DeferredDeduction;
942 if (*Expansions != PackElements) {
960 unsigned PackElements = 0;
961 bool IsPartiallyExpanded =
false;
1003 const QualType *Params,
unsigned NumParams,
1004 const QualType *Args,
unsigned NumArgs,
1008 bool PartialOrdering =
false) {
1023 if (ArgIdx >= NumArgs)
1026 if (isa<PackExpansionType>(Args[ArgIdx])) {
1053 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
1057 if (
ParamIdx + 1 == NumParams || PackScope.hasFixedArity()) {
1058 for (; ArgIdx < NumArgs && PackScope.hasNextElement(); ++ArgIdx) {
1062 Args[ArgIdx], Info, Deduced,
1066 PackScope.nextPackElement();
1087 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
1088 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < NumArgs;
1090 PackScope.nextPackElement();
1096 if (
auto Result = PackScope.finish())
1101 if (ArgIdx < NumArgs)
1116 if (ParamQs == ArgQs)
1151 if (!ParamFunction || !ArgFunction)
1152 return Param == Arg;
1156 if (IsFunctionConversion(Param, Arg, AdjustedParam))
1161 return Param == Arg;
1170 if (!Guide || !Guide->isImplicit())
1182 if (ParamRef->getPointeeType().getQualifiers())
1185 return TypeParm && TypeParm->
getIndex() >= FirstInnerIndex;
1221 bool PartialOrdering,
1222 bool DeducedFromArrayBound) {
1231 = dyn_cast<PackExpansionType>(Arg))
1232 Arg = ArgExpansion->getPattern();
1234 if (PartialOrdering) {
1316 TDF &= ~TDF_TopLevelParameterTypeList;
1337 unsigned Index = TemplateTypeParm->getIndex();
1338 bool RecanonicalizeArg =
false;
1342 if (isa<ArrayType>(Arg)) {
1347 RecanonicalizeArg =
true;
1355 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1368 "saw template type parameter with wrong depth");
1389 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1406 if (RecanonicalizeArg)
1414 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1420 Deduced[Index] = Result;
1432 if (isa<SubstTemplateTypeParmPackType>(Param))
1478 : ParamUnqualType == ArgUnqualType;
1485 #define NON_CANONICAL_TYPE(Class, Base) \ 1486 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class); 1487 #define TYPE(Class, Base) 1488 #include "clang/AST/TypeNodes.def" 1490 case Type::TemplateTypeParm:
1491 case Type::SubstTemplateTypeParmPack:
1492 llvm_unreachable(
"Type nodes handled above");
1497 case Type::VariableArray:
1499 case Type::FunctionNoProto:
1502 case Type::ObjCObject:
1503 case Type::ObjCInterface:
1504 case Type::ObjCObjectPointer:
1508 if (TDF & TDF_IgnoreQualifiers) {
1519 cast<ComplexType>(Param)->getElementType(),
1520 ComplexArg->getElementType(),
1521 Info, Deduced, TDF);
1529 cast<AtomicType>(Param)->getValueType(),
1530 AtomicArg->getValueType(),
1531 Info, Deduced, TDF);
1536 case Type::Pointer: {
1549 cast<PointerType>(Param)->getPointeeType(),
1551 Info, Deduced, SubTDF);
1555 case Type::LValueReference: {
1562 cast<LValueReferenceType>(Param)->getPointeeType(),
1567 case Type::RValueReference: {
1574 cast<RValueReferenceType>(Param)->getPointeeType(),
1580 case Type::IncompleteArray: {
1583 if (!IncompleteArrayArg)
1590 Info, Deduced, SubTDF);
1594 case Type::ConstantArray: {
1597 if (!ConstantArrayArg)
1603 return Sema::TDK_NonDeducedMismatch;
1609 Info, Deduced, SubTDF);
1613 case Type::DependentSizedArray: {
1627 Info, Deduced, SubTDF))
1639 "saw non-type template parameter with wrong depth");
1641 = dyn_cast<ConstantArrayType>(ArrayArg)) {
1642 llvm::APSInt Size(ConstantArrayArg->getSize());
1649 = dyn_cast<DependentSizedArrayType>(ArrayArg))
1650 if (DependentArrayArg->getSizeExpr())
1652 DependentArrayArg->getSizeExpr(),
1662 case Type::FunctionProto: {
1666 if (!FunctionProtoArg)
1670 cast<FunctionProtoType>(Param);
1677 return Sema::TDK_NonDeducedMismatch;
1690 FunctionProtoArg->
getNumParams(), Info, Deduced, SubTDF))
1704 "saw non-type template parameter with wrong depth");
1706 llvm::APSInt Noexcept(1);
1707 switch (FunctionProtoArg->
canThrow()) {
1717 true, Info, Deduced);
1722 S, TemplateParams, NTTP, ArgNoexceptExpr, Info, Deduced);
1735 case Type::InjectedClassName:
1738 Param = cast<InjectedClassNameType>(Param)
1739 ->getInjectedSpecializationType();
1740 assert(isa<TemplateSpecializationType>(Param) &&
1741 "injected class name is not a template specialization type");
1749 case Type::TemplateSpecialization: {
1751 cast<TemplateSpecializationType>(Param);
1764 S, TemplateParams, SpecParam, Arg, Info, Deduced);
1787 Deduced = DeducedOrig;
1792 llvm::SmallPtrSet<const RecordType *, 8> Visited;
1794 ToVisit.push_back(RecordT);
1795 bool Successful =
false;
1797 while (!ToVisit.empty()) {
1799 const RecordType *NextT = ToVisit.pop_back_val();
1802 if (!Visited.insert(NextT).second)
1807 if (NextT != RecordT) {
1811 QualType(NextT, 0), BaseInfo, Deduced);
1823 std::swap(SuccessfulDeduced, Deduced);
1825 Info.
Param = BaseInfo.Param;
1830 Deduced = DeducedOrig;
1835 for (
const auto &
Base : Next->
bases()) {
1836 assert(
Base.getType()->isRecordType() &&
1837 "Base class that isn't a record?");
1843 std::swap(SuccessfulDeduced, Deduced);
1859 case Type::MemberPointer: {
1879 TDF & TDF_IgnoreQualifiers))
1884 QualType(MemPtrArg->getClass(), 0),
1886 TDF & TDF_IgnoreQualifiers);
1894 case Type::BlockPointer: {
1910 case Type::ExtVector: {
1911 const ExtVectorType *VectorParam = cast<ExtVectorType>(Param);
1912 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1914 if (VectorParam->
getNumElements() != VectorArg->getNumElements())
1915 return Sema::TDK_NonDeducedMismatch;
1920 VectorArg->getElementType(),
1921 Info, Deduced, TDF);
1925 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1933 VectorArg->getElementType(),
1934 Info, Deduced, TDF);
1940 case Type::DependentVector: {
1941 const auto *VectorParam = cast<DependentVectorType>(Param);
1943 if (
const auto *VectorArg = dyn_cast<VectorType>(Arg)) {
1947 S, TemplateParams, VectorParam->getElementType(),
1948 VectorArg->getElementType(), Info, Deduced, TDF))
1958 ArgSize = VectorArg->getNumElements();
1967 if (
const auto *VectorArg = dyn_cast<DependentVectorType>(Arg)) {
1971 S, TemplateParams, VectorParam->getElementType(),
1972 VectorArg->getElementType(), Info, Deduced, TDF))
1977 Info, VectorParam->getSizeExpr());
1982 S, TemplateParams, NTTP, VectorArg->getSizeExpr(), Info, Deduced);
1991 case Type::DependentSizedExtVector: {
1993 = cast<DependentSizedExtVectorType>(Param);
1995 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
2000 VectorArg->getElementType(),
2001 Info, Deduced, TDF))
2011 ArgSize = VectorArg->getNumElements();
2021 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
2026 VectorArg->getElementType(),
2027 Info, Deduced, TDF))
2037 VectorArg->getSizeExpr(),
2047 case Type::DependentAddressSpace: {
2049 cast<DependentAddressSpaceType>(Param);
2052 dyn_cast<DependentAddressSpaceType>(Arg)) {
2067 S, TemplateParams, NTTP, AddressSpaceArg->getAddrSpaceExpr(), Info,
2091 true, Info, Deduced);
2097 case Type::TypeOfExpr:
2099 case Type::DependentName:
2100 case Type::UnresolvedUsing:
2101 case Type::Decltype:
2102 case Type::UnaryTransform:
2104 case Type::DeducedTemplateSpecialization:
2105 case Type::DependentTemplateSpecialization:
2106 case Type::PackExpansion:
2112 llvm_unreachable(
"Invalid Type Class!");
2130 llvm_unreachable(
"Null template argument in parameter list");
2152 llvm_unreachable(
"caller should handle pack expansions");
2223 llvm_unreachable(
"Argument packs should be expanded by the caller!");
2226 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2239 if (ArgIdx == Args.size())
2246 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
2249 return ArgIdx < Args.size();
2255 bool FoundPackExpansion =
false;
2256 for (
const auto &A : Args) {
2257 if (FoundPackExpansion)
2265 if (A.isPackExpansion())
2266 FoundPackExpansion =
true;
2278 bool NumberOfArgumentsMustMatch) {
2292 if (!Params[
ParamIdx].isPackExpansion()) {
2297 return NumberOfArgumentsMustMatch
2304 if (Args[ArgIdx].isPackExpansion())
2329 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
2335 PackScope.hasNextElement();
2343 PackScope.nextPackElement();
2348 if (
auto Result = PackScope.finish())
2363 ArgList.
asArray(), Info, Deduced,
2371 bool PackExpansionMatchesPack =
false) {
2382 llvm_unreachable(
"Comparing NULL template argument");
2405 llvm::FoldingSetNodeID XID, YID;
2418 XP != XPEnd; ++XP, ++YP)
2425 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2446 llvm_unreachable(
"Can't get a NULL template argument here");
2455 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2463 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2471 BuildExpressionFromIntegralTemplateArgument(Arg, Loc).getAs<
Expr>();
2480 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
2483 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
2500 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2513 unsigned ArgumentPackIndex) {
2541 "deduced nested pack");
2548 diag::err_template_arg_deduced_incomplete_pack)
2552 if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
2556 PackedArgsBuilder.push_back(Output.pop_back_val());
2561 if (PackedArgsBuilder.empty()) {
2566 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2570 if (Inst.isInvalid() ||
2571 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
2572 NTTP->getDeclName()).isNull())
2574 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2590 return ConvertArg(Arg, 0);
2596 template<
typename TemplateDeclT>
2598 Sema &S, TemplateDeclT *Template,
bool IsDeduced,
2602 unsigned NumAlreadyConverted = 0,
bool PartialOverloading =
false) {
2605 for (
unsigned I = 0, N = TemplateParams->
size(); I != N; ++I) {
2613 if (
auto Result = PackDeductionScope(S, TemplateParams, Deduced, Info, I)
2618 if (!Deduced[I].isNull()) {
2619 if (I < NumAlreadyConverted) {
2624 CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
2627 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2634 Builder.push_back(Deduced[I]);
2642 IsDeduced, Builder)) {
2653 bool HasDefaultArg =
false;
2656 assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
2657 isa<VarTemplatePartialSpecializationDecl>(Template));
2668 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2670 if (PartialOverloading)
break;
2681 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2694 if (
auto *DC = dyn_cast<DeclContext>(D))
2700 static constexpr
bool value =
false;
2704 static constexpr
bool value =
true;
2708 static constexpr
bool value =
true;
2712 template <
typename T>
2713 static typename std::enable_if<IsPartialSpecialization<T>::value,
2716 Sema &S, T *Partial,
bool IsPartialOrdering,
2732 S, Partial, IsPartialOrdering, Deduced, Info, Builder))
2739 Info.
reset(DeducedArgumentList);
2747 auto *Template = Partial->getSpecializedTemplate();
2749 Partial->getTemplateArgsAsWritten();
2759 if (
ParamIdx >= Partial->getTemplateParameters()->size())
2760 ParamIdx = Partial->getTemplateParameters()->size() - 1;
2763 Partial->getTemplateParameters()->getParam(
ParamIdx));
2771 false, ConvertedInstArgs))
2775 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2811 S, Template, PartialOrdering, Deduced, Info, Builder))
2816 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2861 TemplateArgs, Info, Deduced))
2867 if (Inst.isInvalid())
2868 return TDK_InstantiationDepth;
2874 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2902 TemplateArgs, Info, Deduced))
2908 if (Inst.isInvalid())
2909 return TDK_InstantiationDepth;
2915 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2922 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
2974 if (ExplicitTemplateArgs.
size() == 0) {
2978 ParamTypes.push_back(
P->getType());
2981 *FunctionType = Function->
getType();
3002 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3003 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info);
3004 if (Inst.isInvalid())
3005 return TDK_InstantiationDepth;
3007 if (CheckTemplateArgumentList(FunctionTemplate,
SourceLocation(),
3008 ExplicitTemplateArgs,
true, Builder,
false) ||
3010 unsigned Index = Builder.size();
3011 if (Index >= TemplateParams->
size())
3012 return TDK_SubstitutionFailure;
3014 return TDK_InvalidExplicitArguments;
3033 unsigned PartiallySubstitutedPackIndex = -1u;
3034 if (!Builder.empty()) {
3037 auto *Param = TemplateParams->
getParam(Builder.size() - 1);
3041 if (!Expansions || Arg.
pack_size() < *Expansions) {
3042 PartiallySubstitutedPackIndex = Builder.size() - 1;
3043 CurrentInstantiationScope->SetPartiallySubstitutedPack(
3051 assert(Proto &&
"Function template does not have a prototype?");
3066 ParamTypes,
nullptr, ExtParamInfos))
3067 return TDK_SubstitutionFailure;
3079 unsigned ThisTypeQuals = 0;
3081 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
3083 ThisTypeQuals = Method->getTypeQualifiers();
3094 return TDK_SubstitutionFailure;
3103 ParamTypes,
nullptr, ExtParamInfos))
3104 return TDK_SubstitutionFailure;
3114 if (getLangOpts().CPlusPlus17 &&
3116 Function->
getLocation(), EPI.ExceptionSpec, ExceptionStorage,
3118 return TDK_SubstitutionFailure;
3120 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
3125 return TDK_SubstitutionFailure;
3138 Deduced.reserve(TemplateParams->
size());
3139 for (
unsigned I = 0, N = ExplicitArgumentList->
size(); I != N; ++I) {
3141 if (I == PartiallySubstitutedPackIndex)
3144 Deduced.push_back(Arg);
3212 if (AQuals == DeducedAQuals) {
3230 bool ObjCLifetimeConversion =
false;
3234 ObjCLifetimeConversion) ||
3280 if (PD->isParameterPack()) {
3281 unsigned NumExpansions =
3283 if (Idx + NumExpansions > ParamIdx)
3284 return ParamIdx - Idx;
3285 Idx += NumExpansions;
3287 if (Idx == ParamIdx)
3293 llvm_unreachable(
"parameter index would not be produced from template");
3305 unsigned NumExplicitlySpecified,
FunctionDecl *&Specialization,
3308 bool PartialOverloading, llvm::function_ref<
bool()> CheckNonDependent) {
3318 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3319 CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3320 if (Inst.isInvalid())
3321 return TDK_InstantiationDepth;
3330 *
this, FunctionTemplate,
true, Deduced, Info, Builder,
3331 CurrentInstantiationScope, NumExplicitlySpecified,
3332 PartialOverloading))
3344 if (CheckNonDependent())
3345 return TDK_NonDependentConversionFailure;
3350 Info.
reset(DeducedArgumentList);
3358 Specialization = cast_or_null<FunctionDecl>(
3361 return TDK_SubstitutionFailure;
3377 return TDK_SubstitutionFailure;
3380 if (OriginalCallArgs) {
3385 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
3386 for (
unsigned I = 0, N = OriginalCallArgs->size(); I != N; ++I) {
3407 if (CacheEntry.
isNull()) {
3416 DeducedA = CacheEntry;
3430 SuppressedDiagnosticsMap::iterator
3432 if (Pos == SuppressedDiagnostics.end())
3450 if (Method->isInstance()) {
3471 bool ParamWasReference) {
3479 if (ParamWasReference)
3526 Specialization, Info))
3534 if (ArgType.isNull())
continue;
3538 ArgType->isFunctionType())
3554 Deduced(TemplateParams->
size());
3558 ArgType, Info, Deduced, TDF);
3559 if (Result)
continue;
3595 ParamRefType !=
nullptr);
3656 (isa<PointerType>(ParamType) &&
3673 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF);
3697 ElTy = ArrTy->getElementType();
3708 S, TemplateParams, 0, ElTy, E, Info, Deduced, OriginalCallArgs,
true,
3716 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
3727 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
3728 true, Info, Deduced))
3743 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF) {
3745 QualType OrigParamType = ParamType;
3750 S, TemplateParams, FirstInnerIndex, ParamType, ArgType, Arg, TDF))
3756 Deduced, OriginalCallArgs, ArgIdx, TDF);
3763 OriginalCallArgs.push_back(
3766 ArgType, Info, Deduced, TDF);
3798 bool PartialOverloading,
3813 return TDK_TooFewArguments;
3814 else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
3820 return TDK_TooManyArguments;
3830 unsigned NumExplicitlySpecified = 0;
3831 if (ExplicitTemplateArgs) {
3833 SubstituteExplicitTemplateArguments(FunctionTemplate,
3834 *ExplicitTemplateArgs,
3842 NumExplicitlySpecified = Deduced.size();
3845 for (
unsigned I = 0; I != NumParams; ++I)
3852 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx) {
3862 *
this, TemplateParams, FirstInnerIndex, ParamType, Args[ArgIdx], Info, Deduced,
3863 OriginalCallArgs,
false, ArgIdx, 0);
3867 Deduced.resize(TemplateParams->
size());
3869 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
3875 if (!ParamExpansion) {
3877 if (ArgIdx >= Args.size())
3880 ParamTypesForArgChecking.push_back(ParamType);
3881 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++))
3888 PackDeductionScope PackScope(*
this, TemplateParams, Deduced, Info,
3907 if (
ParamIdx + 1 == NumParamTypes || PackScope.hasFixedArity()) {
3908 for (; ArgIdx < Args.size() && PackScope.hasNextElement();
3909 PackScope.nextPackElement(), ++ArgIdx) {
3910 ParamTypesForArgChecking.push_back(ParamPattern);
3911 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx))
3919 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
3920 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
3922 ParamTypesForArgChecking.push_back(ParamPattern);
3925 PackScope.nextPackElement();
3932 if (
auto Result = PackScope.finish())
3941 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
3942 &OriginalCallArgs, PartialOverloading, [&, CallingCtx]() {
3944 return CheckNonDependent(ParamTypesForArgChecking);
3950 bool AdjustExceptionSpec) {
3951 if (ArgFunctionType.
isNull())
3952 return ArgFunctionType;
3960 bool Rebuild =
false;
3963 if (EPI.ExtInfo.getCC() != CC) {
3964 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
3969 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
3970 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
3975 ArgFunctionTypeP->hasExceptionSpec())) {
3981 return ArgFunctionType;
3984 ArgFunctionTypeP->getParamTypes(), EPI);
4019 bool IsAddressOfFunction) {
4031 unsigned NumExplicitlySpecified = 0;
4033 if (ExplicitTemplateArgs) {
4035 = SubstituteExplicitTemplateArguments(FunctionTemplate,
4036 *ExplicitTemplateArgs,
4037 Deduced, ParamTypes,
4038 &FunctionType, Info))
4041 NumExplicitlySpecified = Deduced.size();
4047 if (!IsAddressOfFunction)
4048 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, FunctionType,
4056 Deduced.resize(TemplateParams->
size());
4062 bool HasDeducedReturnType =
false;
4063 if (getLangOpts().CPlusPlus14 && IsAddressOfFunction &&
4065 FunctionType = SubstAutoType(FunctionType, Context.
DependentTy);
4066 HasDeducedReturnType =
true;
4069 if (!ArgFunctionType.
isNull()) {
4075 FunctionType, ArgFunctionType,
4076 Info, Deduced, TDF))
4082 NumExplicitlySpecified,
4083 Specialization, Info))
4088 if (HasDeducedReturnType &&
4090 DeduceReturnType(Specialization, Info.
getLocation(),
false))
4091 return TDK_MiscellaneousDeductionFailure;
4095 auto *SpecializationFPT =
4097 if (getLangOpts().CPlusPlus17 &&
4099 !ResolveExceptionSpec(Info.
getLocation(), SpecializationFPT))
4100 return TDK_MiscellaneousDeductionFailure;
4107 if (!IsAddressOfFunction)
4108 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, SpecializationType,
4114 if (!ArgFunctionType.
isNull()) {
4115 if (IsAddressOfFunction &&
4116 !isSameOrCompatibleFunctionType(
4119 return TDK_MiscellaneousDeductionFailure;
4121 if (!IsAddressOfFunction &&
4122 !Context.
hasSameType(SpecializationType, ArgFunctionType))
4123 return TDK_MiscellaneousDeductionFailure;
4172 assert(!A->
isReferenceType() &&
"Reference types were handled above");
4209 Deduced.resize(TemplateParams->
size());
4233 P, A, Info, Deduced, TDF))
4242 ConversionSpecialized, Info);
4243 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
4275 bool IsAddressOfFunction) {
4278 IsAddressOfFunction);
4285 class SubstituteDeducedTypeTransform :
4291 SubstituteDeducedTypeTransform(
Sema &SemaRef,
QualType Replacement,
4292 bool UseTypeSugar =
true)
4294 Replacement(Replacement), UseTypeSugar(UseTypeSugar) {}
4297 assert(isa<TemplateTypeParmType>(Replacement) &&
4298 "unexpected unsugared replacement kind");
4316 return TransformDesugared(TLB, TL);
4325 QualType TransformDeducedTemplateSpecializationType(
4328 return TransformDesugared(TLB, TL);
4348 return TransformType(TLB, TL);
4357 return DeduceAutoType(Type->
getTypeLoc(), Init, Result,
4358 DependentDeductionDepth);
4371 auto D = S.
Diag(Info.
getLocation(), diag::err_auto_inconsistent_deduction);
4373 for (
auto R : Ranges)
4404 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
4406 return DAR_FailedAlreadyDiagnosed;
4407 Init = NonPlaceholder.
get();
4410 if (!DependentDeductionDepth &&
4412 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4413 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4414 return DAR_Succeeded;
4418 unsigned Depth = DependentDeductionDepth.getValueOr(0);
4424 if (AT->isDecltypeAuto()) {
4425 if (isa<InitListExpr>(Init)) {
4427 return DAR_FailedAlreadyDiagnosed;
4432 return DAR_FailedAlreadyDiagnosed;
4435 Result = SubstituteDeducedTypeTransform(*
this, Deduced).Apply(Type);
4437 return DAR_FailedAlreadyDiagnosed;
4438 return DAR_Succeeded;
4439 }
else if (!getLangOpts().CPlusPlus) {
4440 if (isa<InitListExpr>(Init)) {
4442 return DAR_FailedAlreadyDiagnosed;
4453 Context,
nullptr,
SourceLocation(), Loc, Depth, 0,
nullptr,
false,
false);
4457 Loc, Loc, TemplParamPtr, Loc,
nullptr);
4460 SubstituteDeducedTypeTransform(*
this, TemplArg,
false)
4462 assert(!FuncParam.
isNull() &&
4463 "substituting template parameter for 'auto' failed");
4476 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4477 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4478 return DAR_Succeeded;
4481 return DAR_FailedAlreadyDiagnosed;
4496 for (
unsigned i = 0, e = InitList->
getNumInits(); i < e; ++i) {
4500 *
this, TemplateParamsSt.get(), 0, TemplArg, Init,
4501 Info, Deduced, OriginalCallArgs,
true,
4503 return DeductionFailed(TDK, {DeducedFromInitRange,
4504 Init->getSourceRange()});
4508 DeducedFromInitRange = Init->getSourceRange();
4512 Diag(Loc, diag::err_auto_bitfield);
4513 return DAR_FailedAlreadyDiagnosed;
4517 *
this, TemplateParamsSt.get(), 0, FuncParam, Init, Info, Deduced,
4518 OriginalCallArgs,
false, 0, 0))
4519 return DeductionFailed(TDK, {});
4524 return DeductionFailed(TDK_Incomplete, {});
4529 DeducedType = BuildStdInitializerList(DeducedType, Loc);
4530 if (DeducedType.isNull())
4531 return DAR_FailedAlreadyDiagnosed;
4534 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(Type);
4536 return DAR_FailedAlreadyDiagnosed;
4540 QualType DeducedA = InitList ? Deduced[0].getAsType() : Result;
4542 assert((
bool)InitList == OriginalArg.DecomposedParam &&
4543 "decomposed non-init-list in auto deduction?");
4547 return DeductionFailed(TDK, {});
4551 return DAR_Succeeded;
4558 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4559 .TransformType(TypeWithAuto);
4566 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4567 .TransformType(TypeWithAuto);
4572 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
4574 .TransformType(TypeWithAuto);
4578 if (isa<InitListExpr>(Init))
4581 ? diag::err_init_capture_deduction_failure_from_init_list
4582 : diag::err_auto_var_deduction_failure_from_init_list)
4586 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
4587 : diag::err_auto_var_deduction_failure)
4599 CXXRecordDecl *Lambda = cast<CXXMethodDecl>(FD)->getParent();
4604 CallOp = InstantiateFunctionDeclaration(
4612 InstantiateFunctionDefinition(Loc, CallOp);
4618 "failed to deduce lambda return type");
4621 QualType RetType = getLambdaConversionFunctionResultType(
4634 InstantiateFunctionDefinition(Loc, FD);
4638 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
4642 return StillUndeduced;
4664 ArgTypes.push_back(ArgTy);
4674 unsigned NumCallArguments1) {
4680 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
4683 Deduced.resize(TemplateParams->
size());
4714 unsigned NumComparedArguments = NumCallArguments1;
4716 if (!Method2 && Method1 && !Method1->
isStatic()) {
4719 ++NumComparedArguments;
4720 }
else if (!Method1 && Method2 && !Method2->
isStatic()) {
4727 Args2.insert(Args2.end(), Proto2->param_type_begin(),
4728 Proto2->param_type_end());
4733 if (Args1.size() > NumComparedArguments)
4734 Args1.resize(NumComparedArguments);
4735 if (Args2.size() > NumComparedArguments)
4736 Args2.resize(NumComparedArguments);
4738 Args1.data(), Args1.size(), Info, Deduced,
4749 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
4772 unsigned ArgIdx = 0, NumArgs = Deduced.size();
4773 for (; ArgIdx != NumArgs; ++ArgIdx)
4774 if (Deduced[ArgIdx].isNull())
4781 if (ArgIdx == NumArgs) {
4788 llvm::SmallBitVector UsedParameters(TemplateParams->
size());
4791 for (
unsigned I = 0, N = Args2.size(); I != N; ++I)
4799 TemplateParams->
getDepth(), UsedParameters);
4809 for (; ArgIdx != NumArgs; ++ArgIdx)
4812 if (Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
4831 while (--NumParams > 0) {
4862 unsigned NumCallArguments1,
4863 unsigned NumCallArguments2) {
4869 if (Better1 != Better2)
4870 return Better1 ? FT1 : FT2;
4872 if (!Better1 && !Better2)
4880 if (Variadic1 != Variadic2)
4881 return Variadic1? FT2 : FT1;
4927 bool Complain,
QualType TargetType) {
4928 if (SpecBegin == SpecEnd) {
4930 Diag(Loc, NoneDiag);
4936 if (SpecBegin + 1 == SpecEnd)
4943 = cast<FunctionDecl>(*Best)->getPrimaryTemplate();
4944 assert(BestTemplate &&
"Not a function template specialization?");
4947 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4948 assert(Challenger &&
"Not a function template specialization?");
4949 if (
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4953 BestTemplate = Challenger;
4959 bool Ambiguous =
false;
4962 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4964 !
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4979 Diag(Loc, AmbigDiag);
4984 const auto *FD = cast<FunctionDecl>(*I);
4985 PD << FD << getTemplateArgumentBindingsText(
4986 FD->getPrimaryTemplate()->getTemplateParameters(),
4987 *FD->getTemplateSpecializationArgs());
4988 if (!TargetType.
isNull())
4989 HandleFunctionTypeMismatch(PD, FD->getType(), TargetType);
4990 Diag((*I)->getLocation(), PD);
5004 template<
typename TemplateLikeDecl>
5006 TemplateLikeDecl *P2,
5035 Deduced.resize(P2->getTemplateParameters()->size());
5049 TST1->template_arguments()),
5078 if (Better1 == Better2)
5081 return Better1 ? PS1 : PS2;
5105 "the partial specializations being compared should specialize" 5106 " the same template.");
5118 if (Better1 == Better2)
5121 return Better1 ? PS1 : PS2;
5136 CanonTemplate, PrimaryArgs);
5180 for (
unsigned I = 0, N = P->
size(); I != N; ++I) {
5188 PArgList.addArgument(getTrivialTemplateArgumentLoc(
5196 if (CheckTemplateArgumentList(AArg, Loc, PArgList,
false, PArgs) ||
5218 llvm::SmallBitVector &
Used) {
5221 E = Expansion->getPattern();
5227 E = ICE->getSubExpr();
5229 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
5230 E = Subst->getReplacement();
5262 llvm::SmallBitVector &
Used) {
5269 OnlyDeduced, Depth, Used);
5279 llvm::SmallBitVector &
Used) {
5282 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
5283 if (TTP->getDepth() ==
Depth)
5284 Used[TTP->getIndex()] =
true;
5303 llvm::SmallBitVector &
Used) {
5315 cast<PointerType>(T)->getPointeeType(),
5321 case Type::BlockPointer:
5323 cast<BlockPointerType>(T)->getPointeeType(),
5329 case Type::LValueReference:
5330 case Type::RValueReference:
5332 cast<ReferenceType>(T)->getPointeeType(),
5338 case Type::MemberPointer: {
5343 OnlyDeduced, Depth, Used);
5347 case Type::DependentSizedArray:
5349 cast<DependentSizedArrayType>(T)->getSizeExpr(),
5350 OnlyDeduced, Depth, Used);
5354 case Type::ConstantArray:
5355 case Type::IncompleteArray:
5357 cast<ArrayType>(T)->getElementType(),
5358 OnlyDeduced, Depth, Used);
5362 case Type::ExtVector:
5364 cast<VectorType>(T)->getElementType(),
5365 OnlyDeduced, Depth, Used);
5368 case Type::DependentVector: {
5369 const auto *VecType = cast<DependentVectorType>(T);
5376 case Type::DependentSizedExtVector: {
5378 = cast<DependentSizedExtVectorType>(T);
5386 case Type::DependentAddressSpace: {
5388 cast<DependentAddressSpaceType>(T);
5397 case Type::FunctionProto: {
5401 for (
unsigned I = 0, N = Proto->
getNumParams(); I != N; ++I) {
5406 if (!OnlyDeduced || I + 1 == N ||
5424 case Type::TemplateTypeParm: {
5431 case Type::SubstTemplateTypeParmPack: {
5433 = cast<SubstTemplateTypeParmPackType>(T);
5436 OnlyDeduced, Depth, Used);
5442 case Type::InjectedClassName:
5443 T = cast<InjectedClassNameType>(T)->getInjectedSpecializationType();
5446 case Type::TemplateSpecialization: {
5448 = cast<TemplateSpecializationType>(T);
5460 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5469 cast<ComplexType>(T)->getElementType(),
5470 OnlyDeduced, Depth, Used);
5476 cast<AtomicType>(T)->getValueType(),
5477 OnlyDeduced, Depth, Used);
5480 case Type::DependentName:
5483 cast<DependentNameType>(T)->getQualifier(),
5484 OnlyDeduced, Depth, Used);
5487 case Type::DependentTemplateSpecialization: {
5501 = cast<DependentTemplateSpecializationType>(T);
5506 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5516 OnlyDeduced, Depth, Used);
5519 case Type::TypeOfExpr:
5522 cast<TypeOfExprType>(T)->getUnderlyingExpr(),
5523 OnlyDeduced, Depth, Used);
5526 case Type::Decltype:
5529 cast<DecltypeType>(T)->getUnderlyingExpr(),
5530 OnlyDeduced, Depth, Used);
5533 case Type::UnaryTransform:
5537 OnlyDeduced, Depth, Used);
5540 case Type::PackExpansion:
5542 cast<PackExpansionType>(T)->getPattern(),
5543 OnlyDeduced, Depth, Used);
5547 case Type::DeducedTemplateSpecialization:
5549 cast<DeducedType>(T)->getDeducedType(),
5550 OnlyDeduced, Depth, Used);
5555 case Type::VariableArray:
5556 case Type::FunctionNoProto:
5559 case Type::ObjCInterface:
5560 case Type::ObjCObject:
5561 case Type::ObjCObjectPointer:
5562 case Type::UnresolvedUsing:
5564 #define TYPE(Class, Base) 5565 #define ABSTRACT_TYPE(Class, Base) 5566 #define DEPENDENT_TYPE(Class, Base) 5567 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 5568 #include "clang/AST/TypeNodes.def" 5580 llvm::SmallBitVector &
Used) {
5581 switch (TemplateArg.
getKind()) {
5627 bool OnlyDeduced,
unsigned Depth,
5628 llvm::SmallBitVector &
Used) {
5637 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
5646 llvm::SmallBitVector &Deduced) {
5650 Deduced.resize(TemplateParams->
size());
5653 for (
unsigned I = 0, N = Function->
getNumParams(); I != N; ++I)
5655 true, TemplateParams->
getDepth(), Deduced);
5666 llvm::SmallBitVector Deduced(TemplateParams->
size());
5670 return Deduced.any();
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Defines the clang::ASTContext interface.
The null pointer literal (C++11 [lex.nullptr])
Represents a function declaration or definition.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y)
Verify that the given, deduced template arguments are compatible.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
const TypeClass * getTypePtr() const
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
TemplateDeductionResult
Describes the result of template argument deduction.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
bool isMemberPointerType() const
bool isLambdaConversionOperator(CXXConversionDecl *C)
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Template argument deduction was successful.
UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, TemplateSpecCandidateSet &FailedCandidates, SourceLocation Loc, const PartialDiagnostic &NoneDiag, const PartialDiagnostic &AmbigDiag, const PartialDiagnostic &CandidateDiag, bool Complain=true, QualType TargetType=QualType())
Retrieve the most specialized of the given function template specializations.
const Expr * getInit(unsigned Init) const
static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(Sema &S, TemplateDeclT *Template, bool IsDeduced, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info, SmallVectorImpl< TemplateArgument > &Builder, LocalInstantiationScope *CurrentInstantiationScope=nullptr, unsigned NumAlreadyConverted=0, bool PartialOverloading=false)
FunctionType - C99 6.7.5.3 - Function Declarators.
static Sema::TemplateDeductionResult CheckOriginalCallArgDeduction(Sema &S, TemplateDeductionInfo &Info, Sema::OriginalCallArg OriginalArg, QualType DeducedA)
Check whether the deduced argument type for a call to a function template matches the actual argument...
Provides information about an attempted template argument deduction, whose success or failure was des...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
C Language Family Type Representation.
void setObjCLifetime(ObjCLifetime type)
The template argument is an expression, and we've not resolved it to one of the other forms yet...
bool isRecordType() const
unsigned size() const
Retrieve the number of template arguments in this template argument list.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
const Type * getTypeForDecl() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
static bool IsPossiblyOpaquelyQualifiedType(QualType T)
Determines whether the given type is an opaque type that might be more qualified when instantiated...
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Template argument deduction produced inconsistent deduced values for the given template parameter...
NamedDecl * getParam(unsigned Idx)
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
A container of type source information.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Partial ordering of function templates for a call to a conversion function.
bool CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, SmallVectorImpl< TemplateArgument > &Converted, bool UpdateArgsWithConversions=true)
Check that the given template arguments can be be provided to the given template, converting the argu...
TemplateDeductionResult FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, SmallVectorImpl< OriginalCallArg > const *OriginalCallArgs=nullptr, bool PartialOverloading=false, llvm::function_ref< bool()> CheckNonDependent=[]{ return false;})
Finish template argument deduction for a function template, checking the deduced template arguments f...
QualType getElementType() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static void MarkUsedTemplateParameters(ASTContext &Ctx, const TemplateArgument &TemplateArg, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark the template parameters that are used by this template argument.
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
This file provides some common utility functions for processing Lambda related AST Constructs...
unsigned getDepth() const
Get the nesting depth of the template parameter.
RAII object that enters a new expression evaluation context.
Represents a variable declaration or definition.
void removeObjCLifetime()
QualType getReturnType() const
unsigned getNumParams() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
TemplateDeductionFlags
Various flags that control template argument deduction.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
SourceLocation getLAngleLoc() const
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
void clearSFINAEDiagnostic()
Discard any SFINAE diagnostics.
TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, Decl *Param, SmallVectorImpl< TemplateArgument > &Converted, bool &HasDefaultArg)
If the given template parameter has a default template argument, substitute into that default templat...
bool isParameterPack() const
Whether this declaration is a parameter pack.
Whether we are performing template argument deduction for parameters and arguments in a top-level tem...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
TemplateParameter Param
The template parameter to which a template argument deduction failure refers.
QualType getIntegralType() const
Retrieve the type of the integral value.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
The collection of all-type qualifiers we support.
Base wrapper for a particular "section" of type source info.
QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, bool AdjustExceptionSpec=false)
Adjust the type ArgFunctionType to match the calling convention, noreturn, and optionally the excepti...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a class template specialization, which refers to a class template with a given set of temp...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
static TemplateArgument getEmptyPack()
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
QualType getPointeeType() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a dependent template name that cannot be resolved prior to template instantiation.
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
static bool isVariadicFunctionTemplate(FunctionTemplateDecl *FunTmpl)
Determine whether this a function template whose parameter-type-list ends with a function parameter p...
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
bool isReferenceType() const
The iterator over UnresolvedSets.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Represents the result of substituting a set of types for a template type parameter pack...
static NonTypeTemplateParmDecl * getDeducedParameterFromExpr(TemplateDeductionInfo &Info, Expr *E)
If the given expression is of a form that permits the deduction of a non-type template parameter...
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
unsigned getTypeQualifiers() const
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(TemplateParameterList *P, TemplateDecl *AArg, SourceLocation Loc)
Within template argument deduction from overload resolution per C++ [over.over] allow matching functi...
QualType getParamTypeForDecl() const
unsigned getTypeQuals() const
ArrayRef< ParmVarDecl * > parameters() const
Within template argument deduction from a function call, we are matching with a parameter type for wh...
Describes an C or C++ initializer list.
void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, SourceLocation Loc)
Adjust the calling convention of a method to be the ABI default if it wasn't specified explicitly...
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
void setNameLoc(SourceLocation Loc)
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
bool HasFormOfMemberPointer
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
A convenient class for passing around template argument information.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
bool hasAddressSpace() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, sema::TemplateDeductionInfo &Info)
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
unsigned toTargetAddressSpace(LangAS AS)
bool IsFunctionConversion(QualType FromType, QualType ToType, QualType &ResultTy)
Determine whether the conversion from FromType to ToType is a valid conversion that strips "noexcept"...
static TemplateTypeParmDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack)
Substitution of the deduced template argument values resulted in an error.
SourceLocation RAngleLoc
The source location of the right angle bracket ('>').
LangAS getAddressSpace() const
const TemplateArgument & getArg(unsigned Idx) const
const Type * getClass() const
void MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, llvm::SmallBitVector &Deduced)
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
Scope - A scope is a transient data structure that is used while parsing the program.
static TemplateArgument CreatePackCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument pack by copying the given set of template arguments.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
param_type_iterator param_type_begin() const
unsigned getIndex() const
Get the index of the template parameter within its parameter list.
const DependentSizedArrayType * getAsDependentSizedArrayType(QualType T) const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
SmallVector< DeducedTemplateArgument, 4 > New
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
const LangOptions & getLangOpts() const
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
QualType OriginalParamType
SourceLocation getTypeSpecStartLoc() const
FunctionDecl * resolveAddressOfOnlyViableOverloadCandidate(Expr *E, DeclAccessPair &FoundResult)
Given an expression that refers to an overloaded function, try to resolve that function to a single f...
Expr * getSizeExpr() const
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
QualType getElementType() const
RAII object used to change the argument pack substitution index within a Sema object.
Represents an extended vector type where either the type or size is dependent.
This object can be modified without requiring retains or releases.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
A helper class for building up ExtParameterInfos.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
static bool diagnoseAutoDeductionFailure(Sema &S, Sema::TemplateDeductionResult TDK, TemplateDeductionInfo &Info, ArrayRef< SourceRange > Ranges)
Attempt to produce an informative diagostic explaining why auto deduction failed. ...
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Expr * getAddrSpaceExpr() const
Provides definitions for the various language-specific address spaces.
static Sema::TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, const TemplateArgument &Param, TemplateArgument Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
Sema - This implements semantic analysis and AST building for C.
static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc, FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1)
Determine whether the function template FT1 is at least as specialized as FT2.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &Converted, CheckTemplateArgumentKind CTAK=CTAK_Specified)
Check that the given template argument corresponds to the given template parameter.
Represents a prototype with parameter type info, e.g.
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
void reset(TemplateArgumentList *NewDeduced)
Provide a new template argument list that contains the results of template argument deduction...
bool isStdInitializerList(QualType Ty, QualType *Element)
Tests whether Ty is an instance of std::initializer_list and, if it is and Element is not NULL...
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
static bool hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate, QualType T)
Template argument deduction did not deduce a value for every template parameter.
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
static Sema::TemplateDeductionResult DeduceFromInitializerList(Sema &S, TemplateParameterList *TemplateParams, QualType AdjustedParamType, InitListExpr *ILE, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, unsigned ArgIdx, unsigned TDF)
Attempt template argument deduction from an initializer list deemed to be an argument in a function c...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
static bool isSimpleTemplateIdType(QualType T)
Determine whether the given type T is a simple-template-id type.
void setExplicitArgs(TemplateArgumentList *NewDeduced)
Provide an initial template argument list that contains the explicitly-specified arguments.
Represents an array type in C++ whose size is a value-dependent expression.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static Sema::TemplateDeductionResult DeduceNullPtrTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, QualType NullPtrType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter from the given null pointer template argume...
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
unsigned getNumArgs() const
Retrieve the number of template arguments.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Expr - This represents one expression.
Defines the clang::LangOptions interface.
QualType getPointeeType() const
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
DeducedPack(unsigned Index)
static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, const DeducedTemplateArgument &NewDeduced, QualType ValueType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter as the given deduced template argument...
Declaration of a template type parameter.
unsigned getIndex() const
static DeclContext * getAsDeclContextOrEnclosing(Decl *D)
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(Sema &S, TemplateParameterList *TemplateParams, QualType Param, QualType Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned TDF, bool PartialOrdering=false, bool DeducedFromArrayBound=false)
Deduce the template arguments by comparing the parameter type and the argument type (C++ [temp...
static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType ParamType, Expr *Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, bool DecomposedParam, unsigned ArgIdx, unsigned TDF)
Perform template argument deduction per [temp.deduct.call] for a single parameter / argument pair...
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
const T * castAs() const
Member-template castAs<specific type>.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
static bool ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param, DeducedTemplateArgument Arg, NamedDecl *Template, TemplateDeductionInfo &Info, bool IsDeduced, SmallVectorImpl< TemplateArgument > &Output)
Convert the given deduced template argument and add it to the set of fully-converted template argumen...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
unsigned getNumInits() const
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
void completeExprArrayBound(Expr *E)
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
ObjCLifetime getObjCLifetime() const
DeclContext * getDeclContext()
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Represents a C++ template name within the type system.
decls_iterator decls_begin() const
Defines the clang::TypeLoc interface and its subclasses.
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7)...
ArrayRef< Expr * > inits()
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
FunctionDecl * ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, bool Complain=false, DeclAccessPair *Found=nullptr)
Given an expression that refers to an overloaded function, try to resolve that overloaded function ex...
bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg)
Compare types for equality with respect to possibly compatible function types (noreturn adjustment...
TemplateDeductionResult SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate, TemplateArgumentListInfo &ExplicitTemplateArgs, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< QualType > &ParamTypes, QualType *FunctionType, sema::TemplateDeductionInfo &Info)
Substitute the explicitly-provided template arguments into the given function template according to C...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Data structure that captures multiple levels of template argument lists for use in template instantia...
SourceLocation getEnd() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, bool Diagnose=true)
An lvalue reference type, per C++11 [dcl.ref].
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
Represents a C++ deduction guide declaration.
After substituting deduced template arguments, a dependent parameter type did not match the correspon...
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void removeCVRQualifiers(unsigned mask)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so...
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Captures a template argument whose value has been deduced via c++ template argument deduction...
static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, QualType ArgType)
Determine whether the parameter has qualifiers that the argument lacks.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent) const
C++11 deduced auto type.
bool hasTrailingReturn() const
RecordDecl * getDecl() const
static unsigned getPackIndexForParam(Sema &S, FunctionTemplateDecl *FunctionTemplate, const MultiLevelTemplateArgumentList &Args, unsigned ParamIdx)
Find the pack index for a particular parameter index in an instantiation of a function template with ...
SmallVector< DeducedPack *, 8 > PendingDeducedPacks
Information on packs that we're currently expanding.
There is no lifetime qualification on this type.
Assigning into this object requires the old value to be released and the new value to be retained...
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
A stack object to be created when performing template instantiation.
Stores a list of template parameters and the associated requires-clause (if any) for a TemplateDecl a...
ExtProtoInfo getExtProtoInfo() const
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
The template argument was deduced from an array bound via template argument deduction.
SourceLocation getNameLoc() const
Gets the location of the name.
const ExtParameterInfo * ExtParameterInfos
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static TemplateParameter makeTemplateParameter(Decl *D)
Helper function to build a TemplateParameter when we don't know its type statically.
QualType getReturnType() const
bool hasSameTemplateName(TemplateName X, TemplateName Y)
Determine whether the given template names refer to the same template.
LangAS getAddressSpace() const
Return the address space of this type.
Template argument deduction failed due to inconsistent cv-qualifiers on a template parameter type tha...
TemplateArgument getArgumentPack() const
SourceLocation getLocStart() const LLVM_READONLY
static bool isSameTemplate(TemplateDecl *T1, TemplateDecl *T2)
Determine if the two templates are equivalent.
QualType getElementType() const
static QualType getUnderlyingType(const SubRegion *R)
Template argument deduction did not deduce a value for every expansion of an expanded template parame...
Within template argument deduction from a function call, we are matching in a case where we ignore cv...
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const ParmVarDecl * getParamDecl(unsigned i) const
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init)
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Expr * getNoexceptExpr() const
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
Qualifiers withoutObjCLifetime() const
TypeSourceInfo * SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
bool isMemberFunctionPointerType() const
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
static unsigned getFirstInnerIndex(FunctionTemplateDecl *FTD)
Get the index of the first template parameter that was originally from the innermost template-paramet...
Within template argument deduction from a function call, we are matching in a case where we can perfo...
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
static bool isSameDeclaration(Decl *X, Decl *Y)
Determine whether two declaration pointers refer to the same declaration.
AutoTypeKeyword getKeyword() const
TypeClass getTypeClass() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
SourceLocation getRAngleLoc() const
bool isTargetAddressSpace(LangAS AS)
unsigned getDeducedDepth() const
The depth of template parameters for which deduction is being performed.
diag_iterator diag_end() const
Returns an iterator at the end of the sequence of suppressed diagnostics.
An rvalue ref-qualifier was provided (&&).
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
static bool hasPackExpansionBeforeEnd(ArrayRef< TemplateArgument > Args)
Determine whether the given set of template arguments has a pack expansion that is not the last templ...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
The injected class name of a C++ class template or class template partial specialization.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
QualType getPointeeType() const
Represents a pack expansion of types.
FunctionTemplateDecl * getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, unsigned NumCallArguments2)
Returns the more specialized function template according to the rules of function template partial or...
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
static QualType GetTypeOfFunction(Sema &S, const OverloadExpr::FindResult &R, FunctionDecl *Fn)
Gets the type of a function for template-argument-deducton purposes when it's considered as part of a...
static std::enable_if< IsPartialSpecialization< T >::value, Sema::TemplateDeductionResult >::type FinishTemplateArgumentDeduction(Sema &S, T *Partial, bool IsPartialOrdering, const TemplateArgumentList &TemplateArgs, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info)
Complete template argument deduction for a partial specialization.
Represents a template argument.
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
Represents a template name that was expressed as a qualified name.
Dataflow Directional Tag Classes.
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
const TemplateArgument & getArgument() const
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static QualType ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams, Expr *Arg, QualType ParamType, bool ParamWasReference)
Apply the deduction rules for overload sets.
The base class of all kinds of template declarations (e.g., class, function, etc.).
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
QualType getType() const
Get the type for which this source info wrapper provides information.
The template argument is a pack expansion of a template name that was provided for a template templat...
A non-depnedent component of the parameter did not match the corresponding component of the argument...
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
OverloadExpr * Expression
Represents a C++11 pack expansion that produces a sequence of expressions.
SourceLocation LAngleLoc
The source location of the left angle bracket ('<').
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool hasObjCLifetime() const
void setCVRQualifiers(unsigned mask)
bool isInitCapture() const
Whether this variable is the implicit variable for a lambda init-capture.
bool wasDeducedFromArrayBound() const
For a non-type template argument, determine whether the template argument was deduced from an array b...
pack_iterator pack_begin() const
Iterator referencing the first argument of a template argument pack.
bool isNull() const
Determine whether this template argument has no value.
No template argument deduction flags, which indicates the strictest results for template argument ded...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Allow non-dependent types to differ, e.g., when performing template argument deduction from a functio...
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
Represents a pointer to an Objective C object.
static bool isForwardingReference(QualType Param, unsigned FirstInnerIndex)
Determine whether a type denotes a forwarding reference.
unsigned getIntWidth(QualType T) const
bool isIncompleteArrayType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
Location wrapper for a TemplateArgument.
unsigned getNumArgs() const
Retrieve the number of template arguments.
The template argument was specified in the code or was instantiated with some deduced template argume...
TemplateArgumentList * take()
Take ownership of the deduced template argument list.
CanThrowResult canThrow() const
Determine whether this function type has a non-throwing exception specification.
const TemplateArgument & getArg(unsigned Idx) const
Retrieve a specific template argument as a type.
const llvm::APInt & getSize() const
bool isFunctionType() const
ExtVectorType - Extended vector type.
Base for LValueReferenceType and RValueReferenceType.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None)
The template argument is a type.
Deduction failed; that's all we know.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
The template argument is actually a parameter pack.
static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType &ParamType, QualType &ArgType, Expr *Arg, unsigned &TDF)
Perform the adjustments to the parameter and argument types described in C++ [temp.deduct.call].
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool hasObjCGCAttr() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
A template argument list.
bool isLValueReferenceType() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
pack_iterator pack_end() const
Iterator referencing one past the last argument of a template argument pack.
ArgKind getKind() const
Return the kind of stored template argument.
unsigned getDepth() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
QualType getParamType(unsigned i) const
CallingConv getCallConv() const
Defines the clang::SourceLocation class and associated facilities.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Within template argument deduction for a conversion function, we are matching with an argument type f...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
Represents a template specialization type whose template cannot be resolved, e.g. ...
ArrayRef< TemplateArgument > template_arguments() const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
The template argument is a template name that was provided for a template template parameter...
unsigned getNumExplicitArgs() const
Get the number of explicitly-specified arguments.
Represents a C array with an unspecified size.
TemplateName getCanonicalTemplateName(TemplateName Name) const
Retrieves the "canonical" template name that refers to a given template.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType removeAddrSpaceQualType(QualType T) const
Remove any existing address space on the type and returns the type with qualifiers intact (or that's ...
TPOC
The context in which partial ordering of function templates occurs.
Location information for a TemplateArgument.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
TemplateArgument SecondArg
The second template argument to which the template argument deduction failure refers.
Declaration of a class template.
Partial ordering of function templates for a function call.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
After substituting deduced template arguments, an element of a dependent parameter type did not match...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
A pack that we're currently deducing.
DeducedTemplateArgument Saved
SourceLocation getNameLoc() const
unsigned getCVRQualifiers() const
static bool isSameTemplateArg(ASTContext &Context, TemplateArgument X, const TemplateArgument &Y, bool PackExpansionMatchesPack=false)
Determine whether two template arguments are the same.
QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement)
Completely replace the auto in TypeWithAuto by Replacement.
Decl * SubstDecl(Decl *D, DeclContext *Owner, const MultiLevelTemplateArgumentList &TemplateArgs)
ClassTemplatePartialSpecializationDecl * getMoreSpecializedPartialSpecialization(ClassTemplatePartialSpecializationDecl *PS1, ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc)
Returns the more specialized class template partial specialization according to the rules of partial ...
static Qualifiers fromCVRMask(unsigned CVR)
static Decl::Kind getKind(const Decl *D)
unsigned getNumElements() const
bool IsQualificationConversion(QualType FromType, QualType ToType, bool CStyle, bool &ObjCLifetimeConversion)
IsQualificationConversion - Determines whether the conversion from an rvalue of type FromType to ToTy...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
QualType getAsType() const
Retrieve the type for a type template argument.
A reference to a declared variable, function, enum, etc.
Represents an extended address space qualifier where the input address space value is dependent...
Represents a type template specialization; the template must be a class template, a type alias templa...
Optional< unsigned > getNumArgumentsInExpansion(QualType T, const MultiLevelTemplateArgumentList &TemplateArgs)
Determine the number of arguments in the given pack expansion type.
bool isPointerType() const
unsigned CallArgIndex
The index of the function argument that caused a deduction failure.
void NoteCandidates(Sema &S, SourceLocation Loc)
NoteCandidates - When no template specialization match is found, prints diagnostic messages containin...
TemplateArgument FirstArg
The first template argument to which the template argument deduction failure refers.
TypeSourceInfo * SubstType(TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, SourceLocation Loc, DeclarationName Entity, bool AllowDeducedTST=false)
Perform substitution on the type T with a given set of template arguments.
static bool hasSameExtendedValue(llvm::APSInt X, llvm::APSInt Y)
Compare two APSInts, extending and switching the sign as necessary to compare their values regardless...
static bool hasTemplateArgumentForDeduction(ArrayRef< TemplateArgument > &Args, unsigned &ArgIdx)
Determine whether there is a template argument to be used for deduction.
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
Wrapper for template type parameters.
A trivial tuple used to represent a source range.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
This represents a decl that may have a name.
Partial ordering of function templates in other contexts, e.g., taking the address of a function temp...
static Optional< unsigned > getExpandedPackSize(NamedDecl *Param)
If Param is an expanded parameter pack, get the number of expansions.
void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark which template parameters can be deduced from a given template argument list.
static void AddImplicitObjectParameterType(ASTContext &Context, CXXMethodDecl *Method, SmallVectorImpl< QualType > &ArgTypes)
If this is a non-static member function,.
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
The template argument was deduced via template argument deduction.
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present...
bool isFunctionPointerType() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
void removeAddressSpace()
brief A function argument from which we performed template argument
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
const LangOptions & getLangOpts() const
bool isParameterPack() const
Determine whether this parameter is actually a function parameter pack.
diag_iterator diag_begin() const
Returns an iterator at the beginning of the sequence of suppressed diagnostics.
decls_iterator decls_end() const
Represents the canonical version of C arrays with a specified constant size.
ExceptionSpecInfo ExceptionSpec
Declaration of a template function.
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
DeducedTemplateArgument DeferredDeduction
SourceLocation getLocation() const
QualType getPointeeType() const
CanQualType UnsignedIntTy
Expr * getSizeExpr() const
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
param_type_iterator param_type_end() const