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 E = CE->getSubExpr();
184 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
185 E = Subst->getReplacement();
191 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl()))
201 if (
NamedDecl *NX = dyn_cast<NamedDecl>(X))
202 X = NX->getUnderlyingDecl();
203 if (
NamedDecl *NY = dyn_cast<NamedDecl>(Y))
204 Y = NY->getUnderlyingDecl();
239 llvm_unreachable(
"Non-deduced template arguments handled above");
290 llvm::FoldingSetNodeID ID1, ID2;
354 XA != XAEnd; ++XA, ++YA) {
360 NewPack.push_back(Merged);
369 llvm_unreachable(
"Invalid TemplateArgument Kind!");
381 "deducing non-type template argument with wrong depth");
385 if (Result.isNull()) {
406 if (
auto *Expansion = dyn_cast<PackExpansionType>(ParamType))
407 ParamType = Expansion->getPattern();
428 S, TemplateParams, NTTP,
430 DeducedFromArrayBound),
431 ValueType, Info, Deduced);
444 NullPtrType, CK_NullToPointer)
448 Value->
getType(), Info, Deduced);
461 Value->
getType(), Info, Deduced);
494 = dyn_cast<TemplateTemplateParmDecl>(ParamDecl)) {
501 Deduced[TempParam->getIndex()],
503 if (Result.isNull()) {
504 Info.
Param = TempParam;
505 Info.
FirstArg = Deduced[TempParam->getIndex()];
510 Deduced[TempParam->getIndex()] = Result;
549 assert(Arg.
isCanonical() &&
"Argument type must be canonical");
552 if (
auto *Injected = dyn_cast<InjectedClassNameType>(Arg))
553 Arg = Injected->getInjectedSpecializationType();
557 = dyn_cast<TemplateSpecializationType>(Arg)) {
562 SpecArg->getTemplateName(),
572 SpecArg->template_arguments(), Info, Deduced,
613 case Type::TypeOfExpr:
615 case Type::DependentName:
617 case Type::UnresolvedUsing:
618 case Type::TemplateTypeParm:
621 case Type::ConstantArray:
622 case Type::IncompleteArray:
623 case Type::VariableArray:
624 case Type::DependentSizedArray:
626 cast<ArrayType>(T)->getElementType());
646 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param))
647 if (NTTP->isExpandedParameterPack())
648 return NTTP->getNumExpansionTypes();
650 if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param))
651 if (TTP->isExpandedParameterPack())
652 return TTP->getNumExpansionTemplateParameters();
681 class PackDeductionScope {
687 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
688 unsigned NumNamedPacks = addPacks(Pattern);
689 finishConstruction(NumNamedPacks);
696 : S(S), TemplateParams(TemplateParams), Deduced(Deduced), Info(Info) {
698 finishConstruction(1);
702 void addPack(
unsigned Index) {
706 Pack.
Saved = Deduced[Index];
714 FixedNumExpansions = ExpandedPackExpansions;
716 Packs.push_back(Pack);
722 llvm::SmallBitVector SawIndices(TemplateParams->
size());
724 auto AddPack = [&](
unsigned Index) {
725 if (SawIndices[Index])
727 SawIndices[Index] =
true;
734 for (
unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
735 unsigned Depth, Index;
740 assert(!Packs.empty() &&
"Pack expansion without unexpanded packs?");
742 unsigned NumNamedPacks = Packs.size();
748 llvm::SmallBitVector
Used(TemplateParams->
size());
751 for (
int Index =
Used.find_first(); Index != -1;
752 Index =
Used.find_next(Index))
756 return NumNamedPacks;
759 void finishConstruction(
unsigned NumNamedPacks) {
762 unsigned NumPartialPackArgs = 0;
763 std::pair<unsigned, unsigned> PartialPackDepthIndex(-1u, -1u);
765 if (
auto *Partial =
Scope->getPartiallySubstitutedPack(
766 &PartialPackArgs, &NumPartialPackArgs))
772 bool IsExpanded =
true;
773 for (
unsigned I = 0; I != NumNamedPacks; ++I) {
776 IsPartiallyExpanded =
false;
779 if (PartialPackDepthIndex ==
781 IsPartiallyExpanded =
true;
787 if (IsPartiallyExpanded)
788 PackElements += NumPartialPackArgs;
790 PackElements += *FixedNumExpansions;
792 for (
auto &Pack : Packs) {
799 if (PartialPackDepthIndex ==
801 Pack.New.append(PartialPackArgs, PartialPackArgs + NumPartialPackArgs);
810 if (!IsPartiallyExpanded)
811 Deduced[Pack.Index] = Pack.New[PackElements];
817 ~PackDeductionScope() {
818 for (
auto &Pack : Packs)
824 bool isPartiallyExpanded() {
return IsPartiallyExpanded; }
829 bool hasFixedArity() {
return FixedNumExpansions.hasValue(); }
834 bool hasNextElement() {
835 return !FixedNumExpansions || *FixedNumExpansions > PackElements;
839 void nextPackElement() {
843 for (
auto &Pack : Packs) {
845 if (!Pack.New.empty() || !DeducedArg.
isNull()) {
846 while (Pack.New.size() < PackElements)
848 if (Pack.New.size() == PackElements)
849 Pack.New.push_back(DeducedArg);
851 Pack.New[PackElements] = DeducedArg;
852 DeducedArg = Pack.New.size() > PackElements + 1
853 ? Pack.New[PackElements + 1]
864 finish(
bool TreatNoDeductionsAsNonDeduced =
true) {
867 for (
auto &Pack : Packs) {
869 Deduced[Pack.Index] = Pack.Saved;
875 if (!TreatNoDeductionsAsNonDeduced)
876 Pack.New.resize(PackElements);
880 if (PackElements && Pack.New.empty()) {
881 if (Pack.DeferredDeduction.isNull()) {
888 NewPack = Pack.DeferredDeduction;
890 }
else if (Pack.New.empty()) {
896 std::copy(Pack.New.begin(), Pack.New.end(), ArgumentPack);
904 Pack.New[0].wasDeducedFromArrayBound());
910 if (Pack.Outer->DeferredDeduction.isNull()) {
913 Pack.Outer->DeferredDeduction = NewPack;
916 Loc = &Pack.Outer->DeferredDeduction;
918 Loc = &Deduced[Pack.Index];
927 if (!Result.
isNull() && !Pack.DeferredDeduction.isNull()) {
929 NewPack = Pack.DeferredDeduction;
944 if (*Expansions != PackElements) {
962 unsigned PackElements = 0;
963 bool IsPartiallyExpanded =
false;
1005 const QualType *Params,
unsigned NumParams,
1006 const QualType *Args,
unsigned NumArgs,
1010 bool PartialOrdering =
false) {
1025 if (ArgIdx >= NumArgs)
1028 if (isa<PackExpansionType>(Args[ArgIdx])) {
1055 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
1059 if (
ParamIdx + 1 == NumParams || PackScope.hasFixedArity()) {
1060 for (; ArgIdx < NumArgs && PackScope.hasNextElement(); ++ArgIdx) {
1064 Args[ArgIdx], Info, Deduced,
1068 PackScope.nextPackElement();
1089 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
1090 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < NumArgs;
1092 PackScope.nextPackElement();
1098 if (
auto Result = PackScope.finish())
1103 if (ArgIdx < NumArgs)
1118 if (ParamQs == ArgQs)
1153 if (!ParamFunction || !ArgFunction)
1154 return Param == Arg;
1158 if (IsFunctionConversion(Param, Arg, AdjustedParam))
1163 return Param == Arg;
1172 if (!Guide || !Guide->isImplicit())
1184 if (ParamRef->getPointeeType().getQualifiers())
1187 return TypeParm && TypeParm->
getIndex() >= FirstInnerIndex;
1223 bool PartialOrdering,
1224 bool DeducedFromArrayBound) {
1233 = dyn_cast<PackExpansionType>(Arg))
1234 Arg = ArgExpansion->getPattern();
1236 if (PartialOrdering) {
1318 TDF &= ~TDF_TopLevelParameterTypeList;
1339 unsigned Index = TemplateTypeParm->getIndex();
1340 bool RecanonicalizeArg =
false;
1344 if (isa<ArrayType>(Arg)) {
1349 RecanonicalizeArg =
true;
1357 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1370 "saw template type parameter with wrong depth");
1391 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1408 if (RecanonicalizeArg)
1416 Info.
Param = cast<TemplateTypeParmDecl>(TemplateParams->
getParam(Index));
1422 Deduced[Index] = Result;
1434 if (isa<SubstTemplateTypeParmPackType>(Param))
1480 : ParamUnqualType == ArgUnqualType;
1487 #define NON_CANONICAL_TYPE(Class, Base) \ 1488 case Type::Class: llvm_unreachable("deducing non-canonical type: " #Class); 1489 #define TYPE(Class, Base) 1490 #include "clang/AST/TypeNodes.def" 1492 case Type::TemplateTypeParm:
1493 case Type::SubstTemplateTypeParmPack:
1494 llvm_unreachable(
"Type nodes handled above");
1499 case Type::VariableArray:
1501 case Type::FunctionNoProto:
1504 case Type::ObjCObject:
1505 case Type::ObjCInterface:
1506 case Type::ObjCObjectPointer:
1510 if (TDF & TDF_IgnoreQualifiers) {
1521 cast<ComplexType>(Param)->getElementType(),
1522 ComplexArg->getElementType(),
1523 Info, Deduced, TDF);
1531 cast<AtomicType>(Param)->getValueType(),
1532 AtomicArg->getValueType(),
1533 Info, Deduced, TDF);
1538 case Type::Pointer: {
1551 cast<PointerType>(Param)->getPointeeType(),
1553 Info, Deduced, SubTDF);
1557 case Type::LValueReference: {
1564 cast<LValueReferenceType>(Param)->getPointeeType(),
1569 case Type::RValueReference: {
1576 cast<RValueReferenceType>(Param)->getPointeeType(),
1582 case Type::IncompleteArray: {
1585 if (!IncompleteArrayArg)
1592 Info, Deduced, SubTDF);
1596 case Type::ConstantArray: {
1599 if (!ConstantArrayArg)
1605 return Sema::TDK_NonDeducedMismatch;
1611 Info, Deduced, SubTDF);
1615 case Type::DependentSizedArray: {
1629 Info, Deduced, SubTDF))
1641 "saw non-type template parameter with wrong depth");
1643 = dyn_cast<ConstantArrayType>(ArrayArg)) {
1644 llvm::APSInt Size(ConstantArrayArg->getSize());
1651 = dyn_cast<DependentSizedArrayType>(ArrayArg))
1652 if (DependentArrayArg->getSizeExpr())
1654 DependentArrayArg->getSizeExpr(),
1664 case Type::FunctionProto: {
1668 if (!FunctionProtoArg)
1672 cast<FunctionProtoType>(Param);
1679 return Sema::TDK_NonDeducedMismatch;
1692 FunctionProtoArg->
getNumParams(), Info, Deduced, SubTDF))
1706 "saw non-type template parameter with wrong depth");
1708 llvm::APSInt Noexcept(1);
1709 switch (FunctionProtoArg->
canThrow()) {
1719 true, Info, Deduced);
1724 S, TemplateParams, NTTP, ArgNoexceptExpr, Info, Deduced);
1737 case Type::InjectedClassName:
1740 Param = cast<InjectedClassNameType>(Param)
1741 ->getInjectedSpecializationType();
1742 assert(isa<TemplateSpecializationType>(Param) &&
1743 "injected class name is not a template specialization type");
1751 case Type::TemplateSpecialization: {
1753 cast<TemplateSpecializationType>(Param);
1766 S, TemplateParams, SpecParam, Arg, Info, Deduced);
1789 Deduced = DeducedOrig;
1794 llvm::SmallPtrSet<const RecordType *, 8> Visited;
1796 ToVisit.push_back(RecordT);
1797 bool Successful =
false;
1799 while (!ToVisit.empty()) {
1801 const RecordType *NextT = ToVisit.pop_back_val();
1804 if (!Visited.insert(NextT).second)
1809 if (NextT != RecordT) {
1813 QualType(NextT, 0), BaseInfo, Deduced);
1825 std::swap(SuccessfulDeduced, Deduced);
1827 Info.
Param = BaseInfo.Param;
1832 Deduced = DeducedOrig;
1837 for (
const auto &
Base : Next->
bases()) {
1838 assert(
Base.getType()->isRecordType() &&
1839 "Base class that isn't a record?");
1845 std::swap(SuccessfulDeduced, Deduced);
1861 case Type::MemberPointer: {
1881 TDF & TDF_IgnoreQualifiers))
1886 QualType(MemPtrArg->getClass(), 0),
1888 TDF & TDF_IgnoreQualifiers);
1896 case Type::BlockPointer: {
1912 case Type::ExtVector: {
1913 const ExtVectorType *VectorParam = cast<ExtVectorType>(Param);
1914 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
1916 if (VectorParam->
getNumElements() != VectorArg->getNumElements())
1917 return Sema::TDK_NonDeducedMismatch;
1922 VectorArg->getElementType(),
1923 Info, Deduced, TDF);
1927 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
1935 VectorArg->getElementType(),
1936 Info, Deduced, TDF);
1942 case Type::DependentVector: {
1943 const auto *VectorParam = cast<DependentVectorType>(Param);
1945 if (
const auto *VectorArg = dyn_cast<VectorType>(Arg)) {
1949 S, TemplateParams, VectorParam->getElementType(),
1950 VectorArg->getElementType(), Info, Deduced, TDF))
1960 ArgSize = VectorArg->getNumElements();
1969 if (
const auto *VectorArg = dyn_cast<DependentVectorType>(Arg)) {
1973 S, TemplateParams, VectorParam->getElementType(),
1974 VectorArg->getElementType(), Info, Deduced, TDF))
1979 Info, VectorParam->getSizeExpr());
1984 S, TemplateParams, NTTP, VectorArg->getSizeExpr(), Info, Deduced);
1993 case Type::DependentSizedExtVector: {
1995 = cast<DependentSizedExtVectorType>(Param);
1997 if (
const ExtVectorType *VectorArg = dyn_cast<ExtVectorType>(Arg)) {
2002 VectorArg->getElementType(),
2003 Info, Deduced, TDF))
2013 ArgSize = VectorArg->getNumElements();
2023 = dyn_cast<DependentSizedExtVectorType>(Arg)) {
2028 VectorArg->getElementType(),
2029 Info, Deduced, TDF))
2039 VectorArg->getSizeExpr(),
2049 case Type::DependentAddressSpace: {
2051 cast<DependentAddressSpaceType>(Param);
2054 dyn_cast<DependentAddressSpaceType>(Arg)) {
2069 S, TemplateParams, NTTP, AddressSpaceArg->getAddrSpaceExpr(), Info,
2093 true, Info, Deduced);
2099 case Type::TypeOfExpr:
2101 case Type::DependentName:
2102 case Type::UnresolvedUsing:
2103 case Type::Decltype:
2104 case Type::UnaryTransform:
2106 case Type::DeducedTemplateSpecialization:
2107 case Type::DependentTemplateSpecialization:
2108 case Type::PackExpansion:
2114 llvm_unreachable(
"Invalid Type Class!");
2132 llvm_unreachable(
"Null template argument in parameter list");
2154 llvm_unreachable(
"caller should handle pack expansions");
2225 llvm_unreachable(
"Argument packs should be expanded by the caller!");
2228 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2241 if (ArgIdx == Args.size())
2248 assert(ArgIdx == Args.size() - 1 &&
"Pack not at the end of argument list?");
2251 return ArgIdx < Args.size();
2257 bool FoundPackExpansion =
false;
2258 for (
const auto &A : Args) {
2259 if (FoundPackExpansion)
2267 if (A.isPackExpansion())
2268 FoundPackExpansion =
true;
2280 bool NumberOfArgumentsMustMatch) {
2294 if (!Params[
ParamIdx].isPackExpansion()) {
2299 return NumberOfArgumentsMustMatch
2306 if (Args[ArgIdx].isPackExpansion())
2331 PackDeductionScope PackScope(S, TemplateParams, Deduced, Info, Pattern);
2337 PackScope.hasNextElement();
2345 PackScope.nextPackElement();
2350 if (
auto Result = PackScope.finish())
2365 ArgList.
asArray(), Info, Deduced,
2373 bool PackExpansionMatchesPack =
false) {
2384 llvm_unreachable(
"Comparing NULL template argument");
2407 llvm::FoldingSetNodeID XID, YID;
2420 XP != XPEnd; ++XP, ++YP)
2427 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2448 llvm_unreachable(
"Can't get a NULL template argument here");
2457 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2465 Expr *E = BuildExpressionFromDeclTemplateArgument(Arg, NTTPType, Loc)
2473 BuildExpressionFromIntegralTemplateArgument(Arg, Loc).getAs<
Expr>();
2482 Builder.
MakeTrivial(Context, DTN->getQualifier(), Loc);
2485 Builder.
MakeTrivial(Context, QTN->getQualifier(), Loc);
2502 llvm_unreachable(
"Invalid TemplateArgument Kind!");
2515 unsigned ArgumentPackIndex) {
2543 "deduced nested pack");
2550 diag::err_template_arg_deduced_incomplete_pack)
2554 if (ConvertArg(InnerArg, PackedArgsBuilder.size()))
2558 PackedArgsBuilder.push_back(Output.pop_back_val());
2563 if (PackedArgsBuilder.empty()) {
2568 if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
2572 if (Inst.isInvalid() ||
2573 S.
SubstType(NTTP->getType(), Args, NTTP->getLocation(),
2574 NTTP->getDeclName()).isNull())
2576 }
else if (
auto *TTP = dyn_cast<TemplateTemplateParmDecl>(Param)) {
2592 return ConvertArg(Arg, 0);
2598 template<
typename TemplateDeclT>
2600 Sema &S, TemplateDeclT *Template,
bool IsDeduced,
2604 unsigned NumAlreadyConverted = 0,
bool PartialOverloading =
false) {
2607 for (
unsigned I = 0, N = TemplateParams->
size(); I != N; ++I) {
2615 if (
auto Result = PackDeductionScope(S, TemplateParams, Deduced, Info, I)
2620 if (!Deduced[I].isNull()) {
2621 if (I < NumAlreadyConverted) {
2626 CurrentInstantiationScope->getPartiallySubstitutedPack() == Param) {
2629 CurrentInstantiationScope->ResetPartiallySubstitutedPack();
2636 Builder.push_back(Deduced[I]);
2644 IsDeduced, Builder)) {
2655 bool HasDefaultArg =
false;
2658 assert(isa<ClassTemplatePartialSpecializationDecl>(Template) ||
2659 isa<VarTemplatePartialSpecializationDecl>(Template));
2670 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2672 if (PartialOverloading)
break;
2683 const_cast<NamedDecl *>(TemplateParams->
getParam(I)));
2696 if (
auto *DC = dyn_cast<DeclContext>(D))
2702 static constexpr
bool value =
false;
2706 static constexpr
bool value =
true;
2710 static constexpr
bool value =
true;
2714 template <
typename T>
2715 static typename std::enable_if<IsPartialSpecialization<T>::value,
2718 Sema &S, T *Partial,
bool IsPartialOrdering,
2734 S, Partial, IsPartialOrdering, Deduced, Info, Builder))
2741 Info.
reset(DeducedArgumentList);
2749 auto *Template = Partial->getSpecializedTemplate();
2751 Partial->getTemplateArgsAsWritten();
2761 if (
ParamIdx >= Partial->getTemplateParameters()->size())
2762 ParamIdx = Partial->getTemplateParameters()->size() - 1;
2765 Partial->getTemplateParameters()->getParam(
ParamIdx));
2773 false, ConvertedInstArgs))
2777 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2813 S, Template, PartialOrdering, Deduced, Info, Builder))
2818 for (
unsigned I = 0, E = TemplateParams->
size(); I != E; ++I) {
2863 TemplateArgs, Info, Deduced))
2869 if (Inst.isInvalid())
2870 return TDK_InstantiationDepth;
2876 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2904 TemplateArgs, Info, Deduced))
2910 if (Inst.isInvalid())
2911 return TDK_InstantiationDepth;
2917 *
this, Partial,
false, TemplateArgs, Deduced, Info);
2924 return Spec->getTemplateName().getAsTemplateDecl() !=
nullptr;
2976 if (ExplicitTemplateArgs.
size() == 0) {
2980 ParamTypes.push_back(
P->getType());
2983 *FunctionType = Function->
getType();
3004 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3005 CodeSynthesisContext::ExplicitTemplateArgumentSubstitution, Info);
3006 if (Inst.isInvalid())
3007 return TDK_InstantiationDepth;
3009 if (CheckTemplateArgumentList(FunctionTemplate,
SourceLocation(),
3010 ExplicitTemplateArgs,
true, Builder,
false) ||
3012 unsigned Index = Builder.size();
3013 if (Index >= TemplateParams->
size())
3014 return TDK_SubstitutionFailure;
3016 return TDK_InvalidExplicitArguments;
3035 unsigned PartiallySubstitutedPackIndex = -1u;
3036 if (!Builder.empty()) {
3039 auto *Param = TemplateParams->
getParam(Builder.size() - 1);
3043 if (!Expansions || Arg.
pack_size() < *Expansions) {
3044 PartiallySubstitutedPackIndex = Builder.size() - 1;
3045 CurrentInstantiationScope->SetPartiallySubstitutedPack(
3053 assert(Proto &&
"Function template does not have a prototype?");
3068 ParamTypes,
nullptr, ExtParamInfos))
3069 return TDK_SubstitutionFailure;
3083 if (
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Function)) {
3085 ThisTypeQuals = Method->getTypeQualifiers();
3096 return TDK_SubstitutionFailure;
3105 ParamTypes,
nullptr, ExtParamInfos))
3106 return TDK_SubstitutionFailure;
3116 if (getLangOpts().CPlusPlus17 &&
3118 Function->
getLocation(), EPI.ExceptionSpec, ExceptionStorage,
3120 return TDK_SubstitutionFailure;
3122 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
3127 return TDK_SubstitutionFailure;
3140 Deduced.reserve(TemplateParams->
size());
3141 for (
unsigned I = 0, N = ExplicitArgumentList->
size(); I != N; ++I) {
3143 if (I == PartiallySubstitutedPackIndex)
3146 Deduced.push_back(Arg);
3214 if (AQuals == DeducedAQuals) {
3232 bool ObjCLifetimeConversion =
false;
3236 ObjCLifetimeConversion) ||
3282 if (PD->isParameterPack()) {
3283 unsigned NumExpansions =
3285 if (Idx + NumExpansions > ParamIdx)
3286 return ParamIdx - Idx;
3287 Idx += NumExpansions;
3289 if (Idx == ParamIdx)
3295 llvm_unreachable(
"parameter index would not be produced from template");
3307 unsigned NumExplicitlySpecified,
FunctionDecl *&Specialization,
3310 bool PartialOverloading, llvm::function_ref<
bool()> CheckNonDependent) {
3320 *
this, Info.
getLocation(), FunctionTemplate, DeducedArgs,
3321 CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3322 if (Inst.isInvalid())
3323 return TDK_InstantiationDepth;
3332 *
this, FunctionTemplate,
true, Deduced, Info, Builder,
3333 CurrentInstantiationScope, NumExplicitlySpecified,
3334 PartialOverloading))
3346 if (CheckNonDependent())
3347 return TDK_NonDependentConversionFailure;
3352 Info.
reset(DeducedArgumentList);
3360 Specialization = cast_or_null<FunctionDecl>(
3363 return TDK_SubstitutionFailure;
3379 return TDK_SubstitutionFailure;
3382 if (OriginalCallArgs) {
3387 llvm::SmallDenseMap<std::pair<unsigned, QualType>,
QualType> DeducedATypes;
3388 for (
unsigned I = 0, N = OriginalCallArgs->size(); I != N; ++I) {
3409 if (CacheEntry.
isNull()) {
3418 DeducedA = CacheEntry;
3432 SuppressedDiagnosticsMap::iterator
3434 if (Pos == SuppressedDiagnostics.end())
3452 if (Method->isInstance()) {
3473 bool ParamWasReference) {
3481 if (ParamWasReference)
3528 Specialization, Info))
3536 if (ArgType.isNull())
continue;
3540 ArgType->isFunctionType())
3556 Deduced(TemplateParams->
size());
3560 ArgType, Info, Deduced, TDF);
3561 if (Result)
continue;
3597 ParamRefType !=
nullptr);
3658 (isa<PointerType>(ParamType) &&
3675 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF);
3699 ElTy = ArrTy->getElementType();
3710 S, TemplateParams, 0, ElTy, E, Info, Deduced, OriginalCallArgs,
true,
3718 if (
auto *DependentArrTy = dyn_cast_or_null<DependentSizedArrayType>(ArrTy)) {
3729 S, TemplateParams, NTTP, llvm::APSInt(Size), T,
3730 true, Info, Deduced))
3745 bool DecomposedParam,
unsigned ArgIdx,
unsigned TDF) {
3747 QualType OrigParamType = ParamType;
3752 S, TemplateParams, FirstInnerIndex, ParamType, ArgType, Arg, TDF))
3758 Deduced, OriginalCallArgs, ArgIdx, TDF);
3765 OriginalCallArgs.push_back(
3768 ArgType, Info, Deduced, TDF);
3800 bool PartialOverloading,
3815 return TDK_TooFewArguments;
3816 else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
3822 return TDK_TooManyArguments;
3832 unsigned NumExplicitlySpecified = 0;
3833 if (ExplicitTemplateArgs) {
3835 SubstituteExplicitTemplateArguments(FunctionTemplate,
3836 *ExplicitTemplateArgs,
3844 NumExplicitlySpecified = Deduced.size();
3847 for (
unsigned I = 0; I != NumParams; ++I)
3854 auto DeduceCallArgument = [&](
QualType ParamType,
unsigned ArgIdx) {
3864 *
this, TemplateParams, FirstInnerIndex, ParamType, Args[ArgIdx], Info, Deduced,
3865 OriginalCallArgs,
false, ArgIdx, 0);
3869 Deduced.resize(TemplateParams->
size());
3871 for (
unsigned ParamIdx = 0, NumParamTypes = ParamTypes.size(), ArgIdx = 0;
3877 if (!ParamExpansion) {
3879 if (ArgIdx >= Args.size())
3882 ParamTypesForArgChecking.push_back(ParamType);
3883 if (
auto Result = DeduceCallArgument(ParamType, ArgIdx++))
3890 PackDeductionScope PackScope(*
this, TemplateParams, Deduced, Info,
3909 if (
ParamIdx + 1 == NumParamTypes || PackScope.hasFixedArity()) {
3910 for (; ArgIdx < Args.size() && PackScope.hasNextElement();
3911 PackScope.nextPackElement(), ++ArgIdx) {
3912 ParamTypesForArgChecking.push_back(ParamPattern);
3913 if (
auto Result = DeduceCallArgument(ParamPattern, ArgIdx))
3921 if (NumExpansions && !PackScope.isPartiallyExpanded()) {
3922 for (
unsigned I = 0; I != *NumExpansions && ArgIdx < Args.size();
3924 ParamTypesForArgChecking.push_back(ParamPattern);
3927 PackScope.nextPackElement();
3934 if (
auto Result = PackScope.finish())
3943 FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
3944 &OriginalCallArgs, PartialOverloading, [&, CallingCtx]() {
3946 return CheckNonDependent(ParamTypesForArgChecking);
3952 bool AdjustExceptionSpec) {
3953 if (ArgFunctionType.
isNull())
3954 return ArgFunctionType;
3962 bool Rebuild =
false;
3965 if (EPI.ExtInfo.getCC() != CC) {
3966 EPI.ExtInfo = EPI.ExtInfo.withCallingConv(CC);
3971 if (EPI.ExtInfo.getNoReturn() != NoReturn) {
3972 EPI.ExtInfo = EPI.ExtInfo.withNoReturn(NoReturn);
3977 ArgFunctionTypeP->hasExceptionSpec())) {
3983 return ArgFunctionType;
3986 ArgFunctionTypeP->getParamTypes(), EPI);
4021 bool IsAddressOfFunction) {
4033 unsigned NumExplicitlySpecified = 0;
4035 if (ExplicitTemplateArgs) {
4037 = SubstituteExplicitTemplateArguments(FunctionTemplate,
4038 *ExplicitTemplateArgs,
4039 Deduced, ParamTypes,
4040 &FunctionType, Info))
4043 NumExplicitlySpecified = Deduced.size();
4049 if (!IsAddressOfFunction)
4050 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, FunctionType,
4058 Deduced.resize(TemplateParams->
size());
4064 bool HasDeducedReturnType =
false;
4065 if (getLangOpts().CPlusPlus14 && IsAddressOfFunction &&
4067 FunctionType = SubstAutoType(FunctionType, Context.
DependentTy);
4068 HasDeducedReturnType =
true;
4071 if (!ArgFunctionType.
isNull()) {
4077 FunctionType, ArgFunctionType,
4078 Info, Deduced, TDF))
4084 NumExplicitlySpecified,
4085 Specialization, Info))
4090 if (HasDeducedReturnType &&
4092 DeduceReturnType(Specialization, Info.
getLocation(),
false))
4093 return TDK_MiscellaneousDeductionFailure;
4097 auto *SpecializationFPT =
4099 if (getLangOpts().CPlusPlus17 &&
4101 !ResolveExceptionSpec(Info.
getLocation(), SpecializationFPT))
4102 return TDK_MiscellaneousDeductionFailure;
4109 if (!IsAddressOfFunction)
4110 ArgFunctionType = adjustCCAndNoReturn(ArgFunctionType, SpecializationType,
4116 if (!ArgFunctionType.
isNull()) {
4117 if (IsAddressOfFunction &&
4118 !isSameOrCompatibleFunctionType(
4121 return TDK_MiscellaneousDeductionFailure;
4123 if (!IsAddressOfFunction &&
4124 !Context.
hasSameType(SpecializationType, ArgFunctionType))
4125 return TDK_MiscellaneousDeductionFailure;
4174 assert(!A->
isReferenceType() &&
"Reference types were handled above");
4211 Deduced.resize(TemplateParams->
size());
4235 P, A, Info, Deduced, TDF))
4244 ConversionSpecialized, Info);
4245 Specialization = cast_or_null<CXXConversionDecl>(ConversionSpecialized);
4277 bool IsAddressOfFunction) {
4280 IsAddressOfFunction);
4287 class SubstituteDeducedTypeTransform :
4293 SubstituteDeducedTypeTransform(
Sema &SemaRef,
QualType Replacement,
4294 bool UseTypeSugar =
true)
4296 Replacement(Replacement), UseTypeSugar(UseTypeSugar) {}
4299 assert(isa<TemplateTypeParmType>(Replacement) &&
4300 "unexpected unsugared replacement kind");
4318 return TransformDesugared(TLB, TL);
4327 QualType TransformDeducedTemplateSpecializationType(
4330 return TransformDesugared(TLB, TL);
4334 Replacement, Replacement.
isNull());
4350 return TransformType(TLB, TL);
4359 return DeduceAutoType(Type->
getTypeLoc(), Init, Result,
4360 DependentDeductionDepth);
4373 auto D = S.
Diag(Info.
getLocation(), diag::err_auto_inconsistent_deduction);
4375 for (
auto R : Ranges)
4406 ExprResult NonPlaceholder = CheckPlaceholderExpr(Init);
4408 return DAR_FailedAlreadyDiagnosed;
4409 Init = NonPlaceholder.
get();
4412 if (!DependentDeductionDepth &&
4414 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4415 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4416 return DAR_Succeeded;
4420 unsigned Depth = DependentDeductionDepth.getValueOr(0);
4426 if (AT->isDecltypeAuto()) {
4427 if (isa<InitListExpr>(Init)) {
4429 return DAR_FailedAlreadyDiagnosed;
4434 return DAR_FailedAlreadyDiagnosed;
4438 return DAR_FailedAlreadyDiagnosed;
4441 Result = SubstituteDeducedTypeTransform(*
this, Deduced).Apply(Type);
4443 return DAR_FailedAlreadyDiagnosed;
4444 return DAR_Succeeded;
4445 }
else if (!getLangOpts().CPlusPlus) {
4446 if (isa<InitListExpr>(Init)) {
4448 return DAR_FailedAlreadyDiagnosed;
4459 Context,
nullptr,
SourceLocation(), Loc, Depth, 0,
nullptr,
false,
false);
4463 Loc, Loc, TemplParamPtr, Loc,
nullptr);
4466 SubstituteDeducedTypeTransform(*
this, TemplArg,
false)
4468 assert(!FuncParam.
isNull() &&
4469 "substituting template parameter for 'auto' failed");
4482 Result = SubstituteDeducedTypeTransform(*
this,
QualType()).Apply(Type);
4483 assert(!Result.
isNull() &&
"substituting DependentTy can't fail");
4484 return DAR_Succeeded;
4487 return DAR_FailedAlreadyDiagnosed;
4502 for (
unsigned i = 0, e = InitList->
getNumInits(); i < e; ++i) {
4506 *
this, TemplateParamsSt.get(), 0, TemplArg, Init,
4507 Info, Deduced, OriginalCallArgs,
true,
4509 return DeductionFailed(TDK, {DeducedFromInitRange,
4510 Init->getSourceRange()});
4514 DeducedFromInitRange = Init->getSourceRange();
4518 Diag(Loc, diag::err_auto_bitfield);
4519 return DAR_FailedAlreadyDiagnosed;
4523 *
this, TemplateParamsSt.get(), 0, FuncParam, Init, Info, Deduced,
4524 OriginalCallArgs,
false, 0, 0))
4525 return DeductionFailed(TDK, {});
4530 return DeductionFailed(TDK_Incomplete, {});
4535 DeducedType = BuildStdInitializerList(DeducedType, Loc);
4536 if (DeducedType.isNull())
4537 return DAR_FailedAlreadyDiagnosed;
4540 Result = SubstituteDeducedTypeTransform(*
this, DeducedType).Apply(Type);
4542 return DAR_FailedAlreadyDiagnosed;
4546 QualType DeducedA = InitList ? Deduced[0].getAsType() : Result;
4548 assert((
bool)InitList == OriginalArg.DecomposedParam &&
4549 "decomposed non-init-list in auto deduction?");
4553 return DeductionFailed(TDK, {});
4557 return DAR_Succeeded;
4564 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4565 .TransformType(TypeWithAuto);
4572 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto)
4573 .TransformType(TypeWithAuto);
4578 return SubstituteDeducedTypeTransform(*
this, TypeToReplaceAuto,
4580 .TransformType(TypeWithAuto);
4584 if (isa<InitListExpr>(Init))
4587 ? diag::err_init_capture_deduction_failure_from_init_list
4588 : diag::err_auto_var_deduction_failure_from_init_list)
4592 VDecl->
isInitCapture() ? diag::err_init_capture_deduction_failure
4593 : diag::err_auto_var_deduction_failure)
4605 CXXRecordDecl *Lambda = cast<CXXMethodDecl>(FD)->getParent();
4610 CallOp = InstantiateFunctionDeclaration(
4618 InstantiateFunctionDefinition(Loc, CallOp);
4624 "failed to deduce lambda return type");
4627 QualType RetType = getLambdaConversionFunctionResultType(
4640 InstantiateFunctionDefinition(Loc, FD);
4644 Diag(Loc, diag::err_auto_fn_used_before_defined) << FD;
4648 return StillUndeduced;
4669 ArgTypes.push_back(ArgTy);
4679 unsigned NumCallArguments1) {
4685 assert(Proto1 && Proto2 &&
"Function templates must have prototypes");
4688 Deduced.resize(TemplateParams->
size());
4719 unsigned NumComparedArguments = NumCallArguments1;
4721 if (!Method2 && Method1 && !Method1->
isStatic()) {
4724 ++NumComparedArguments;
4725 }
else if (!Method1 && Method2 && !Method2->
isStatic()) {
4732 Args2.insert(Args2.end(), Proto2->param_type_begin(),
4733 Proto2->param_type_end());
4738 if (Args1.size() > NumComparedArguments)
4739 Args1.resize(NumComparedArguments);
4740 if (Args2.size() > NumComparedArguments)
4741 Args2.resize(NumComparedArguments);
4743 Args1.data(), Args1.size(), Info, Deduced,
4754 S, TemplateParams, Proto2->getReturnType(), Proto1->
getReturnType(),
4777 unsigned ArgIdx = 0, NumArgs = Deduced.size();
4778 for (; ArgIdx != NumArgs; ++ArgIdx)
4779 if (Deduced[ArgIdx].isNull())
4786 if (ArgIdx == NumArgs) {
4793 llvm::SmallBitVector UsedParameters(TemplateParams->
size());
4796 for (
unsigned I = 0, N = Args2.size(); I != N; ++I)
4804 TemplateParams->
getDepth(), UsedParameters);
4814 for (; ArgIdx != NumArgs; ++ArgIdx)
4817 if (Deduced[ArgIdx].isNull() && UsedParameters[ArgIdx])
4836 while (--NumParams > 0) {
4867 unsigned NumCallArguments1,
4868 unsigned NumCallArguments2) {
4874 if (Better1 != Better2)
4875 return Better1 ? FT1 : FT2;
4877 if (!Better1 && !Better2)
4885 if (Variadic1 != Variadic2)
4886 return Variadic1? FT2 : FT1;
4932 bool Complain,
QualType TargetType) {
4933 if (SpecBegin == SpecEnd) {
4935 Diag(Loc, NoneDiag);
4941 if (SpecBegin + 1 == SpecEnd)
4948 = cast<FunctionDecl>(*Best)->getPrimaryTemplate();
4949 assert(BestTemplate &&
"Not a function template specialization?");
4952 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4953 assert(Challenger &&
"Not a function template specialization?");
4954 if (
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4958 BestTemplate = Challenger;
4964 bool Ambiguous =
false;
4967 = cast<FunctionDecl>(*I)->getPrimaryTemplate();
4969 !
isSameTemplate(getMoreSpecializedTemplate(BestTemplate, Challenger,
4984 Diag(Loc, AmbigDiag);
4989 const auto *FD = cast<FunctionDecl>(*I);
4990 PD << FD << getTemplateArgumentBindingsText(
4991 FD->getPrimaryTemplate()->getTemplateParameters(),
4992 *FD->getTemplateSpecializationArgs());
4993 if (!TargetType.
isNull())
4994 HandleFunctionTypeMismatch(PD, FD->getType(), TargetType);
4995 Diag((*I)->getLocation(), PD);
5009 template<
typename TemplateLikeDecl>
5011 TemplateLikeDecl *P2,
5040 Deduced.resize(P2->getTemplateParameters()->size());
5054 TST1->template_arguments()),
5083 if (Better1 == Better2)
5086 return Better1 ? PS1 : PS2;
5110 "the partial specializations being compared should specialize" 5111 " the same template.");
5123 if (Better1 == Better2)
5126 return Better1 ? PS1 : PS2;
5141 CanonTemplate, PrimaryArgs);
5185 for (
unsigned I = 0, N = P->
size(); I != N; ++I) {
5193 PArgList.addArgument(getTrivialTemplateArgumentLoc(
5201 if (CheckTemplateArgumentList(AArg, Loc, PArgList,
false, PArgs) ||
5223 llvm::SmallBitVector &
Used) {
5226 E = Expansion->getPattern();
5232 E = ICE->getSubExpr();
5233 else if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(E))
5234 E = CE->getSubExpr();
5236 dyn_cast<SubstNonTypeTemplateParmExpr>(E))
5237 E = Subst->getReplacement();
5269 llvm::SmallBitVector &
Used) {
5276 OnlyDeduced, Depth, Used);
5286 llvm::SmallBitVector &
Used) {
5289 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
5290 if (TTP->getDepth() ==
Depth)
5291 Used[TTP->getIndex()] =
true;
5310 llvm::SmallBitVector &
Used) {
5322 cast<PointerType>(T)->getPointeeType(),
5328 case Type::BlockPointer:
5330 cast<BlockPointerType>(T)->getPointeeType(),
5336 case Type::LValueReference:
5337 case Type::RValueReference:
5339 cast<ReferenceType>(T)->getPointeeType(),
5345 case Type::MemberPointer: {
5350 OnlyDeduced, Depth, Used);
5354 case Type::DependentSizedArray:
5356 cast<DependentSizedArrayType>(T)->getSizeExpr(),
5357 OnlyDeduced, Depth, Used);
5361 case Type::ConstantArray:
5362 case Type::IncompleteArray:
5364 cast<ArrayType>(T)->getElementType(),
5365 OnlyDeduced, Depth, Used);
5369 case Type::ExtVector:
5371 cast<VectorType>(T)->getElementType(),
5372 OnlyDeduced, Depth, Used);
5375 case Type::DependentVector: {
5376 const auto *VecType = cast<DependentVectorType>(T);
5383 case Type::DependentSizedExtVector: {
5385 = cast<DependentSizedExtVectorType>(T);
5393 case Type::DependentAddressSpace: {
5395 cast<DependentAddressSpaceType>(T);
5404 case Type::FunctionProto: {
5408 for (
unsigned I = 0, N = Proto->
getNumParams(); I != N; ++I) {
5413 if (!OnlyDeduced || I + 1 == N ||
5431 case Type::TemplateTypeParm: {
5438 case Type::SubstTemplateTypeParmPack: {
5440 = cast<SubstTemplateTypeParmPackType>(T);
5443 OnlyDeduced, Depth, Used);
5449 case Type::InjectedClassName:
5450 T = cast<InjectedClassNameType>(T)->getInjectedSpecializationType();
5453 case Type::TemplateSpecialization: {
5455 = cast<TemplateSpecializationType>(T);
5467 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5476 cast<ComplexType>(T)->getElementType(),
5477 OnlyDeduced, Depth, Used);
5483 cast<AtomicType>(T)->getValueType(),
5484 OnlyDeduced, Depth, Used);
5487 case Type::DependentName:
5490 cast<DependentNameType>(T)->getQualifier(),
5491 OnlyDeduced, Depth, Used);
5494 case Type::DependentTemplateSpecialization: {
5508 = cast<DependentTemplateSpecializationType>(T);
5513 for (
unsigned I = 0, N = Spec->
getNumArgs(); I != N; ++I)
5523 OnlyDeduced, Depth, Used);
5526 case Type::TypeOfExpr:
5529 cast<TypeOfExprType>(T)->getUnderlyingExpr(),
5530 OnlyDeduced, Depth, Used);
5533 case Type::Decltype:
5536 cast<DecltypeType>(T)->getUnderlyingExpr(),
5537 OnlyDeduced, Depth, Used);
5540 case Type::UnaryTransform:
5544 OnlyDeduced, Depth, Used);
5547 case Type::PackExpansion:
5549 cast<PackExpansionType>(T)->getPattern(),
5550 OnlyDeduced, Depth, Used);
5554 case Type::DeducedTemplateSpecialization:
5556 cast<DeducedType>(T)->getDeducedType(),
5557 OnlyDeduced, Depth, Used);
5562 case Type::VariableArray:
5563 case Type::FunctionNoProto:
5566 case Type::ObjCInterface:
5567 case Type::ObjCObject:
5568 case Type::ObjCObjectPointer:
5569 case Type::UnresolvedUsing:
5571 #define TYPE(Class, Base) 5572 #define ABSTRACT_TYPE(Class, Base) 5573 #define DEPENDENT_TYPE(Class, Base) 5574 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 5575 #include "clang/AST/TypeNodes.def" 5587 llvm::SmallBitVector &
Used) {
5588 switch (TemplateArg.
getKind()) {
5634 bool OnlyDeduced,
unsigned Depth,
5635 llvm::SmallBitVector &
Used) {
5644 for (
unsigned I = 0, N = TemplateArgs.
size(); I != N; ++I)
5653 llvm::SmallBitVector &Deduced) {
5657 Deduced.resize(TemplateParams->
size());
5660 for (
unsigned I = 0, N = Function->
getNumParams(); I != N; ++I)
5662 true, TemplateParams->
getDepth(), Deduced);
5673 llvm::SmallBitVector Deduced(TemplateParams->
size());
5677 return Deduced.any();
const IncompleteArrayType * getAsIncompleteArrayType(QualType T) const
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Defines the clang::ASTContext interface.
The null pointer literal (C++11 [lex.nullptr])
Represents a function declaration or definition.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers, not considering qualifier compatibility.
static DeducedTemplateArgument checkDeducedTemplateArguments(ASTContext &Context, const DeducedTemplateArgument &X, const DeducedTemplateArgument &Y)
Verify that the given, deduced template arguments are compatible.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
const TypeClass * getTypePtr() const
bool isTemplateVariadic() const
Determines whether this function prototype contains a parameter pack at the end.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
TemplateDeductionResult
Describes the result of template argument deduction.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
bool isMemberPointerType() const
bool isLambdaConversionOperator(CXXConversionDecl *C)
llvm::PointerUnion3< TemplateTypeParmDecl *, NonTypeTemplateParmDecl *, TemplateTemplateParmDecl * > TemplateParameter
Stores a template parameter of any kind.
A stack-allocated class that identifies which local variable declaration instantiations are present i...
Template argument deduction was successful.
UnresolvedSetIterator getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, TemplateSpecCandidateSet &FailedCandidates, SourceLocation Loc, const PartialDiagnostic &NoneDiag, const PartialDiagnostic &AmbigDiag, const PartialDiagnostic &CandidateDiag, bool Complain=true, QualType TargetType=QualType())
Retrieve the most specialized of the given function template specializations.
const Expr * getInit(unsigned Init) const
static Sema::TemplateDeductionResult ConvertDeducedTemplateArguments(Sema &S, TemplateDeclT *Template, bool IsDeduced, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info, SmallVectorImpl< TemplateArgument > &Builder, LocalInstantiationScope *CurrentInstantiationScope=nullptr, unsigned NumAlreadyConverted=0, bool PartialOverloading=false)
FunctionType - C99 6.7.5.3 - Function Declarators.
static Sema::TemplateDeductionResult CheckOriginalCallArgDeduction(Sema &S, TemplateDeductionInfo &Info, Sema::OriginalCallArg OriginalArg, QualType DeducedA)
Check whether the deduced argument type for a call to a function template matches the actual argument...
Provides information about an attempted template argument deduction, whose success or failure was des...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
C Language Family Type Representation.
void setObjCLifetime(ObjCLifetime type)
The template argument is an expression, and we've not resolved it to one of the other forms yet...
bool isRecordType() const
unsigned size() const
Retrieve the number of template arguments in this template argument list.
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
const Type * getTypeForDecl() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
static bool IsPossiblyOpaquelyQualifiedType(QualType T)
Determines whether the given type is an opaque type that might be more qualified when instantiated...
bool isVariadic() const
Whether this function prototype is variadic.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Template argument deduction produced inconsistent deduced values for the given template parameter...
NamedDecl * getParam(unsigned Idx)
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
A container of type source information.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getConversionType() const
Returns the type that this conversion function is converting to.
Partial ordering of function templates for a call to a conversion function.
bool CheckTemplateArgumentList(TemplateDecl *Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, SmallVectorImpl< TemplateArgument > &Converted, bool UpdateArgsWithConversions=true)
Check that the given template arguments can be be provided to the given template, converting the argu...
TemplateDeductionResult FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, SmallVectorImpl< OriginalCallArg > const *OriginalCallArgs=nullptr, bool PartialOverloading=false, llvm::function_ref< bool()> CheckNonDependent=[]{ return false;})
Finish template argument deduction for a function template, checking the deduced template arguments f...
QualType getElementType() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static void MarkUsedTemplateParameters(ASTContext &Ctx, const TemplateArgument &TemplateArg, bool OnlyDeduced, unsigned Depth, llvm::SmallBitVector &Used)
Mark the template parameters that are used by this template argument.
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
This file provides some common utility functions for processing Lambda related AST Constructs...
unsigned getDepth() const
Get the nesting depth of the template parameter.
RAII object that enters a new expression evaluation context.
Represents a variable declaration or definition.
void removeObjCLifetime()
QualType getReturnType() const
unsigned getNumParams() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
TemplateDeductionFlags
Various flags that control template argument deduction.
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical) const
Produce a unique representation of the given statement.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
SourceLocation getLAngleLoc() const
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
void clearSFINAEDiagnostic()
Discard any SFINAE diagnostics.
TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, Decl *Param, SmallVectorImpl< TemplateArgument > &Converted, bool &HasDefaultArg)
If the given template parameter has a default template argument, substitute into that default templat...
bool isParameterPack() const
Whether this declaration is a parameter pack.
Whether we are performing template argument deduction for parameters and arguments in a top-level tem...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
TemplateParameter Param
The template parameter to which a template argument deduction failure refers.
QualType getIntegralType() const
Retrieve the type of the integral value.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
The collection of all-type qualifiers we support.
Base wrapper for a particular "section" of type source info.
QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, bool AdjustExceptionSpec=false)
Adjust the type ArgFunctionType to match the calling convention, noreturn, and optionally the excepti...
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a class template specialization, which refers to a class template with a given set of temp...
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
void setDeducedFromArrayBound(bool Deduced)
Specify whether the given non-type template argument was deduced from an array bound.
TemplateArgument getPackExpansionPattern() const
When the template argument is a pack expansion, returns the pattern of the pack expansion.
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
static TemplateArgument getEmptyPack()
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
QualType getPointeeType() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a dependent template name that cannot be resolved prior to template instantiation.
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base)
Determine whether the type Derived is a C++ class that is derived from the type Base.
SourceLocation getBeginLoc() const LLVM_READONLY
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
static bool isVariadicFunctionTemplate(FunctionTemplateDecl *FunTmpl)
Determine whether this a function template whose parameter-type-list ends with a function parameter p...
Defines the ExceptionSpecificationType enumeration and various utility functions. ...
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
bool isReferenceType() const
The iterator over UnresolvedSets.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Represents the result of substituting a set of types for a template type parameter pack...
static NonTypeTemplateParmDecl * getDeducedParameterFromExpr(TemplateDeductionInfo &Info, Expr *E)
If the given expression is of a form that permits the deduction of a non-type template parameter...
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(TemplateParameterList *P, TemplateDecl *AArg, SourceLocation Loc)
Within template argument deduction from overload resolution per C++ [over.over] allow matching functi...
QualType getParamTypeForDecl() const
ArrayRef< ParmVarDecl * > parameters() const
Within template argument deduction from a function call, we are matching with a parameter type for wh...
Describes an C or C++ initializer list.
void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, SourceLocation Loc)
Adjust the calling convention of a method to be the ABI default if it wasn't specified explicitly...
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
bool isCompleteType(SourceLocation Loc, QualType T)
An rvalue reference type, per C++11 [dcl.ref].
void setNameLoc(SourceLocation Loc)
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
bool HasFormOfMemberPointer
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
A convenient class for passing around template argument information.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
bool hasAddressSpace() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, sema::TemplateDeductionInfo &Info)
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
unsigned toTargetAddressSpace(LangAS AS)
bool IsFunctionConversion(QualType FromType, QualType ToType, QualType &ResultTy)
Determine whether the conversion from FromType to ToType is a valid conversion that strips "noexcept"...
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
Qualifiers getTypeQuals() const
FunctionDecl * resolveAddressOfOnlyViableOverloadCandidate(Expr *E, DeclAccessPair &FoundResult)
Given an expression that refers to an overloaded function, try to resolve that function to a single f...
Expr * getSizeExpr() const
TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType, SourceLocation Loc)
Allocate a TemplateArgumentLoc where all locations have been initialized to the given location...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
QualType getElementType() const
RAII object used to change the argument pack substitution index within a Sema object.
Represents an extended vector type where either the type or size is dependent.
This object can be modified without requiring retains or releases.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
A helper class for building up ExtParameterInfos.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
static bool diagnoseAutoDeductionFailure(Sema &S, Sema::TemplateDeductionResult TDK, TemplateDeductionInfo &Info, ArrayRef< SourceRange > Ranges)
Attempt to produce an informative diagostic explaining why auto deduction failed. ...
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Expr * getAddrSpaceExpr() const
Provides definitions for the various language-specific address spaces.
static Sema::TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, const TemplateArgument &Param, TemplateArgument Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
Sema - This implements semantic analysis and AST building for C.
static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc, FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1)
Determine whether the function template FT1 is at least as specialized as FT2.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, SmallVectorImpl< TemplateArgument > &Converted, CheckTemplateArgumentKind CTAK=CTAK_Specified)
Check that the given template argument corresponds to the given template parameter.
Represents a prototype with parameter type info, e.g.
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
void reset(TemplateArgumentList *NewDeduced)
Provide a new template argument list that contains the results of template argument deduction...
bool isStdInitializerList(QualType Ty, QualType *Element)
Tests whether Ty is an instance of std::initializer_list and, if it is and Element is not NULL...
std::pair< unsigned, unsigned > getDepthAndIndex(NamedDecl *ND)
Retrieve the depth and index of a template parameter.
static bool hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate, QualType T)
Template argument deduction did not deduce a value for every template parameter.
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
bool hasQualifiers() const
Determine whether this type has any qualifiers.
ConstantExpr - An expression that occurs in a constant context.
static Sema::TemplateDeductionResult DeduceFromInitializerList(Sema &S, TemplateParameterList *TemplateParams, QualType AdjustedParamType, InitListExpr *ILE, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, unsigned ArgIdx, unsigned TDF)
Attempt template argument deduction from an initializer list deemed to be an argument in a function c...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
static bool isSimpleTemplateIdType(QualType T)
Determine whether the given type T is a simple-template-id type.
void setExplicitArgs(TemplateArgumentList *NewDeduced)
Provide an initial template argument list that contains the explicitly-specified arguments.
Represents an array type in C++ whose size is a value-dependent expression.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
static Sema::TemplateDeductionResult DeduceNullPtrTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, QualType NullPtrType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter from the given null pointer template argume...
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
unsigned getNumArgs() const
Retrieve the number of template arguments.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Defines the clang::LangOptions interface.
QualType getPointeeType() const
SourceLocation getLocation() const
Returns the location at which template argument is occurring.
DeducedPack(unsigned Index)
static Sema::TemplateDeductionResult DeduceNonTypeTemplateArgument(Sema &S, TemplateParameterList *TemplateParams, NonTypeTemplateParmDecl *NTTP, const DeducedTemplateArgument &NewDeduced, QualType ValueType, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced)
Deduce the value of the given non-type template parameter as the given deduced template argument...
Declaration of a template type parameter.
unsigned getIndex() const
static DeclContext * getAsDeclContextOrEnclosing(Decl *D)
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch(Sema &S, TemplateParameterList *TemplateParams, QualType Param, QualType Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, unsigned TDF, bool PartialOrdering=false, bool DeducedFromArrayBound=false)
Deduce the template arguments by comparing the parameter type and the argument type (C++ [temp...
static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex, QualType ParamType, Expr *Arg, TemplateDeductionInfo &Info, SmallVectorImpl< DeducedTemplateArgument > &Deduced, SmallVectorImpl< Sema::OriginalCallArg > &OriginalCallArgs, bool DecomposedParam, unsigned ArgIdx, unsigned TDF)
Perform template argument deduction per [temp.deduct.call] for a single parameter / argument pair...
unsigned NumTemplateArgs
The number of template arguments in TemplateArgs.
const T * castAs() const
Member-template castAs<specific type>.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
static bool ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param, DeducedTemplateArgument Arg, NamedDecl *Template, TemplateDeductionInfo &Info, bool IsDeduced, SmallVectorImpl< TemplateArgument > &Output)
Convert the given deduced template argument and add it to the set of fully-converted template argumen...
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...
Qualifiers getTypeQualifiers() const
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
Whether this function prototype has a trailing return type.
RecordDecl * getDecl() const
static unsigned getPackIndexForParam(Sema &S, FunctionTemplateDecl *FunctionTemplate, const MultiLevelTemplateArgumentList &Args, unsigned ParamIdx)
Find the pack index for a particular parameter index in an instantiation of a function template with ...
SmallVector< DeducedPack *, 8 > PendingDeducedPacks
Information on packs that we're currently expanding.
There is no lifetime qualification on this type.
Assigning into this object requires the old value to be released and the new value to be retained...
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr...
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
A stack object to be created when performing template instantiation.
Stores a list of template parameters and the associated requires-clause (if any) for a TemplateDecl a...
ExtProtoInfo getExtProtoInfo() const
bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, TemplateArgumentListInfo &Result, const MultiLevelTemplateArgumentList &TemplateArgs)
The template argument was deduced from an array bound via template argument deduction.
SourceLocation getNameLoc() const
Gets the location of the name.
const ExtParameterInfo * ExtParameterInfos
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static TemplateParameter makeTemplateParameter(Decl *D)
Helper function to build a TemplateParameter when we don't know its type statically.
QualType getReturnType() const
bool hasSameTemplateName(TemplateName X, TemplateName Y)
Determine whether the given template names refer to the same template.
LangAS getAddressSpace() const
Return the address space of this type.
Template argument deduction failed due to inconsistent cv-qualifiers on a template parameter type tha...
TemplateArgument getArgumentPack() const
static bool isSameTemplate(TemplateDecl *T1, TemplateDecl *T2)
Determine if the two templates are equivalent.
QualType getElementType() const
static QualType getUnderlyingType(const SubRegion *R)
Template argument deduction did not deduce a value for every expansion of an expanded template parame...
Within template argument deduction from a function call, we are matching in a case where we ignore cv...
Represents a static or instance method of a struct/union/class.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
const ParmVarDecl * getParamDecl(unsigned i) const
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init)
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
const TemplateTypeParmType * getReplacedParameter() const
Gets the template parameter that was substituted for.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
TemplateDeductionResult DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, const TemplateArgumentList &TemplateArgs, sema::TemplateDeductionInfo &Info)
Perform template argument deduction to determine whether the given template arguments match the given...
Qualifiers withoutObjCLifetime() const
TypeSourceInfo * SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
bool isMemberFunctionPointerType() const
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
static unsigned getFirstInnerIndex(FunctionTemplateDecl *FTD)
Get the index of the first template parameter that was originally from the innermost template-paramet...
Within template argument deduction from a function call, we are matching in a case where we can perfo...
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
static bool isSameDeclaration(Decl *X, Decl *Y)
Determine whether two declaration pointers refer to the same declaration.
AutoTypeKeyword getKeyword() const
TypeClass getTypeClass() const
unsigned getMinRequiredArguments() const
Returns the minimum number of arguments needed to call this function.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
SourceLocation getRAngleLoc() const
bool isTargetAddressSpace(LangAS AS)
unsigned getDeducedDepth() const
The depth of template parameters for which deduction is being performed.
diag_iterator diag_end() const
Returns an iterator at the end of the sequence of suppressed diagnostics.
An rvalue ref-qualifier was provided (&&).
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
static bool hasPackExpansionBeforeEnd(ArrayRef< TemplateArgument > Args)
Determine whether the given set of template arguments has a pack expansion that is not the last templ...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getArrayDecayedType(QualType T) const
Return the properly qualified result of decaying the specified array type to a pointer.
The injected class name of a C++ class template or class template partial specialization.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
QualType getPointeeType() const
Represents a pack expansion of types.
FunctionTemplateDecl * getMoreSpecializedTemplate(FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, unsigned NumCallArguments2)
Returns the more specialized function template according to the rules of function template partial or...
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
const TemplateArgumentLoc * getTemplateArgs() const
Retrieve the template arguments.
static QualType GetTypeOfFunction(Sema &S, const OverloadExpr::FindResult &R, FunctionDecl *Fn)
Gets the type of a function for template-argument-deducton purposes when it's considered as part of a...
static std::enable_if< IsPartialSpecialization< T >::value, Sema::TemplateDeductionResult >::type FinishTemplateArgumentDeduction(Sema &S, T *Partial, bool IsPartialOrdering, const TemplateArgumentList &TemplateArgs, SmallVectorImpl< DeducedTemplateArgument > &Deduced, TemplateDeductionInfo &Info)
Complete template argument deduction for a partial specialization.
Represents a template argument.
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument. ...
Represents a template name that was expressed as a qualified name.
Dataflow Directional Tag Classes.
void getInjectedTemplateArgs(const TemplateParameterList *Params, SmallVectorImpl< TemplateArgument > &Args)
Get a template argument list with one argument per template parameter in a template parameter list...
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
const TemplateArgument & getArgument() const
NestedNameSpecifier * getQualifier() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static QualType ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams, Expr *Arg, QualType ParamType, bool ParamWasReference)
Apply the deduction rules for overload sets.
The base class of all kinds of template declarations (e.g., class, function, etc.).
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_RValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
QualType getType() const
Get the type for which this source info wrapper provides information.
The template argument is a pack expansion of a template name that was provided for a template templat...
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 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