Lines Matching +full:ovl +full:- +full:2 +full:l

1 //===--- SemaOverload.cpp - C++ Overloading -------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
60 return llvm::any_of(FD->parameters(), [](const ParmVarDecl *P) {
61 return P->hasAttr<PassObjectSizeAttr>();
81 DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo);
83 DRE->setHadMultipleCandidates(true);
86 if (auto *FPT = DRE->getType()->getAs<FunctionProtoType>()) {
87 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) {
89 DRE->setType(Fn->getType());
92 return S.ImpCastExprToType(DRE, S.Context.getPointerType(DRE->getType()),
129 /// GetConversionRank - Retrieve the implicit conversion rank
159 ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
162 ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
195 /// GetImplicitConversionName - Return the name of this kind of
200 "Lvalue-to-rvalue",
201 "Array-to-pointer",
202 "Function-to-pointer",
211 "Floating-integral conversion",
213 "Pointer-to-member conversion",
215 "Compatible-types conversion",
216 "Derived-to-base conversion",
221 "Complex-real conversion",
231 "Non-decaying array conversion",
238 /// StandardConversionSequence - Set the standard conversion
257 /// getRank - Retrieve the rank of this standard conversion sequence
273 /// isPointerConversionToBool - Determines whether this conversion is
274 /// a conversion of a pointer or pointer-to-member to bool. This is
279 // array-to-pointer or function-to-pointer implicit conversions, so
282 if (getToType(1)->isBooleanType() &&
283 (getFromType()->isPointerType() ||
284 getFromType()->isMemberPointerType() ||
285 getFromType()->isObjCObjectPointerType() ||
286 getFromType()->isBlockPointerType() ||
293 /// isPointerConversionToVoidPointer - Determines whether this
304 // array-to-pointer implicit conversion, so check for its presence
309 if (Second == ICK_Pointer_Conversion && FromType->isAnyPointerType())
310 if (const PointerType* ToPtrType = ToType->getAs<PointerType>())
311 return ToPtrType->getPointeeType()->isVoidType();
324 const_cast<Expr *>(IgnoreNarrowingConversion(Ctx, EWC->getSubExpr()));
325 return ExprWithCleanups::Create(Ctx, Inner, EWC->cleanupsHaveSideEffects(),
326 EWC->getObjects());
330 switch (ICE->getCastKind()) {
339 Converted = ICE->getSubExpr();
359 /// \param IgnoreFloatToIntegralConversion If true type-narrowing conversions
375 if (auto *ET = ToType->getAs<EnumType>())
376 ToType = ET->getDecl()->getIntegerType();
381 if (FromType->isRealFloatingType())
383 if (FromType->isIntegralOrUnscopedEnumerationType())
385 // -- from a pointer type or pointer-to-member type to bool, or
388 // -- from a floating-point type to an integer type, or
390 // -- from an integer type or unscoped enumeration type to a floating-point
396 if (FromType->isRealFloatingType() && ToType->isIntegralType(Ctx)) {
398 } else if (FromType->isIntegralOrUnscopedEnumerationType() &&
399 ToType->isRealFloatingType()) {
405 // If it's value-dependent, we can't tell whether it's narrowing.
406 if (Initializer->isValueDependent())
410 Initializer->getIntegerConstantExpr(Ctx)) {
413 Result.convertFromAPInt(*IntConstantValue, IntConstantValue->isSigned(),
423 ConstantType = Initializer->getType();
433 // -- from long double to double or float, or from double to float, except
438 if (FromType->isRealFloatingType() && ToType->isRealFloatingType() &&
443 // If it's value-dependent, we can't tell whether it's narrowing.
444 if (Initializer->isValueDependent())
448 if ((Ctx.getLangOpts().C23 && Initializer->EvaluateAsRValue(R, Ctx)) ||
449 Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)) {
472 ConstantType = Initializer->getType();
479 ConstantType = Initializer->getType();
489 // -- from an integer type or unscoped enumeration type to an integer type
496 assert(FromType->isIntegralOrUnscopedEnumerationType());
497 assert(ToType->isIntegralOrUnscopedEnumerationType());
498 const bool FromSigned = FromType->isSignedIntegerOrEnumerationType();
500 const bool ToSigned = ToType->isSignedIntegerOrEnumerationType();
509 // If it's value-dependent, we can't tell whether it's narrowing.
510 if (Initializer->isValueDependent())
514 if (!(OptInitializerValue = Initializer->getIntegerConstantExpr(Ctx))) {
521 // Negative -> unsigned is narrowing. Otherwise, more bits is never
530 // Convert the initializer to and from the target width and signed-ness.
541 ConstantType = Initializer->getType();
549 if (FromType->isComplexType() && !ToType->isComplexType())
557 if (Initializer->EvaluateAsRValue(R, Ctx)) {
566 ConstantType = Initializer->getType();
578 /// dump - Print this standard conversion sequence to standard
590 OS << " -> ";
606 OS << " -> ";
617 /// dump - Print this user-defined conversion sequence to standard
623 OS << " -> ";
630 OS << " -> ";
635 /// dump - Print this implicit conversion sequence to standard
647 OS << "User-defined conversion: ";
706 /// to the form used in overload-candidate information.
733 Saved->FirstArg = Info.FirstArg;
734 Saved->SecondArg = Info.SecondArg;
735 Saved->TemplateArgs = Info.takeSugared();
736 Saved->CallArgIndex = Info.CallArgIndex;
744 Saved->FirstArg = Info.FirstArg;
745 Saved->SecondArg = Info.SecondArg;
756 Saved->Param = Info.Param;
757 Saved->FirstArg = Info.FirstArg;
758 Saved->SecondArg = Info.SecondArg;
775 Saved->TemplateArgs = Info.takeSugared();
776 Saved->Satisfaction = Info.AssociatedConstraintsSatisfaction;
817 Diag->~PartialDiagnosticAt();
826 Diag->~PartialDiagnosticAt();
867 return static_cast<DFIParamWithArguments*>(Data)->Param;
897 return static_cast<DFIDeducedMismatchArgs*>(Data)->TemplateArgs;
903 return static_cast<CNSInfo*>(Data)->TemplateArgs;
935 return &static_cast<DFIArguments*>(Data)->FirstArg;
967 return &static_cast<DFIArguments*>(Data)->SecondArg;
982 return static_cast<DFIDeducedMismatchArgs*>(Data)->CallArgIndex;
993 if (X->getNumParams() != Y->getNumParams())
998 for (unsigned I = 0; I < X->getNumParams(); ++I)
999 if (!Ctx.hasSameUnqualifiedType(X->getParamDecl(I)->getType(),
1000 Y->getParamDecl(I)->getType()))
1002 if (auto *FTX = X->getDescribedFunctionTemplate()) {
1003 auto *FTY = Y->getDescribedFunctionTemplate();
1006 if (!Ctx.isSameTemplateParameterList(FTX->getTemplateParameters(),
1007 FTY->getTemplateParameters()))
1015 assert(EqFD->getOverloadedOperator() ==
1017 // C++2a [over.match.oper]p4:
1018 // A non-template function or function template F named operator== is a
1031 QualType RHS = FirstOperand->getType();
1032 auto *RHSRec = RHS->getAs<RecordType>();
1037 S.LookupQualifiedName(Members, RHSRec->getDecl());
1040 if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
1045 for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
1046 auto *NotEqFD = Op->getAsFunction();
1048 NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
1050 declaresSameEntity(cast<Decl>(EqFD->getEnclosingNamespaceContext()),
1051 cast<Decl>(Op->getLexicalDeclContext())))
1066 auto Op = FD->getOverloadedOperator();
1070 assert(OriginalArgs.size() == 2);
1076 // match than the non-reversed version.
1077 return FD->getNumNonObjectParams() != 2 ||
1078 !S.Context.hasSameUnqualifiedType(FD->getParamDecl(0)->getType(),
1079 FD->getParamDecl(1)->getType()) ||
1080 FD->hasAttr<EnableIfAttr>();
1085 for (auto &C : i->Conversions)
1087 if (!i->Viable && i->FailureKind == ovl_fail_bad_deduction)
1088 i->DeductionFailure.Destroy();
1107 SmallVector<Entry, 2> Entries;
1111 assert(E->hasPlaceholderType(BuiltinType::ARCUnbridgedCast));
1120 *i->Addr = i->Saved;
1125 /// checkPlaceholderForOverload - Do any interesting placeholder-like
1135 if (const BuiltinType *placeholder = E->getType()->getAsPlaceholderType()) {
1138 if (placeholder->getKind() == BuiltinType::Overload) return false;
1142 if (placeholder->getKind() == BuiltinType::ARCUnbridgedCast &&
1144 unbridgedCasts->save(S, E);
1161 /// checkArgPlaceholdersForOverload - Check a set of call operands for
1187 OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl();
1190 // A using-declaration does not conflict with another declaration
1201 (OldIsUsingDecl || NewIsUsingDecl) && CurContext->isRecord() &&
1202 !New->getFriendObjectKind();
1204 if (FunctionDecl *OldF = OldD->getAsFunction()) {
1238 if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) {
1253 // -- if the name of the friend is a qualified or unqualified template-id,
1255 // -- if the name of the friend is a qualified-id and a matching
1256 // non-template function is found in the specified class or namespace,
1258 // -- if the name of the friend is a qualified-id and a matching function
1262 // -- the name shall be an unqualified-id [...]
1266 if (New->getFriendObjectKind() && New->getQualifier() &&
1267 !New->getDescribedFunctionTemplate() &&
1268 !New->getDependentSpecializationInfo() &&
1269 !New->getType()->isDependentType()) {
1274 New->setInvalidDecl();
1291 if (New->isMain())
1295 if (New->isMSVCRTEntryPoint())
1300 FunctionTemplateDecl *OldTemplate = Old->getDescribedFunctionTemplate();
1301 FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate();
1305 // and with normal (non-template) functions.
1310 QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
1311 QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
1317 // If either of these functions is a K&R-style function (no
1329 if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
1332 // For member-like friends, the enclosing class is part of the signature.
1333 if ((New->isMemberLikeConstrainedFriend() ||
1334 Old->isMemberLikeConstrainedFriend()) &&
1335 !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
1341 // references to non-instantiated entities during constraint substitution.
1356 NewTemplate, NewTemplate->getTemplateParameters(), OldTemplate,
1357 OldTemplate->getTemplateParameters(), false, Sema::TPL_TemplateMatch);
1359 Old->getDeclaredReturnType(), New->getDeclaredReturnType());
1360 // FIXME(GH58571): Match template parameter list even for non-constrained
1364 NewTemplate->getTemplateParameters()->hasAssociatedConstraints() ||
1365 OldTemplate->getTemplateParameters()->hasAssociatedConstraints();
1367 // The set of declarations named by a using-declarator that inhabits a
1392 if (M->isExplicitObjectMemberFunction())
1400 // or non-static member function). Add it now, on the assumption that this
1403 (M->isConstexpr() || M->isConsteval()) &&
1419 if (OldMethod->isImplicitObjectMemberFunction() &&
1420 OldMethod->getParent() != NewMethod->getParent()) {
1422 SemaRef.Context.getTypeDeclType(OldMethod->getParent())
1433 if (Base->isLValueReferenceType())
1434 return D->isLValueReferenceType();
1435 return Base->isRValueReferenceType() == D->isRValueReferenceType();
1439 // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
1443 if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
1445 if (OldMethod->isExplicitObjectMemberFunction() ||
1446 NewMethod->isExplicitObjectMemberFunction())
1448 if (!UseMemberUsingDeclRules && (OldMethod->getRefQualifier() == RQ_None ||
1449 NewMethod->getRefQualifier() == RQ_None)) {
1450 SemaRef.Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
1451 << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
1452 SemaRef.Diag(OldMethod->getLocation(), diag::note_previous_declaration);
1458 if (OldMethod && OldMethod->isExplicitObjectMemberFunction())
1460 if (NewMethod && NewMethod->isExplicitObjectMemberFunction())
1463 if (OldType->getNumParams() - OldParamsOffset !=
1464 NewType->getNumParams() - NewParamsOffset ||
1466 {OldType->param_type_begin() + OldParamsOffset,
1467 OldType->param_type_end()},
1468 {NewType->param_type_begin() + NewParamsOffset,
1469 NewType->param_type_end()},
1474 if (OldMethod && NewMethod && !OldMethod->isStatic() &&
1475 !NewMethod->isStatic()) {
1478 auto NewObjectType = New->getFunctionObjectParameterReferenceType();
1479 auto OldObjectType = Old->getFunctionObjectParameterReferenceType();
1482 return F->getRefQualifier() == RQ_None &&
1483 !F->isExplicitObjectMemberFunction();
1499 if (!UseOverrideRules || (!NewMethod->isExplicitObjectMemberFunction() &&
1500 !OldMethod->isExplicitObjectMemberFunction()))
1506 New->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) {
1507 Expr *NewRC = New->getTrailingRequiresClause(),
1508 *OldRC = Old->getTrailingRequiresClause();
1516 if (NewMethod && OldMethod && OldMethod->isImplicitObjectMemberFunction() &&
1517 NewMethod->isImplicitObjectMemberFunction()) {
1523 // consider it to be a function-level modifier for the sake of function
1530 // enable_if attributes are an order-sensitive part of the signature.
1532 NewI = New->specific_attr_begin<EnableIfAttr>(),
1533 NewE = New->specific_attr_end<EnableIfAttr>(),
1534 OldI = Old->specific_attr_begin<EnableIfAttr>(),
1535 OldE = Old->specific_attr_end<EnableIfAttr>();
1540 NewI->getCond()->Profile(NewID, SemaRef.Context, true);
1541 OldI->getCond()->Profile(OldID, SemaRef.Context, true);
1582 /// Tries a user-defined conversion from From to ToType.
1603 // Attempt user-defined conversion.
1604 OverloadCandidateSet Conversions(From->getExprLoc(),
1617 // constructor (i.e., a user-defined conversion function) is
1622 = S.Context.getCanonicalType(From->getType().getUnqualifiedType());
1625 if (Constructor->isCopyConstructor() &&
1627 S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) {
1633 ICS.Standard.setFromType(From->getType());
1645 ICS.Ambiguous.setFromType(From->getType());
1649 if (Cand->Best)
1650 ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function);
1662 /// TryImplicitConversion - Attempt to perform an implicit conversion
1672 /// conversion sequence containing an lvalue-to-rvalue conversion (C++
1673 /// 4.1) followed by a floating-integral conversion (C++ 4.9).
1681 /// If @p SuppressUserConversions, then user-defined conversions are
1683 /// If @p AllowExplicit, then explicit user-defined conversions are
1686 /// \param AllowObjCWritebackConversion Whether we allow the Objective-C
1714 // constructor (i.e., a user-defined conversion function) is
1716 QualType FromType = From->getType();
1717 if (ToType->getAs<RecordType>() && FromType->getAs<RecordType>() &&
1719 S.IsDerivedFrom(From->getBeginLoc(), FromType, ToType))) {
1731 // Determine whether this is considered a derived-to-base conversion.
1763 // Objective-C ARC: Determine whether we will allow the writeback conversion.
1768 ObjC().CheckObjCBridgeRelatedConversions(From->getBeginLoc(), ToType,
1769 From->getType(), From);
1785 // Permit the conversion F(t __attribute__((noreturn))) -> F(t)
1786 // or F(t noexcept) -> F(t)
1788 // - a pointer
1789 // - a member pointer
1790 // - a block pointer
1794 Type::TypeClass TyClass = CanTo->getTypeClass();
1795 if (TyClass != CanFrom->getTypeClass()) return false;
1798 CanTo = CanTo.castAs<PointerType>()->getPointeeType();
1799 CanFrom = CanFrom.castAs<PointerType>()->getPointeeType();
1801 CanTo = CanTo.castAs<BlockPointerType>()->getPointeeType();
1802 CanFrom = CanFrom.castAs<BlockPointerType>()->getPointeeType();
1807 if (ToMPT->getClass() != FromMPT->getClass())
1809 CanTo = ToMPT->getPointeeType();
1810 CanFrom = FromMPT->getPointeeType();
1815 TyClass = CanTo->getTypeClass();
1816 if (TyClass != CanFrom->getTypeClass()) return false;
1822 FunctionType::ExtInfo FromEInfo = FromFn->getExtInfo();
1825 FunctionType::ExtInfo ToEInfo = ToFn->getExtInfo();
1838 if (FromFPT->isNothrow() && !ToFPT->isNothrow()) {
1854 FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo();
1857 QualType QT = Context.getFunctionType(FromFPT->getReturnType(),
1858 FromFPT->getParamTypes(), ExtInfo);
1859 FromFn = QT->getAs<FunctionType>();
1872 const auto FromFX = FromFPT->getFunctionEffects();
1873 const auto ToFX = ToFPT->getFunctionEffects();
1875 FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo();
1878 FromFPT->getReturnType(), FromFPT->getParamTypes(), ExtInfo);
1879 FromFn = QT->getAs<FunctionType>();
1900 if (!FromType->isRealFloatingType() || !ToType->isRealFloatingType())
1907 if ((FromType->isBFloat16Type() &&
1908 (ToType->isFloat16Type() || ToType->isHalfType())) ||
1909 (ToType->isBFloat16Type() &&
1910 (FromType->isFloat16Type() || FromType->isHalfType())))
1913 // Conversions between IEEE-quad and IBM-extended semantics are not
1941 if (ToType->isBooleanType() && FromType->isArithmeticType()) {
1946 if ((FromType->isRealFloatingType() && ToType->isIntegralType(S.Context)) ||
1947 (FromType->isIntegralOrUnscopedEnumerationType() &&
1948 ToType->isRealFloatingType())) {
1958 if (FromType->isIntegralOrUnscopedEnumerationType() &&
1959 ToType->isIntegralType(S.Context)) {
1978 if (!ToType->isVectorType() && !FromType->isVectorType())
1986 if (auto *ToExtType = ToType->getAs<ExtVectorType>()) {
1987 if (auto *FromExtType = FromType->getAs<ExtVectorType>()) {
1990 unsigned FromElts = FromExtType->getNumElements();
1991 unsigned ToElts = ToExtType->getNumElements();
1999 QualType FromElTy = FromExtType->getElementType();
2000 QualType ToElTy = ToExtType->getElementType();
2011 if (FromType->isArithmeticType()) {
2014 QualType ToElTy = ToExtType->getElementType();
2022 if (ToType->isSVESizelessBuiltinType() ||
2023 FromType->isSVESizelessBuiltinType())
2030 if (ToType->isRVVSizelessBuiltinType() ||
2031 FromType->isRVVSizelessBuiltinType())
2040 // 2)lax vector conversions are permitted and the vector types are of the
2042 // 3)the destination type does not have the ARM MVE strict-polymorphism
2045 if (ToType->isVectorType() && FromType->isVectorType()) {
2048 !ToType->hasAttr(attr::ArmMveStrictPolymorphism))) {
2054 S.Diag(From->getBeginLoc(), diag::warn_deprecated_lax_vec_conv_all)
2070 /// IsStandardConversion - Determines whether there is a standard
2073 /// only consider non-class types; for conversions that involve class
2083 QualType FromType = From->getType();
2094 (FromType->isRecordType() || ToType->isRecordType()))
2097 // The first conversion can be an lvalue-to-rvalue conversion,
2098 // array-to-pointer conversion, or function-to-pointer conversion
2108 FromType = Fn->getType();
2120 if (!ToType->isBooleanType())
2126 // fact that non-static member functions *must* have such an address-of
2129 if (Method && !Method->isStatic() &&
2130 !Method->isExplicitObjectMemberFunction()) {
2131 assert(isa<UnaryOperator>(From->IgnoreParens()) &&
2132 "Non-unary operator on non-static member address");
2133 assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode()
2135 "Non-address-of operator on non-static member address");
2137 = S.Context.getTypeDeclType(Method->getParent()).getTypePtr();
2139 } else if (isa<UnaryOperator>(From->IgnoreParens())) {
2140 assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode() ==
2142 "Non-address-of operator for overloaded function expression");
2149 // Lvalue-to-rvalue conversion (C++11 4.1):
2150 // A glvalue (3.10) of a non-function, non-array type T can
2152 bool argIsLValue = From->isGLValue();
2153 if (argIsLValue && !FromType->canDecayToPointerType() &&
2158 // ... if the lvalue has atomic type, the value has the non-atomic version
2160 if (const AtomicType *Atomic = FromType->getAs<AtomicType>())
2161 FromType = Atomic->getValueType();
2163 // If T is a non-class type, the type of the rvalue is the
2164 // cv-unqualified version of T. Otherwise, the type of the rvalue
2168 } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() &&
2169 ToType->isArrayParameterType()) {
2181 } else if (FromType->isArrayType()) {
2182 // Array-to-pointer conversion (C++ 4.2)
2196 // array-to-pointer conversion followed by a qualification
2204 } else if (FromType->isFunctionType() && argIsLValue) {
2205 // Function-to-pointer conversion (C++ 4.3).
2208 if (auto *DRE = dyn_cast<DeclRefExpr>(From->IgnoreParenCasts()))
2209 if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
2225 // floating-integral conversion, pointer conversion,
2226 // pointer-to-member conversion, or boolean conversion (C++ 4p1).
2227 // For overloading in C, this can also be a "compatible-type"
2248 } else if (ToType->isBooleanType() &&
2249 (FromType->isArithmeticType() ||
2250 FromType->isAnyPointerType() ||
2251 FromType->isBlockPointerType() ||
2252 FromType->isMemberPointerType())) {
2256 } else if (FromType->isIntegralOrUnscopedEnumerationType() &&
2257 ToType->isIntegralType(S.Context)) {
2261 } else if (FromType->isAnyComplexType() && ToType->isAnyComplexType()) {
2265 } else if ((FromType->isAnyComplexType() && ToType->isArithmeticType()) ||
2266 (ToType->isAnyComplexType() && FromType->isArithmeticType())) {
2267 // Complex-real conversions (C99 6.3.1.7)
2274 } else if ((FromType->isRealFloatingType() &&
2275 ToType->isIntegralType(S.Context)) ||
2276 (FromType->isIntegralOrUnscopedEnumerationType() &&
2277 ToType->isRealFloatingType())) {
2279 // Floating-integral conversions (C++ 4.9).
2316 } else if (ToType->isEventT() &&
2317 From->isIntegerConstantExpr(S.getASTContext()) &&
2318 From->EvaluateKnownConstInt(S.getASTContext()) == 0) {
2321 } else if (ToType->isQueueT() &&
2322 From->isIntegerConstantExpr(S.getASTContext()) &&
2323 (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) {
2326 } else if (ToType->isSamplerT() &&
2327 From->isIntegerConstantExpr(S.getASTContext())) {
2330 } else if ((ToType->isFixedPointType() &&
2331 FromType->isConvertibleToFixedPointType()) ||
2332 (FromType->isFixedPointType() &&
2333 ToType->isConvertibleToFixedPointType())) {
2360 // [...] Any difference in top-level cv-qualification is
2372 SCS.setToType(2, FromType);
2416 SCS.setToType(2, ToType);
2427 const RecordType *UT = ToType->getAsUnionType();
2428 if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>())
2431 RecordDecl *UD = UT->getDecl();
2433 for (const auto *it : UD->fields()) {
2434 if (IsStandardConversion(S, From, it->getType(), InOverloadResolution, SCS,
2436 ToType = it->getType();
2444 const BuiltinType *To = ToType->getAs<BuiltinType>();
2445 // All integers are built-in.
2455 if (Context.isPromotableIntegerType(FromType) && !FromType->isBooleanType() &&
2456 !FromType->isEnumeralType()) {
2458 (FromType->isSignedIntegerType() ||
2462 return To->getKind() == BuiltinType::Int;
2465 return To->getKind() == BuiltinType::UInt;
2486 if (const EnumType *FromEnumType = FromType->getAs<EnumType>()) {
2489 if (FromEnumType->getDecl()->isScoped())
2495 // the bitfield-ness of the actual source expression.
2496 if (FromEnumType->getDecl()->isFixed()) {
2497 QualType Underlying = FromEnumType->getDecl()->getIntegerType();
2502 // We have already pre-calculated the promotion type, so this is trivial.
2503 if (ToType->isIntegerType() &&
2504 isCompleteType(From->getBeginLoc(), FromType))
2506 ToType, FromEnumType->getDecl()->getPromotionType());
2509 // If the bit-field has an enumerated type, it is treated as any other
2512 // ... so do not fall through into the bit-field checks below in C++.
2526 if (FromType->isAnyCharacterType() && !FromType->isCharType() &&
2527 ToType->isIntegerType()) {
2530 bool FromIsSigned = FromType->isSignedIntegerType();
2544 FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) {
2553 // An rvalue for an integral bit-field (9.6) can be converted to an
2555 // bit-field; otherwise, it can be converted to unsigned int if
2556 // unsigned int can represent all the values of the bit-field. If
2557 // the bit-field is larger yet, no integral promotion applies to
2558 // it. If the bit-field has an enumerated type, it is treated as any
2560 // FIXME: We should delay checking of bit-fields until we actually perform the
2563 // FIXME: In C, only bit-fields of types _Bool, int, or unsigned int may be
2564 // promoted, per C11 6.3.1.1/2. We promote all bit-fields (including enum
2565 // bit-fields and those whose underlying type is larger than int) for GCC
2568 if (FieldDecl *MemberDecl = From->getSourceBitField()) {
2570 if (FromType->isIntegralType(Context) &&
2572 MemberDecl->getBitWidth()->getIntegerConstantExpr(Context))) {
2573 llvm::APSInt ToSize(BitWidth->getBitWidth(), BitWidth->isUnsigned());
2578 (FromType->isSignedIntegerType() && *BitWidth <= ToSize)) {
2579 return To->getKind() == BuiltinType::Int;
2584 if (FromType->isUnsignedIntegerType() && *BitWidth <= ToSize) {
2585 return To->getKind() == BuiltinType::UInt;
2595 if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) {
2601 if (Context.getLangOpts().HLSL && FromType->isIntegerType() &&
2602 ToType->isIntegerType())
2609 if (const BuiltinType *FromBuiltin = FromType->getAs<BuiltinType>())
2610 if (const BuiltinType *ToBuiltin = ToType->getAs<BuiltinType>()) {
2613 if (FromBuiltin->getKind() == BuiltinType::Float &&
2614 ToBuiltin->getKind() == BuiltinType::Double)
2621 (FromBuiltin->getKind() == BuiltinType::Float ||
2622 FromBuiltin->getKind() == BuiltinType::Double) &&
2623 (ToBuiltin->getKind() == BuiltinType::LongDouble ||
2624 ToBuiltin->getKind() == BuiltinType::Float128 ||
2625 ToBuiltin->getKind() == BuiltinType::Ibm128))
2630 if (getLangOpts().HLSL && FromBuiltin->getKind() == BuiltinType::Half &&
2631 (ToBuiltin->getKind() == BuiltinType::Float ||
2632 ToBuiltin->getKind() == BuiltinType::Double))
2637 FromBuiltin->getKind() == BuiltinType::Half &&
2638 ToBuiltin->getKind() == BuiltinType::Float)
2646 const ComplexType *FromComplex = FromType->getAs<ComplexType>();
2650 const ComplexType *ToComplex = ToType->getAs<ComplexType>();
2654 return IsFloatingPointPromotion(FromComplex->getElementType(),
2655 ToComplex->getElementType()) ||
2656 IsIntegralPromotion(nullptr, FromComplex->getElementType(),
2657 ToComplex->getElementType());
2660 /// BuildSimilarlyQualifiedPointerType - In a pointer conversion from
2663 /// if non-empty, will be a pointer to ToType that may or may not have
2671 assert((FromPtr->getTypeClass() == Type::Pointer ||
2672 FromPtr->getTypeClass() == Type::ObjCObjectPointer) &&
2673 "Invalid similarly-qualified pointer type");
2675 /// Conversions to 'id' subsume cv-qualifier conversions.
2676 if (ToType->isObjCIdType() || ToType->isObjCQualifiedIdType())
2680 = Context.getCanonicalType(FromPtr->getPointeeType());
2687 // Exact qualifier match -> return the pointer type we're converting to.
2712 // Handle value-dependent integral null pointer constants correctly.
2713 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
2714 if (Expr->isValueDependent() && !Expr->isTypeDependent() &&
2715 Expr->getType()->isIntegerType() && !Expr->getType()->isEnumeralType())
2718 return Expr->isNullPointerConstant(Context,
2732 // Conversion from a null pointer constant to any Objective-C pointer type.
2733 if (ToType->isObjCObjectPointerType() &&
2740 if (FromType->isBlockPointerType() && ToType->isPointerType() &&
2741 ToType->castAs<PointerType>()->getPointeeType()->isVoidType()) {
2747 if (ToType->isBlockPointerType() &&
2753 // If the left-hand-side is nullptr_t, the right side can be a null
2755 if (ToType->isNullPtrType() &&
2761 const PointerType* ToTypePtr = ToType->getAs<PointerType>();
2772 // , including objective-c pointers.
2773 QualType ToPointeeType = ToTypePtr->getPointeeType();
2774 if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType() &&
2777 FromType->castAs<ObjCObjectPointerType>(), ToPointeeType, ToType,
2781 const PointerType *FromTypePtr = FromType->getAs<PointerType>();
2785 QualType FromPointeeType = FromTypePtr->getPointeeType();
2795 if (FromPointeeType->isIncompleteOrObjectType() &&
2796 ToPointeeType->isVoidType()) {
2805 if (getLangOpts().MSVCCompat && FromPointeeType->isFunctionType() &&
2806 ToPointeeType->isVoidType()) {
2814 // conversion for compatible-but-not-identical pointee types.
2829 // necessitates this conversion is ill-formed. The result of the
2830 // conversion is a pointer to the base class sub-object of the
2836 if (getLangOpts().CPlusPlus && FromPointeeType->isRecordType() &&
2837 ToPointeeType->isRecordType() &&
2839 IsDerivedFrom(From->getBeginLoc(), FromPointeeType, ToPointeeType)) {
2846 if (FromPointeeType->isVectorType() && ToPointeeType->isVectorType() &&
2882 ToType->getAs<ObjCObjectPointerType>();
2884 FromType->getAs<ObjCObjectPointerType>();
2889 if (Context.hasSameUnqualifiedType(ToObjCPtr->getPointeeType(),
2890 FromObjCPtr->getPointeeType()))
2893 // Conversion between Objective-C pointers.
2895 const ObjCInterfaceType* LHS = ToObjCPtr->getInterfaceType();
2896 const ObjCInterfaceType* RHS = FromObjCPtr->getInterfaceType();
2898 !ToObjCPtr->getPointeeType().isAtLeastAsQualifiedAs(
2899 FromObjCPtr->getPointeeType()))
2902 ToObjCPtr->getPointeeType(),
2909 // Okay: this is some kind of implicit downcast of Objective-C
2914 ToObjCPtr->getPointeeType(),
2922 if (const PointerType *ToCPtr = ToType->getAs<PointerType>())
2923 ToPointeeType = ToCPtr->getPointeeType();
2925 ToType->getAs<BlockPointerType>()) {
2928 if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) {
2932 ToPointeeType = ToBlockPtr->getPointeeType();
2934 else if (FromType->getAs<BlockPointerType>() &&
2935 ToObjCPtr && ToObjCPtr->isObjCBuiltinType()) {
2945 if (const PointerType *FromCPtr = FromType->getAs<PointerType>())
2946 FromPointeeType = FromCPtr->getPointeeType();
2948 FromType->getAs<BlockPointerType>())
2949 FromPointeeType = FromBlockPtr->getPointeeType();
2954 // is an Objective-C conversion.
2955 if (FromPointeeType->isPointerType() && ToPointeeType->isPointerType() &&
2964 // Allow conversion of pointee being objective-c pointer to another one;
2966 if (FromPointeeType->getAs<ObjCObjectPointerType>() &&
2967 ToPointeeType->getAs<ObjCObjectPointerType>() &&
2977 // differences in the argument and result types are in Objective-C
2981 = FromPointeeType->getAs<FunctionProtoType>();
2983 = ToPointeeType->getAs<FunctionProtoType>();
2986 // Objective-C pointer conversion.
2993 if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() ||
2994 FromFunctionType->isVariadic() != ToFunctionType->isVariadic() ||
2995 FromFunctionType->getMethodQuals() != ToFunctionType->getMethodQuals())
2999 if (Context.getCanonicalType(FromFunctionType->getReturnType()) ==
3000 Context.getCanonicalType(ToFunctionType->getReturnType())) {
3002 } else if (isObjCPointerConversion(FromFunctionType->getReturnType(),
3003 ToFunctionType->getReturnType(),
3005 // Okay, we have an Objective-C pointer conversion.
3013 for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams();
3015 QualType FromArgType = FromFunctionType->getParamType(ArgIdx);
3016 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
3022 // Okay, we have an Objective-C pointer conversion.
3031 // We had an Objective-C conversion. Allow this pointer
3046 ToType->getAs<BlockPointerType>())
3047 ToPointeeType = ToBlockPtr->getPointeeType();
3053 FromType->getAs<BlockPointerType>())
3054 FromPointeeType = FromBlockPtr->getPointeeType();
3058 // differences in the argument and result types are in Objective-C
3062 = FromPointeeType->getAs<FunctionProtoType>();
3064 = ToPointeeType->getAs<FunctionProtoType>();
3074 if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() ||
3075 FromFunctionType->isVariadic() != ToFunctionType->isVariadic())
3078 FunctionType::ExtInfo FromEInfo = FromFunctionType->getExtInfo();
3079 FunctionType::ExtInfo ToEInfo = ToFunctionType->getExtInfo();
3084 if (Context.hasSameType(FromFunctionType->getReturnType(),
3085 ToFunctionType->getReturnType())) {
3088 QualType RHS = FromFunctionType->getReturnType();
3089 QualType LHS = ToFunctionType->getReturnType();
3090 if ((!getLangOpts().CPlusPlus || !RHS->isRecordType()) &&
3100 // Okay, we have an Objective-C pointer conversion.
3107 for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams();
3110 QualType FromArgType = FromFunctionType->getParamType(ArgIdx);
3111 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
3118 // Okay, we have an Objective-C pointer conversion.
3148 if (auto *FPT = FromType->getAs<FunctionProtoType>())
3151 if (auto *MPT = FromType->getAs<MemberPointerType>())
3152 return MPT->getPointeeType()->getAs<FunctionProtoType>();
3166 if (FromType->isMemberPointerType() && ToType->isMemberPointerType()) {
3167 const auto *FromMember = FromType->castAs<MemberPointerType>(),
3168 *ToMember = ToType->castAs<MemberPointerType>();
3169 if (!Context.hasSameType(FromMember->getClass(), ToMember->getClass())) {
3170 PDiag << ft_different_class << QualType(ToMember->getClass(), 0)
3171 << QualType(FromMember->getClass(), 0);
3174 FromType = FromMember->getPointeeType();
3175 ToType = ToMember->getPointeeType();
3178 if (FromType->isPointerType())
3179 FromType = FromType->getPointeeType();
3180 if (ToType->isPointerType())
3181 ToType = ToType->getPointeeType();
3187 // Don't print extra info for non-specialized template functions.
3188 if (FromType->isInstantiationDependentType() &&
3189 !FromType->getAs<TemplateSpecializationType>()) {
3209 if (FromFunction->getNumParams() != ToFunction->getNumParams()) {
3210 PDiag << ft_parameter_arity << ToFunction->getNumParams()
3211 << FromFunction->getNumParams();
3219 << ToFunction->getParamType(ArgPos)
3220 << FromFunction->getParamType(ArgPos);
3225 if (!Context.hasSameType(FromFunction->getReturnType(),
3226 ToFunction->getReturnType())) {
3227 PDiag << ft_return_type << ToFunction->getReturnType()
3228 << FromFunction->getReturnType();
3232 if (FromFunction->getMethodQuals() != ToFunction->getMethodQuals()) {
3233 PDiag << ft_qualifer_mismatch << ToFunction->getMethodQuals()
3234 << FromFunction->getMethodQuals();
3240 if (cast<FunctionProtoType>(FromFunction->getCanonicalTypeUnqualified())
3241 ->isNothrow() !=
3242 cast<FunctionProtoType>(ToFunction->getCanonicalTypeUnqualified())
3243 ->isNothrow()) {
3261 size_t J = Reversed ? (llvm::size(New) - Idx - 1) : Idx;
3268 Context.removePtrSizeAddrSpace((New.begin() + J)->getUnqualifiedType());
3282 return FunctionParamTypesAreEqual(OldType->param_types(),
3283 NewType->param_types(), ArgPos, Reversed);
3291 if (OldFunction->getNumNonObjectParams() !=
3292 NewFunction->getNumNonObjectParams())
3296 unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter());
3298 unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter());
3300 auto *OldPT = cast<FunctionProtoType>(OldFunction->getFunctionType());
3301 auto *NewPT = cast<FunctionProtoType>(NewFunction->getFunctionType());
3303 return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore),
3304 NewPT->param_types().slice(NewIgnore),
3313 QualType FromType = From->getType();
3318 if (Diagnose && !IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() &&
3319 From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
3321 if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy))
3322 DiagRuntimeBehavior(From->getExprLoc(), From,
3324 << ToType << From->getSourceRange());
3326 Diag(From->getExprLoc(), diag::warn_non_literal_null_pointer)
3327 << ToType << From->getSourceRange();
3329 if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) {
3330 if (const PointerType *FromPtrType = FromType->getAs<PointerType>()) {
3331 QualType FromPointeeType = FromPtrType->getPointeeType(),
3332 ToPointeeType = ToPtrType->getPointeeType();
3334 if (FromPointeeType->isRecordType() && ToPointeeType->isRecordType() &&
3336 // We must have a derived-to-base conversion. Check an
3346 From->getExprLoc(), From->getSourceRange(), DeclarationName(),
3355 FromPointeeType->isFunctionType() && ToPointeeType->isVoidType()) {
3358 Diag(From->getExprLoc(), diag::ext_ms_impcast_fn_obj)
3359 << From->getSourceRange();
3363 ToType->getAs<ObjCObjectPointerType>()) {
3365 FromType->getAs<ObjCObjectPointerType>()) {
3366 // Objective-C++ conversions are always okay.
3368 // Objective-C++ implicit conversions.
3369 if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType())
3371 } else if (FromType->isBlockPointerType()) {
3376 } else if (ToType->isBlockPointerType()) {
3377 if (!FromType->isBlockPointerType())
3383 if (From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull))
3393 const MemberPointerType *ToTypePtr = ToType->getAs<MemberPointerType>();
3398 if (From->isNullPointerConstant(Context,
3406 const MemberPointerType *FromTypePtr = FromType->getAs<MemberPointerType>();
3412 QualType FromClass(FromTypePtr->getClass(), 0);
3413 QualType ToClass(ToTypePtr->getClass(), 0);
3416 IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass)) {
3417 ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(),
3429 QualType FromType = From->getType();
3430 const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>();
3433 assert(From->isNullPointerConstant(Context,
3440 const MemberPointerType *ToPtrType = ToType->getAs<MemberPointerType>();
3444 QualType FromClass = QualType(FromPtrType->getClass(), 0);
3445 QualType ToClass = QualType(ToPtrType->getClass(), 0);
3448 assert(FromClass->isRecordType() && "Pointer into non-class.");
3449 assert(ToClass->isRecordType() && "Pointer into non-class.");
3454 IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass, Paths);
3462 Diag(From->getExprLoc(), diag::err_ambiguous_memptr_conv)
3463 << 0 << FromClass << ToClass << PathDisplayStr << From->getSourceRange();
3468 Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual)
3470 << From->getSourceRange();
3475 CheckBaseClassAccess(From->getExprLoc(), FromClass, ToClass,
3502 /// outer layer is const-qualified.
3513 // Objective-C ARC:
3514 // Check Objective-C lifetime conversions.
3523 // Objective-C lifetime qualifiers.
3535 // -- for every j > 0, if const is in cv 1,j then const is in cv
3536 // 2,j, and similarly for volatile.
3541 // - in top level it is only valid to convert to addr space that is a
3542 // superset in all cases apart from C-style casts where we allow
3544 // - in non-top levels it is not a valid conversion.
3551 // -- if the cv 1,j and cv 2,j are different, then const is in
3559 // -- if [...] P1,i [...] is "array of unknown bound of", P3,i is
3561 if (FromType->isIncompleteArrayType() && !ToType->isIncompleteArrayType())
3564 // -- if the resulting P3,i is different from P1,i [...], then const is
3566 if (!CStyle && FromType->isConstantArrayType() &&
3567 ToType->isIncompleteArrayType() && !PreviousToQualsIncludeConst)
3570 // Keep track of whether all prior cv-qualifiers in the "to" type
3590 // A conversion can add cv-qualifiers at levels other than the first
3591 // in multi-level pointers, subject to the following rules: [...]
3610 /// - Determine whether this is a conversion from a scalar type to an
3619 const AtomicType *ToAtomic = ToType->getAs<AtomicType>();
3624 if (!IsStandardConversion(S, From, ToAtomic->getValueType(),
3634 SCS.setToType(2, InnerSCS.getToType(2));
3641 const auto *CtorType = Constructor->getType()->castAs<FunctionProtoType>();
3642 if (CtorType->getNumParams() > 0) {
3643 QualType FirstArg = CtorType->getParamType(0);
3662 bool Usable = !Info.Constructor->isInvalidDecl() &&
3683 CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) {
3687 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Best->Function);
3688 QualType ThisType = Constructor->getFunctionObjectParameterType();
3693 User.FoundConversionFunction = Best->FoundDecl;
3709 /// Determines whether there is a user-defined conversion sequence
3712 /// user-defined conversion sequence that performs such a conversion
3717 /// "explicit" conversion functions as well as non-explicit conversion
3721 /// allow an extra Objective-C pointer conversion on uses of explicit
3738 if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) {
3740 // When objects of class type are direct-initialized (8.5), or
3741 // copy-initialized from an expression of the same or a
3743 // constructor. [...] For copy-initialization, the candidate
3745 // that class. The argument list is the expression-list within
3747 if (S.Context.hasSameUnqualifiedType(ToType, From->getType()) ||
3748 (From->getType()->getAs<RecordType>() &&
3749 S.IsDerivedFrom(From->getBeginLoc(), From->getType(), ToType)))
3752 if (!S.isCompleteType(From->getExprLoc(), ToType)) {
3755 = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
3761 // But first, see if there is an init-list-constructor that will work.
3771 // If we're list-initializing, we pass the individual elements as
3773 Args = InitList->getInits();
3774 NumArgs = InitList->getNumInits();
3783 bool Usable = !Info.Constructor->isInvalidDecl();
3785 Usable = Usable && Info.Constructor->isConvertingConstructor(
3794 // conversion is to X or reference to cv X, user-defined conversion
3810 // Allow one user-defined conversion when user specifies a
3811 // From->ToType conversion via an static cast (c-style, etc).
3824 } else if (!S.isCompleteType(From->getBeginLoc(), From->getType())) {
3827 From->getType()->getAs<RecordType>()) {
3829 = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) {
3831 const auto &Conversions = FromRecordDecl->getVisibleConversionFunctions();
3835 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext());
3837 D = cast<UsingShadowDecl>(D)->getTargetDecl();
3842 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
3863 CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) {
3868 = dyn_cast<CXXConstructorDecl>(Best->Function)) {
3870 // If the user-defined conversion is specified by a
3879 if (Best->Conversions[0].isEllipsis())
3882 User.Before = Best->Conversions[0].Standard;
3888 User.FoundConversionFunction = Best->FoundDecl;
3890 User.After.setFromType(Constructor->getFunctionObjectParameterType());
3895 = dyn_cast<CXXConversionDecl>(Best->Function)) {
3898 // [...] If the user-defined conversion is specified by a
3899 // conversion function (12.3.2), the initial standard
3902 User.Before = Best->Conversions[0].Standard;
3905 User.FoundConversionFunction = Best->FoundDecl;
3910 // result of the user-defined conversion to the target type
3913 // initialization by user-defined conversion apply when
3914 // selecting the best user-defined conversion for a
3915 // user-defined conversion sequence (see 13.3.3 and
3917 User.After = Best->FinalConversion;
3935 OverloadCandidateSet CandidateSet(From->getExprLoc(),
3950 Diag(From->getBeginLoc(), diag::err_typecheck_ambiguous_condition)
3951 << From->getType() << ToType << From->getSourceRange();
3953 if (!RequireCompleteType(From->getBeginLoc(), ToType,
3955 From->getType(), From->getSourceRange()))
3956 Diag(From->getBeginLoc(), diag::err_typecheck_nonviable_condition)
3957 << false << From->getType() << From->getSourceRange() << ToType;
3966 // conversion-operator return value 'points' to, or nullptr.
3969 const FunctionType *ConvFuncTy = Conv->getType()->castAs<FunctionType>();
3971 ConvFuncTy->getReturnType()->getAs<PointerType>();
3976 return RetPtrTy->getPointeeType()->getAs<FunctionType>();
3979 /// Compare the user-defined conversion functions or constructors
3980 /// of two user-defined conversion sequences to determine whether any ordering
3990 if (!Conv1->getParent()->isLambda() || !Conv2->getParent()->isLambda())
3993 // Objective-C++:
3994 // If both conversion functions are implicitly-declared conversions from
4000 bool Block1 = Conv1->getConversionType()->isBlockPointerType();
4001 bool Block2 = Conv2->getConversionType()->isBlockPointerType();
4009 // different), prefer the 'free' mechanism, followed by the calling-convention
4010 // of operator(). The latter is in place to support the MSVC-like solution of
4011 // defining ALL of the possible conversions in regards to calling-convention.
4016 Conv1FuncRet->getCallConv() != Conv2FuncRet->getCallConv()) {
4017 CallingConv Conv1CC = Conv1FuncRet->getCallConv();
4018 CallingConv Conv2CC = Conv2FuncRet->getCallConv();
4020 CXXMethodDecl *CallOp = Conv2->getParent()->getLambdaCallOperator();
4021 const auto *CallOpProto = CallOp->getType()->castAs<FunctionProtoType>();
4024 CallOp->getType()->castAs<FunctionType>()->getCallConv();
4026 CallOpProto->isVariadic(), /*IsCXXMethod=*/false);
4028 CallOpProto->isVariadic(), /*IsCXXMethod=*/true);
4049 /// CompareImplicitConversionSequences - Compare two implicit
4059 // -- a standard conversion sequence (13.3.3.1.1) is a better
4060 // conversion sequence than a user-defined conversion sequence or
4062 // -- a user-defined conversion sequence (13.3.3.1.2) is a better
4069 // treated as a user-defined sequence that is indistinguishable
4070 // from any other user-defined conversion sequence.
4079 // void f(char*); // #2
4082 // In C++03, we pick #2 as the best viable function.
4084 // conversion is better than string-literal to char* conversion (since there
4086 // convert arguments, #2 would be the best viable function in C++11.
4093 // Ill-formedness must not differ
4116 // List-initialization sequence L1 is a better conversion sequence than
4117 // list-initialization sequence L2 if:
4118 // - L1 converts to std::initializer_list<X> for some X and L2 does not, or,
4143 if (S.Context.hasSameUnqualifiedType(CAT1->getElementType(),
4144 CAT2->getElementType())) {
4146 if (CAT1->getSize() != CAT2->getSize())
4148 return CAT1->getSize().ult(CAT2->getSize())
4167 // User-defined conversion sequence U1 is a better conversion
4168 // sequence than another user-defined conversion sequence U2 if
4169 // they contain the same user-defined conversion function or
4197 // any non-identity conversion sequence
4214 return Context.hasSameType(SCS1.getToType(2), SCS2.getToType(2))? Result
4237 // -- S1 and S2 are reference bindings (8.5.3) and neither refers to an
4238 // implicit object parameter of a non-static member function declared
4239 // without a ref-qualifier, and *either* S1 binds an rvalue reference
4273 if (!FromType->isEnumeralType())
4276 EnumDecl *Enum = FromType->castAs<EnumType>()->getDecl();
4277 if (!Enum->isFixed())
4280 QualType UnderlyingType = Enum->getIntegerType();
4287 /// CompareStandardConversionSequences - Compare two standard
4298 // -- S1 is a proper subsequence of S2 (comparing the conversion
4302 // non-identity conversion sequence) or, if not that,
4307 // -- the rank of S1 is better than the rank of S2 (by the rules
4359 // their derived-to-base conversions.
4371 // Adjust the types we're converting from via the array-to-pointer
4378 QualType FromPointee1 = FromType1->getPointeeType().getUnqualifiedType();
4379 QualType FromPointee2 = FromType2->getPointeeType().getUnqualifiedType();
4386 // Objective-C++: If one interface is more specific than the
4389 = FromType1->getAs<ObjCObjectPointerType>();
4391 = FromType2->getAs<ObjCObjectPointerType>();
4420 // -- S1 and S2 are reference bindings (8.5.3), and the types to
4422 // top-level cv-qualifiers, and the type to which the reference
4423 // initialized by S2 refers is more cv-qualified than the type
4425 QualType T1 = SCS1.getToType(2);
4426 QualType T2 = SCS2.getToType(2);
4433 // Objective-C++ ARC: If the references refer to objects with different
4456 // floating-to-integral conversion if the integral conversion
4472 S.Context.getTypeSize(SCS1.getToType(2)))
4490 SCS1.getFromType(), SCS1.getToType(2));
4492 SCS2.getFromType(), SCS2.getToType(2));
4503 S.Context.areCompatibleSveTypes(SCS1.getFromType(), SCS1.getToType(2));
4505 S.Context.areCompatibleSveTypes(SCS2.getFromType(), SCS2.getToType(2));
4517 S.Context.areCompatibleRVVTypes(SCS1.getFromType(), SCS1.getToType(2));
4519 S.Context.areCompatibleRVVTypes(SCS2.getFromType(), SCS2.getToType(2));
4530 /// CompareQualificationConversions - Compares two standard conversion
4538 // -- S1 and S2 differ only in their qualification conversion and
4541 // [...] and the cv-qualification signature of type T1 is a proper subset
4542 // of the cv-qualification signature of type T2, and S1 is not the
4543 // deprecated string literal array-to-pointer conversion (4.2).
4544 // [C++2a]
4552 QualType T1 = SCS1.getToType(2);
4553 QualType T2 = SCS2.getToType(2);
4556 assert(!T1->isReferenceType() && !T2->isReferenceType());
4571 // Objective-C++ ARC:
4585 // FIXME: In Objective-C ARC, we can have qualification conversions in both
4586 // directions, so we can't short-cut this second check in general.
4597 /// CompareDerivedToBaseConversions - Compares two standard conversion
4599 /// various kinds of derived-to-base conversions (C++
4601 /// conversions between Objective-C interface types.
4611 // Adjust the types we're converting from via the array-to-pointer
4632 /*FIXME: Remove if Objective-C id conversions get their own rank*/
4633 FromType1->isPointerType() && FromType2->isPointerType() &&
4634 ToType1->isPointerType() && ToType2->isPointerType()) {
4636 FromType1->castAs<PointerType>()->getPointeeType().getUnqualifiedType();
4638 ToType1->castAs<PointerType>()->getPointeeType().getUnqualifiedType();
4640 FromType2->castAs<PointerType>()->getPointeeType().getUnqualifiedType();
4642 ToType2->castAs<PointerType>()->getPointeeType().getUnqualifiedType();
4644 // -- conversion of C* to B* is better than conversion of C* to A*,
4652 // -- conversion of B* to A* is better than conversion of C* to A*,
4662 = FromType1->getAs<ObjCObjectPointerType>();
4664 = FromType2->getAs<ObjCObjectPointerType>();
4666 = ToType1->getAs<ObjCObjectPointerType>();
4668 = ToType2->getAs<ObjCObjectPointerType>();
4671 // Apply the same conversion ranking rules for Objective-C pointer types
4673 // Objective-C pseudo-subtyping relationship used for assignment of
4674 // Objective-C pointer types.
4684 // A conversion to an a non-id object pointer type or qualified 'id'
4686 if (ToPtr1->isObjCIdType() &&
4687 (ToPtr2->isObjCQualifiedIdType() || ToPtr2->getInterfaceDecl()))
4689 if (ToPtr2->isObjCIdType() &&
4690 (ToPtr1->isObjCQualifiedIdType() || ToPtr1->getInterfaceDecl()))
4693 // A conversion to a non-id object pointer type is better than a
4695 if (ToPtr1->isObjCQualifiedIdType() && ToPtr2->getInterfaceDecl())
4697 if (ToPtr2->isObjCQualifiedIdType() && ToPtr1->getInterfaceDecl())
4700 // A conversion to an a non-Class object pointer type or qualified 'Class'
4702 if (ToPtr1->isObjCClassType() &&
4703 (ToPtr2->isObjCQualifiedClassType() || ToPtr2->getInterfaceDecl()))
4705 if (ToPtr2->isObjCClassType() &&
4706 (ToPtr1->isObjCQualifiedClassType() || ToPtr1->getInterfaceDecl()))
4709 // A conversion to a non-Class object pointer type is better than a
4711 if (ToPtr1->isObjCQualifiedClassType() && ToPtr2->getInterfaceDecl())
4713 if (ToPtr2->isObjCQualifiedClassType() && ToPtr1->getInterfaceDecl())
4716 // -- "conversion of C* to B* is better than conversion of C* to A*,"
4718 !FromPtr1->isObjCIdType() && !FromPtr1->isObjCClassType() &&
4720 if (FromPtr1->isSpecialized()) {
4724 FromPtr1->getInterfaceDecl() == ToPtr1->getInterfaceDecl();
4726 FromPtr1->getInterfaceDecl() == ToPtr2->getInterfaceDecl();
4737 // -- "conversion of B* to A* is better than conversion of C* to A*,"
4745 // Ranking of member-pointer types.
4747 FromType1->isMemberPointerType() && FromType2->isMemberPointerType() &&
4748 ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) {
4749 const auto *FromMemPointer1 = FromType1->castAs<MemberPointerType>();
4750 const auto *ToMemPointer1 = ToType1->castAs<MemberPointerType>();
4751 const auto *FromMemPointer2 = FromType2->castAs<MemberPointerType>();
4752 const auto *ToMemPointer2 = ToType2->castAs<MemberPointerType>();
4753 const Type *FromPointeeType1 = FromMemPointer1->getClass();
4754 const Type *ToPointeeType1 = ToMemPointer1->getClass();
4755 const Type *FromPointeeType2 = FromMemPointer2->getClass();
4756 const Type *ToPointeeType2 = ToMemPointer2->getClass();
4778 // -- conversion of C to B is better than conversion of C to A,
4779 // -- binding of an expression of type C to a reference of type
4790 // -- conversion of B to A is better than conversion of C to A.
4791 // -- binding of an expression of type B to a reference of type
4820 assert(!OrigT1->isReferenceType() &&
4822 assert(!OrigT2->isReferenceType() && "T2 cannot be a reference type");
4834 // C++2a [dcl.init.ref]p4:
4836 // reference-related to "cv2 T2" if T1 is similar to T2, or
4838 // "cv1 T1" is reference-compatible with "cv2 T2" if
4842 // Check for standard conversions we can apply to pointers: derived-to-base
4851 else if (UnqualT1->isObjCObjectOrInterfaceType() &&
4852 UnqualT2->isObjCObjectOrInterfaceType() &&
4855 else if (UnqualT2->isFunctionType() &&
4884 // If we find a qualifier mismatch, the types are not reference-compatible,
4885 // but are still be reference-related if they're similar.
4901 // At this point, if the types are reference-related, we must either have the
4909 /// Look for a user-defined conversion to a value reference-compatible
4916 assert(T2->isRecordType() && "Can only find conversions of record types.");
4917 auto *T2RecordDecl = cast<CXXRecordDecl>(T2->castAs<RecordType>()->getDecl());
4921 const auto &Conversions = T2RecordDecl->getVisibleConversionFunctions();
4924 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext());
4926 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4932 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
4939 if (!ConvTemplate && DeclType->isRValueReferenceType()) {
4941 = Conv->getConversionType()->getAs<LValueReferenceType>();
4942 if (RefType && !RefType->getPointeeType()->isFunctionType())
4949 Conv->getConversionType()
4961 Conv->getConversionType()->getAs<ReferenceType>();
4963 (!RefType->isLValueReferenceType() &&
4964 !RefType->getPointeeType()->isFunctionType()))
4988 // user-defined conversion sequence (13.3.3.1.2), with the
4992 // type, a derived-to-base Conversion.
4993 if (!Best->FinalConversion.DirectBinding)
4997 ICS.UserDefined.Before = Best->Conversions[0].Standard;
4998 ICS.UserDefined.After = Best->FinalConversion;
5000 ICS.UserDefined.ConversionFunction = Best->Function;
5001 ICS.UserDefined.FoundConversionFunction = Best->FoundDecl;
5012 if (Cand->Best)
5013 ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function);
5033 assert(DeclType->isReferenceType() && "Reference init needs a reference");
5039 QualType T1 = DeclType->castAs<ReferenceType>()->getPointeeType();
5040 QualType T2 = Init->getType();
5049 T2 = Fn->getType();
5053 bool isRValRef = DeclType->isRValueReferenceType();
5054 Expr::Classification InitCategory = Init->Classify(S.Context);
5064 // consider that when ordering reference-to-function bindings.
5072 // a reference binding that performs a non-top-level qualification
5081 ICS.Standard.setToType(2, T1);
5085 ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType();
5098 // -- If reference is an lvalue reference and the initializer expression
5100 // -- is an lvalue (but is not a bit-field), and "cv1 T1" is
5101 // reference-compatible with "cv2 T2," or
5103 // Per C++ [over.ics.ref]p4, we don't check the bit-field property here.
5111 // derived-to-base Conversion (13.3.3.1).
5115 // derived-to-base conversions is suppressed when we're
5121 // -- has a class type (i.e., T2 is a class type), where T1 is
5122 // not reference-related to T2, and can be implicitly
5124 // is reference-compatible with "cv3 T3" 92) (this
5128 if (!SuppressUserConversions && T2->isRecordType() &&
5138 // -- Otherwise, the reference shall be an lvalue reference to a
5139 // non-volatile const type (i.e., cv1 shall be const), or the reference
5147 // -- If the initializer expression
5149 // -- is an xvalue, class prvalue, array prvalue or function
5150 // lvalue and "cv1 T1" is reference-compatible with "cv2 T2", or
5154 (T2->isRecordType() || T2->isArrayType())) ||
5155 (InitCategory.isLValue() && T2->isFunctionType()))) {
5162 !(InitCategory.isPRValue() || T2->isRecordType()));
5166 // -- has a class type (i.e., T2 is a class type), where T1 is not
5167 // reference-related to T2, and can be implicitly converted to
5169 // "cv3 T3", where "cv1 T1" is reference-compatible with
5177 T2->isRecordType() && S.isCompleteType(DeclLoc, T2) &&
5183 // user-defined conversion sequence includes an lvalue-to-rvalue
5184 // conversion, the program is ill-formed.
5193 if (T1->isFunctionType())
5196 // -- Otherwise, a temporary of type "cv1 T1" is created and
5198 // rules for a non-reference copy initialization (8.5). The
5200 // reference-related to T2, cv1 must be the same
5201 // cv-qualification as, or greater cv-qualification than,
5202 // cv2; otherwise, the program is ill-formed.
5204 // If cv1 == cv2 or cv1 is a greater cv-qualified than cv2, then
5205 // we would be reference-compatible or reference-compatible with
5209 // Note that we only want to check address spaces and cvr-qualifiers here.
5230 (T1->isRecordType() || T2->isRecordType()))
5233 // If T1 is reference-related to T2 and the reference is an rvalue
5236 Init->Classify(S.Context).isLValue()) {
5247 // to copy-initializing a temporary of the underlying type with
5248 // the argument expression. Any difference in top-level
5249 // cv-qualification is subsumed by the initialization itself
5268 ICS.UserDefined.ConversionFunction->getReturnType()
5269 ->getAs<LValueReferenceType>();
5300 /// TryListConversion - Try to copy-initialize a value of type ToType from the
5321 InitTy = IAT->getElementType();
5322 if (!S.isCompleteType(From->getBeginLoc(), InitTy))
5325 // C++20 [over.ics.list]/2:
5326 // If the initializer list is a designated-initializer-list, a conversion
5332 bool IsDesignatedInit = From->hasDesignatedInit();
5333 if (!ToType->isAggregateType() && !ToType->isReferenceType() &&
5345 // appropriately-typed string literal (8.5.2 [dcl.init.string]), the
5347 if (From->getNumInits() == 1 && !IsDesignatedInit) {
5348 if (ToType->isRecordType()) {
5349 QualType InitType = From->getInit(0)->getType();
5351 S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType))
5352 return TryCopyInitialization(S, From->getInit(0), ToType,
5358 if (AT && S.IsStringInit(From->getInit(0), AT)) {
5382 // default-constructible, and if all the elements of the initializer list
5386 unsigned e = From->getNumInits();
5393 InitTy = AT->getElementType();
5395 if (CT->getSize().ult(e)) {
5402 if (CT->getSize().ugt(e)) {
5404 InitListExpr EmptyList(S.Context, From->getEndLoc(), std::nullopt,
5405 From->getEndLoc());
5422 // Cannot convert to zero-sized.
5439 Expr *Init = From->getInit(i);
5447 if (CompareImplicitConversionSequences(S, From->getBeginLoc(), ICS,
5463 S, From->getEndLoc(), DfltElt, Result) ==
5473 // Otherwise, if the parameter is a non-aggregate class X and overload
5475 // conversion sequence is a user-defined conversion sequence. If multiple
5477 // implicit conversion sequence is a user-defined conversion sequence.
5478 if (ToType->isRecordType() && !ToType->isAggregateType()) {
5491 // sequence is a user-defined conversion sequence.
5492 if (ToType->isAggregateType()) {
5518 if (ToType->isReferenceType()) {
5520 // mention initializer lists in any way. So we go by what list-
5523 QualType T1 = ToType->castAs<ReferenceType>()->getPointeeType();
5525 // If the initializer list has a single element that is reference-related
5527 if (From->getNumInits() == 1 && !IsDesignatedInit) {
5528 Expr *Init = From->getInit(0);
5530 QualType T2 = Init->getType();
5539 T2 = Fn->getType();
5544 S.CompareReferenceRelationship(From->getBeginLoc(), T1, T2);
5547 return TryReferenceInit(S, Init, ToType, /*FIXME*/ From->getBeginLoc(),
5561 "Sub-initialization cannot result in ellipsis conversion.");
5564 if (ToType->isRValueReferenceType() ||
5569 SCS.IsLvalueReference = ToType->isLValueReferenceType();
5583 if (!ToType->isRecordType()) {
5584 // - if the initializer list has one element that is not itself an
5587 unsigned NumInits = From->getNumInits();
5588 if (NumInits == 1 && !isa<InitListExpr>(From->getInit(0)))
5589 Result = TryCopyInitialization(S, From->getInit(0), ToType,
5593 // - if the initializer list has no elements, the implicit conversion
5610 /// TryCopyInitialization - Try to copy-initialize a value of type
5615 /// do not permit any user-defined conversion sequences.
5626 if (ToType->isReferenceType())
5628 /*FIXME:*/ From->getBeginLoc(),
5652 /// TryObjectArgumentInitialization - Try to initialize the object
5663 if (const auto *PT = FromType->getAs<PointerType>()) {
5664 FromType = PT->getPointeeType();
5679 if (Method->isExplicitObjectMemberFunction()) {
5681 ExplicitParameterType = Method->getFunctionObjectParameterReferenceType();
5692 assert(FromType->isRecordType());
5702 Qualifiers Quals = Method->getMethodQualifiers();
5703 if (isa<CXXDestructorDecl>(Method) || Method->isStatic()) {
5715 // For non-static member functions, the type of the implicit object
5718 // - "lvalue reference to cv X" for functions declared without a
5719 // ref-qualifier or with the & ref-qualifier
5720 // - "rvalue reference to cv X" for functions declared with the &&
5721 // ref-qualifier
5724 // cv-qualification on the member function declaration.
5727 // are not allowed to perform user-defined conversions
5730 // non-constant references.
5762 } else if (!Method->isExplicitObjectMemberFunction()) {
5768 // Check the ref-qualifier.
5769 switch (Method->getRefQualifier()) {
5776 // non-const lvalue reference cannot bind to an rvalue
5801 ICS.Standard.IsLvalueReference = Method->getRefQualifier() != RQ_RValue;
5805 = (Method->getRefQualifier() == RQ_None);
5809 /// PerformObjectArgumentInitialization - Perform initialization of
5816 QualType ImplicitParamRecordType = Method->getFunctionObjectParameterType();
5819 if (const PointerType *PT = From->getType()->getAs<PointerType>()) {
5820 FromRecordType = PT->getPointeeType();
5821 DestType = Method->getThisType();
5824 FromRecordType = From->getType();
5826 FromClassification = From->Classify(Context);
5829 if (From->isPRValue()) {
5831 Method->getRefQualifier() !=
5839 *this, From->getBeginLoc(), From->getType(), FromClassification, Method,
5840 Method->getParent());
5848 Diag(From->getBeginLoc(), diag::err_member_function_call_bad_cvr)
5849 << Method->getDeclName() << FromRecordType << (CVR - 1)
5850 << From->getSourceRange();
5851 Diag(Method->getLocation(), diag::note_previous_decl)
5852 << Method->getDeclName();
5861 Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
5862 Diag(From->getBeginLoc(), diag::err_member_function_call_bad_ref)
5863 << Method->getDeclName() << FromClassification.isRValue()
5865 Diag(Method->getLocation(), diag::note_previous_decl)
5866 << Method->getDeclName();
5879 return Diag(From->getBeginLoc(), diag::err_member_function_call_bad_type)
5881 << From->getSourceRange();
5892 if (!Context.hasSameType(From->getType(), DestType)) {
5894 QualType PteeTy = DestType->getPointeeType();
5901 From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get();
5906 /// TryContextuallyConvertToBool - Attempt to contextually convert the
5911 // - Otherwise, if the initialization is direct-initialization, the source
5914 if (From->getType()->isNullPtrType())
5915 return ImplicitConversionSequence::getNullptrToBool(From->getType(),
5917 From->isGLValue());
5919 // All other direct-initialization of bool is equivalent to an implicit
5939 return Diag(From->getBeginLoc(), diag::err_typecheck_bool_condition)
5940 << From->getType() << From->getSourceRange();
5966 // (non-conforming) extension.
5967 return SCS.getFromType()->isIntegralOrUnscopedEnumerationType() &&
5968 SCS.getToType(2)->isBooleanType();
5974 return SCS.getFromType()->isNullPtrType();
6016 /// BuildConvertedConstantExpression - Check that the expression From is a
6049 if (T->isRecordType())
6057 return S.Diag(From->getBeginLoc(),
6059 << From->getType() << From->getSourceRange() << T;
6069 return S.Diag(From->getBeginLoc(),
6071 << From->getType() << From->getSourceRange() << T;
6074 if (SCS->ReferenceBinding && !SCS->DirectBinding) {
6075 return S.Diag(From->getBeginLoc(),
6077 << From->getType() << From->getSourceRange() << T;
6080 // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
6081 // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
6084 if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
6085 return S.Diag(From->getBeginLoc(),
6087 << From->getSourceRange();
6094 if (T->isRecordType()) {
6107 // C++2a [intro.execution]p5:
6108 // A full-expression is [...] a constant-expression [...]
6109 Result = S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(),
6118 switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue,
6122 // value-dependent so we can't tell whether it's actually narrowing.
6131 PreNarrowingType->isIntegralOrEnumerationType() &&
6134 // errors by allowing the un-narrowed value through.
6138 S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing)
6146 S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing)
6147 << CCE << /*Constant*/ 0 << From->getType() << T;
6156 /// CheckConvertedConstantExpression - Check that the expression From is a
6168 if (Result.isInvalid() || Result.get()->isValueDependent()) {
6194 assert(T->isIntegralOrEnumerationType() && "unexpected converted const type");
6199 if (!R.isInvalid() && !R.get()->isValueDependent())
6216 if (CCE == Sema::CCEK_TemplateArg && T->isRecordType())
6223 if (!E->EvaluateAsConstantExpr(Eval, Context, Kind) ||
6237 assert(CE->getResultStorageKind() != ConstantResultStorageKind::None &&
6259 Diag(E->getBeginLoc(), diag::err_expr_not_cce)
6260 << CCE << E->getSourceRange();
6267 /// dropPointerConversions - If the given standard conversion sequence
6275 SCS.ToTypePtrs[2] = SCS.ToTypePtrs[1] = SCS.ToTypePtrs[0];
6279 /// TryContextuallyConvertToObjCPointer - Attempt to contextually
6280 /// convert the expression From to an Objective-C pointer type.
6333 M && !M->isImplicitAccess())
6334 Base = M->getBase();
6336 M && !M->isImplicitAccess())
6337 Base = M->getBase();
6339 QualType T = Base ? Base->getType() : S.getCurrentThisType();
6341 if (T->isPointerType())
6342 T = T->getPointeeType();
6349 QualType ObjType = Obj->getType();
6350 if (ObjType->isPointerType()) {
6351 ObjType = ObjType->getPointeeType();
6356 if (Obj->Classify(S.getASTContext()).isPRValue()) {
6359 !Fun->getParamDecl(0)->getType()->isRValueReferenceType());
6368 InitializedEntity::InitializeParameter(S.Context, Fun->getParamDecl(0)),
6369 Obj->getExprLoc(), Obj);
6375 assert(Method->isExplicitObjectMemberFunction() &&
6385 Method, Object->getBeginLoc());
6391 return AllowScopedEnumerations ? T->isIntegralOrEnumerationType()
6392 : T->isIntegralOrUnscopedEnumerationType();
6403 Converter.diagnoseAmbiguous(SemaRef, Loc, T) << From->getSourceRange();
6406 cast<CXXConversionDecl>(ViableConversions[I]->getUnderlyingDecl());
6407 QualType ConvTy = Conv->getConversionType().getNonReferenceType();
6421 cast<CXXConversionDecl>(Found->getUnderlyingDecl());
6425 QualType ConvTy = Conversion->getConversionType().getNonReferenceType();
6430 << FixItHint::CreateInsertion(From->getBeginLoc(),
6433 SemaRef.getLocForEndOfToken(From->getEndLoc()), ")");
6441 SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found);
6449 Result = SemaRef.CreateRecoveryExpr(From->getBeginLoc(), From->getEndLoc(),
6450 From, Result.get()->getType());
6463 cast<CXXConversionDecl>(Found->getUnderlyingDecl());
6464 SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found);
6466 QualType ToType = Conversion->getConversionType().getNonReferenceType();
6472 << From->getSourceRange();
6480 From = ImplicitCastExpr::Create(SemaRef.Context, Result.get()->getType(),
6482 nullptr, Result.get()->getValueKind(),
6490 if (!Converter.match(From->getType()) && !Converter.Suppress)
6491 Converter.diagnoseNoMatch(SemaRef, Loc, From->getType())
6492 << From->getSourceRange();
6504 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext());
6506 D = cast<UsingShadowDecl>(D)->getTargetDecl();
6511 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
6532 /// must have a single non-explicit conversion function converting to a matching
6547 // We can't perform any more checking for type-dependent expressions.
6548 if (From->isTypeDependent())
6552 if (From->hasPlaceholderType()) {
6561 QualType T = Converted.isUsable() ? Converted.get()->getType() : QualType();
6570 const RecordType *RecordTy = T->getAs<RecordType>();
6573 Converter.diagnoseNoMatch(*this, Loc, T) << From->getSourceRange();
6586 Converter.diagnoseIncomplete(S, Loc, T) << From->getSourceRange();
6599 cast<CXXRecordDecl>(RecordTy->getDecl())->getVisibleConversionFunctions();
6610 NamedDecl *D = (*I)->getUnderlyingDecl();
6615 Conversion = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl());
6625 QualType CurToType = Conversion->getConversionType().getNonReferenceType();
6628 if (Conversion->isExplicit()) {
6650 // type T and is well-formed if and only if e can be implicitly
6683 DeclAccessPair::make(Best->Function, Best->FoundDecl.getAccess());
6699 // We'll complain below about a non-integral condition type.
6710 // We'll complain below about a non-integral condition type.
6730 /// IsAcceptableNonMemberOperatorCandidate - Determine whether Fn is
6731 /// an acceptable non-member overloaded operator for a call whose
6732 /// arguments have types T1 (and, if non-empty, T2). This routine
6738 QualType T1 = Args[0]->getType();
6739 QualType T2 = Args.size() > 1 ? Args[1]->getType() : QualType();
6741 if (T1->isDependentType() || (!T2.isNull() && T2->isDependentType()))
6744 if (T1->isRecordType() || (!T2.isNull() && T2->isRecordType()))
6747 const auto *Proto = Fn->getType()->castAs<FunctionProtoType>();
6748 if (Proto->getNumParams() < 1)
6751 if (T1->isEnumeralType()) {
6752 QualType ArgType = Proto->getParamType(0).getNonReferenceType();
6757 if (Proto->getNumParams() < 2)
6760 if (!T2.isNull() && T2->isEnumeralType()) {
6761 QualType ArgType = Proto->getParamType(1).getNonReferenceType();
6770 if (FD->isTargetMultiVersionDefault())
6773 if (!FD->getASTContext().getTargetInfo().getTriple().isAArch64())
6774 return FD->isTargetMultiVersion();
6776 if (!FD->isMultiVersion())
6780 // or the first non-default in the absence of default version.
6784 FD->getASTContext().forEachMultiversionedFunctionVersion(
6788 else if (CurFD->isTargetMultiVersionDefault())
6802 = dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>());
6804 assert(!Function->getDescribedFunctionTemplate() &&
6811 // "this->f") that was either written explicitly or created
6816 AddMethodCandidate(Method, FoundDecl, Method->getParent(), QualType(),
6822 // We treat a constructor like a non-member function, since its object
6833 if (Constructor && Constructor->isDefaulted() && Constructor->isDeleted() &&
6834 Constructor->isMoveConstructor())
6842 // if no operand has a class type, only those non-member functions in the
6844 // (possibly cv-qualified) T1", when T1 is an enumeration type, or (if there
6846 // (possibly cv-qualified) T2", when T2 is an enumeration type, are
6873 if (getLangOpts().CPlusPlusModules && Function->isInAnotherModuleUnit()) {
6880 if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
6881 ND = SpecInfo->getTemplate();
6883 if (ND->getFormalLinkage() == Linkage::Internal) {
6900 QualType ClassType = Context.getTypeDeclType(Constructor->getParent());
6901 if (Args.size() == 1 && Constructor->isSpecializationCopyingObject() &&
6902 (Context.hasSameUnqualifiedType(ClassType, Args[0]->getType()) ||
6903 IsDerivedFrom(Args[0]->getBeginLoc(), Args[0]->getType(),
6915 // one argument and D is reference-related to P and P is reference-related
6918 if (Shadow && Args.size() == 1 && Constructor->getNumParams() >= 1 &&
6919 Constructor->getParamDecl(0)->getType()->isReferenceType()) {
6920 QualType P = Constructor->getParamDecl(0)->getType()->getPointeeType();
6921 QualType C = Context.getRecordType(Constructor->getParent());
6922 QualType D = Context.getRecordType(Shadow->getParent());
6923 SourceLocation Loc = Args.front()->getExprLoc();
6935 Constructor->getMethodQualifiers().getAddressSpace(),
6942 unsigned NumParams = Proto->getNumParams();
6944 // (C++ 13.3.2p2): A candidate function having fewer than m
6948 !Proto->isVariadic() &&
6955 // (C++ 13.3.2p2): A candidate function having more than m parameters
6960 unsigned MinRequiredArgs = Function->getMinRequiredArguments();
6976 if (!(Caller && Caller->isImplicit()) &&
6984 if (Function->getTrailingRequiresClause()) {
6999 PO == OverloadCandidateParamOrder::Reversed ? 1 - ArgIdx : ArgIdx;
7004 // (C++ 13.3.2p3): for F to be a viable function, there shall
7008 QualType ParamType = Proto->getParamType(ArgIdx);
7020 // (C++ 13.3.2p2): For the purposes of overload resolution, any
7047 // to addition of c-style arguments in method.
7048 if (Method->param_size() > NumNamedArgs)
7049 NumNamedArgs = Method->param_size();
7054 // We can't do any type-checking on a type-dependent argument.
7055 if (Args[i]->isTypeDependent()) {
7060 ParmVarDecl *param = Method->parameters()[i];
7064 // Strip the unbridged-cast placeholder expression off unless it's
7066 if (argExpr->hasPlaceholderType(BuiltinType::ARCUnbridgedCast) &&
7067 !param->hasAttr<CFConsumedAttr>())
7071 if (param->getType() == Context.UnknownAnyTy) {
7077 = TryCopyInitialization(*this, argExpr, param->getType(),
7083 // This function looks for a reasonably-exact match, so we consider
7094 if (Match && Method->isVariadic()) {
7096 if (Args[i]->isTypeDependent()) {
7108 // Check for extra arguments to non-variadic methods.
7115 QualType ReturnT = Methods[b]->getReturnType();
7116 if (ReturnT->isObjCIdType())
7136 assert(!Method->isStatic() && "Shouldn't have `this` for static methods!");
7145 assert((MissingImplicitThis || MD->isStatic() ||
7147 "Expected `this` for non-ctor instance methods");
7154 unsigned ArgSizeNoVarargs = std::min(Function->param_size(), Args.size());
7160 S.Context, Function->getParamDecl(I)),
7173 if (!Function->isVariadic() && Args.size() < Function->getNumParams()) {
7174 for (unsigned i = Args.size(), e = Function->getNumParams(); i != e; ++i) {
7175 ParmVarDecl *P = Function->getParamDecl(i);
7176 if (!P->hasDefaultArg())
7194 auto EnableIfAttrs = Function->specific_attrs<EnableIfAttr>();
7200 // FIXME: We should look into making enable_if late-parsed.
7209 // FIXME: This doesn't consider value-dependent cases, because doing so is
7211 if (EIA->getCond()->isValueDependent() ||
7212 !EIA->getCond()->EvaluateWithSubstitution(
7227 for (const auto *DIA : ND->specific_attrs<DiagnoseIfAttr>()) {
7228 if (ArgDependent == DIA->getArgDependent())
7238 [](const DiagnoseIfAttr *DIA) { return DIA->isError(); });
7240 // Note that diagnose_if attributes are late-parsed, so they appear in the
7246 S.Diag(Loc, diag::err_diagnose_if_succeeded) << DIA->getMessage();
7247 S.Diag(DIA->getLocation(), diag::note_from_diagnose_if)
7248 << DIA->getParent() << DIA->getCond()->getSourceRange();
7254 S.Diag(Loc, diag::warn_diagnose_if_succeeded) << DIA->getMessage();
7255 S.Diag(DIA->getLocation(), diag::note_from_diagnose_if)
7256 << DIA->getParent() << DIA->getCond()->getSourceRange();
7273 if (!DIA->getCond()->EvaluateWithSubstitution(
7274 Result, Context, cast<FunctionDecl>(DIA->getParent()), Args, ThisArg))
7286 return DIA->getCond()->EvaluateAsBooleanCondition(Result, Context) &&
7299 NamedDecl *D = F.getDecl()->getUnderlyingDecl();
7304 FunTmpl ? FunTmpl->getTemplatedDecl() : cast<FunctionDecl>(D);
7306 if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic()) {
7312 ObjectType = E->getType();
7314 // always classify them as l-values.
7315 if (!ObjectType.isNull() && ObjectType->isPointerType())
7318 ObjectClassification = E->Classify(Context);
7325 cast<CXXRecordDecl>(FunTmpl->getDeclContext()),
7331 cast<CXXMethodDecl>(FD)->getParent(), ObjectType,
7339 // static method as non-static.
7343 assert(cast<CXXMethodDecl>(FD)->isStatic());
7366 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(Decl->getDeclContext());
7369 Decl = cast<UsingShadowDecl>(Decl)->getTargetDecl();
7372 assert(isa<CXXMethodDecl>(TD->getTemplatedDecl()) &&
7396 = dyn_cast<FunctionProtoType>(Method->getType()->getAs<FunctionType>());
7407 if (Method->isDefaulted() && Method->isDeleted() &&
7408 Method->isMoveAssignmentOperator())
7427 (Method->isExplicitObjectMemberFunction() &&
7433 Method->isImplicitObjectMemberFunction();
7436 !IgnoreExplicitObject && Method->isExplicitObjectMemberFunction() ? 1 : 0;
7438 unsigned NumParams = Method->getNumParams() - ExplicitOffset +
7441 // (C++ 13.3.2p2): A candidate function having fewer than m
7445 !Proto->isVariadic() &&
7452 // (C++ 13.3.2p2): A candidate function having more than m parameters
7457 unsigned MinRequiredArgs = Method->getMinRequiredArguments() -
7473 else if (Method->isStatic()) {
7506 if (Method->getTrailingRequiresClause()) {
7526 // (C++ 13.3.2p3): for F to be a viable function, there shall
7533 ? Method->getFunctionObjectParameterReferenceType()
7534 : Proto->getParamType(ArgIdx - 1);
7536 ParamType = Proto->getParamType(ArgIdx + ExplicitOffset);
7550 // (C++ 13.3.2p2): For the purposes of overload resolution, any
7584 // deduction (14.8.3, 14.8.2). Those candidates are then handled as
7586 // or more function templates and also to a set of overloaded non-template
7588 // function template are combined with the set of non-template candidate
7607 Candidate.Function = MethodTmpl->getTemplatedDecl();
7613 cast<CXXMethodDecl>(Candidate.Function)->isStatic() ||
7638 /// or a non-value-dependent explicit-specification that evaluates to true.
7640 return ExplicitSpecifier::getFromDecl(FTD->getTemplatedDecl()).isExplicit();
7652 // If the function template has a non-dependent explicit specification,
7658 Candidate.Function = FunctionTemplate->getTemplatedDecl();
7667 // deduction (14.8.3, 14.8.2). Those candidates are then handled as
7669 // or more function templates and also to a set of overloaded non-template
7671 // function template are combined with the set of non-template candidate
7674 FunctionTemplate->getTemplateDepth());
7691 Candidate.Function = FunctionTemplate->getTemplatedDecl();
7734 auto *FD = FunctionTemplate->getTemplatedDecl();
7749 if (HasThisConversion && !cast<CXXMethodDecl>(FD)->isStatic() &&
7752 if (!FD->hasCXXExplicitFunctionObjectParameter() ||
7753 !ParamTypes[0]->isDependentType()) {
7757 FD->hasCXXExplicitFunctionObjectParameter() ? ParamTypes[0]
7765 Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
7767 for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size());
7770 if (!ParamType->isDependentType()) {
7773 ConvIdx = Args.size() - 1 - I;
7774 assert(Args.size() + ThisConversions == 2 &&
7775 "number of args (including 'this') must be exactly 2 for "
7808 /// Objective-C pointer to another.
7826 // If we're not allowed to consider Objective-C pointer conversions,
7831 // Is this an Objective-C pointer conversion?
7843 assert(!Conversion->getDescribedFunctionTemplate() &&
7845 QualType ConvType = Conversion->getConversionType().getNonReferenceType();
7851 if (getLangOpts().CPlusPlus14 && ConvType->isUndeducedType()) {
7852 if (DeduceReturnType(Conversion, From->getExprLoc()))
7854 ConvType = Conversion->getConversionType().getNonReferenceType();
7858 // functions that don't convert to exactly (possibly cv-qualified) T.
7860 !Context.hasSameUnqualifiedType(Conversion->getConversionType(), ToType))
7869 if (Conversion->isExplicit() &&
7891 if (!AllowExplicit && Conversion->isExplicit()) {
7904 QualType ObjectType = From->getType();
7905 if (const auto *FromPtrType = ObjectType->getAs<PointerType>())
7906 ObjectType = FromPtrType->getPointeeType();
7908 cast<CXXRecordDecl>(ObjectType->castAs<RecordType>()->getDecl());
7912 // - the object parameter of a user-defined conversion function
7913 // [...] user-defined conversion sequences are not considered.
7915 *this, CandidateSet.getLocation(), From->getType(),
7916 From->Classify(Context), Conversion, ConversionContext,
7926 if (Conversion->getTrailingRequiresClause()) {
7936 // We won't go through a user-defined type conversion function to convert a
7938 // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user]
7940 = Context.getCanonicalType(From->getType().getUnqualifiedType());
7956 // well-formed.
7957 DeclRefExpr ConversionRef(Context, Conversion, false, Conversion->getType(),
7958 VK_LValue, From->getBeginLoc());
7960 Context.getPointerType(Conversion->getType()),
7964 QualType ConversionType = Conversion->getConversionType();
7965 if (!isCompleteType(From->getBeginLoc(), ConversionType)) {
7980 Buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
7993 // If the user-defined conversion is specified by a specialization of a
7996 if (Conversion->getPrimaryTemplate() &&
8005 // the second standard conversion sequence of the user-defined
8006 // conversion sequence includes an lvalue-to-rvalue conversion, the
8007 // program is ill-formed.
8008 if (ToType->isRValueReferenceType() &&
8045 assert(isa<CXXConversionDecl>(FunctionTemplate->getTemplatedDecl()) &&
8051 // If the function template has a non-dependent explicit specification,
8057 Candidate.Function = FunctionTemplate->getTemplatedDecl();
8063 QualType ObjectType = From->getType();
8064 Expr::Classification ObjectClassification = From->Classify(getASTContext());
8074 Candidate.Function = FunctionTemplate->getTemplatedDecl();
8116 if (Conversion->hasCXXExplicitFunctionObjectParameter()) {
8118 Conversion->getParamDecl(0)->getType(),
8123 *this, CandidateSet.getLocation(), Object->getType(),
8124 Object->Classify(Context), Conversion, ActingContext);
8134 // The first conversion is actually a user-defined conversion whose
8148 unsigned NumParams = Proto->getNumParams();
8150 // (C++ 13.3.2p2): A candidate function having fewer than m
8153 if (Args.size() > NumParams && !Proto->isVariadic()) {
8172 // (C++ 13.3.2p3): for F to be a viable function, there shall
8176 QualType ParamType = Proto->getParamType(ArgIdx);
8189 // (C++ 13.3.2p2): For the purposes of overload resolution, any
8196 if (Conversion->getTrailingRequiresClause()) {
8221 NamedDecl *D = F.getDecl()->getUnderlyingDecl();
8226 FunTmpl ? FunTmpl->getTemplatedDecl() : cast<FunctionDecl>(D);
8265 // cv-unqualified version is T1, and for a binary operator @ with
8266 // a left operand of a type whose cv-unqualified version is T1 and
8267 // a right operand of a type whose cv-unqualified version is T2,
8269 // candidates, non-member candidates and built-in candidates, are
8271 QualType T1 = Args[0]->getType();
8273 // -- If T1 is a complete class type or a class currently being
8277 if (const RecordType *T1Rec = T1->getAs<RecordType>()) {
8279 if (!isCompleteType(OpLoc, T1) && !T1Rec->isBeingDefined())
8282 if (!T1Rec->getDecl()->getDefinition())
8286 LookupQualifiedName(Operators, T1Rec->getDecl());
8292 if (Oper->getAsFunction() &&
8295 *this, {Args[1], Args[0]}, Oper->getAsFunction()))
8297 AddMethodCandidate(Oper.getPair(), Args[0]->getType(),
8298 Args[0]->Classify(Context), Args.slice(1),
8324 // For the built-in assignment operators, conversions of the
8326 // -- no temporaries are introduced to hold the left operand, and
8327 // -- no user-defined conversions are applied to the left
8328 // operand to achieve a type match with the left-most
8329 // parameter of a built-in candidate.
8331 // We block these conversions by turning off user-defined
8333 // a reference to a non-class type can occur from something that
8358 /// BuiltinCandidateTypeSet - A set of types that will be used for the
8359 /// candidate operator functions for built-in operators (C++
8363 /// TypeSet - A set of types.
8366 /// PointerTypes - The set of pointer types that will be used in the
8367 /// built-in candidates.
8370 /// MemberPointerTypes - The set of member pointer types that will be
8371 /// used in the built-in candidates.
8374 /// EnumerationTypes - The set of enumeration types that will be
8375 /// used in the built-in candidates.
8378 /// The set of vector types that will be used in the built-in
8382 /// The set of matrix types that will be used in the built-in
8386 /// The set of _BitInt types that will be used in the built-in candidates.
8389 /// A flag indicating non-record types are viable candidates
8400 /// Sema - The semantic analysis instance where we are building the
8404 /// Context - The AST context in which we will build the type sets.
8412 /// iterator - Iterates through the types that are part of the set.
8447 /// AddPointerWithMoreQualifiedTypeVariants - Add the pointer type @p Ty to
8448 /// the set of pointer types along with any more-qualified variants of
8465 const PointerType *PointerTy = Ty->getAs<PointerType>();
8468 const ObjCObjectPointerType *PTy = Ty->castAs<ObjCObjectPointerType>();
8469 PointeeTy = PTy->getPointeeType();
8472 PointeeTy = PointerTy->getPointeeType();
8477 // only overload situation where it matters is subscript or pointer +- int,
8479 if (PointeeTy->isArrayType())
8493 // the type cannot be restrict-qualified.
8496 (!(PointeeTy->isAnyPointerType() || PointeeTy->isReferenceType()))))
8516 /// AddMemberPointerWithMoreQualifiedTypeVariants - Add the pointer type @p Ty
8517 /// to the set of pointer types along with any more-qualified variants of
8532 const MemberPointerType *PointerTy = Ty->getAs<MemberPointerType>();
8535 QualType PointeeTy = PointerTy->getPointeeType();
8538 // only overload situation where it matters is subscript or pointer +- int,
8540 if (PointeeTy->isArrayType())
8542 const Type *ClassTy = PointerTy->getClass();
8558 /// AddTypesConvertedFrom - Add each of the types to which the type @p
8577 if (const ReferenceType *RefTy = Ty->getAs<ReferenceType>())
8578 Ty = RefTy->getPointeeType();
8581 if (Ty->isArrayType())
8587 // Flag if we ever add a non-record type.
8588 const RecordType *TyRec = Ty->getAs<RecordType>();
8593 HasArithmeticOrEnumeralTypes || Ty->isArithmeticType();
8595 if (Ty->isObjCIdType() || Ty->isObjCClassType())
8597 else if (Ty->getAs<PointerType>() || Ty->getAs<ObjCObjectPointerType>()) {
8598 // Insert our type, and its more-qualified variants, into the set
8602 } else if (Ty->isMemberPointerType()) {
8606 } else if (Ty->isEnumeralType()) {
8609 } else if (Ty->isBitIntType()) {
8612 } else if (Ty->isVectorType()) {
8617 } else if (Ty->isMatrixType()) {
8622 } else if (Ty->isNullPtrType()) {
8629 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl());
8630 for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) {
8632 D = cast<UsingShadowDecl>(D)->getTargetDecl();
8640 if (AllowExplicitConversions || !Conv->isExplicit()) {
8641 AddTypesConvertedFrom(Conv->getConversionType(), Loc, false, false,
8651 return S.Context.getAddrSpaceQualType(T, Arg->getType().getAddressSpace());
8655 /// the volatile- and non-volatile-qualified assignment operators for the
8661 QualType ParamTypes[2];
8681 /// CollectVRQualifiers - This routine returns Volatile/Restrict qualifiers,
8687 ArgExpr->getType()->getAs<MemberPointerType>())
8688 TyRec = RHSMPType->getClass()->getAs<RecordType>();
8690 TyRec = ArgExpr->getType()->getAs<RecordType>();
8698 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl());
8699 if (!ClassDecl->hasDefinition())
8702 for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) {
8704 D = cast<UsingShadowDecl>(D)->getTargetDecl();
8706 QualType CanTy = Context.getCanonicalType(Conv->getConversionType());
8707 if (const ReferenceType *ResTypeRef = CanTy->getAs<ReferenceType>())
8708 CanTy = ResTypeRef->getPointeeType();
8715 if (const PointerType *ResTypePtr = CanTy->getAs<PointerType>())
8716 CanTy = ResTypePtr->getPointeeType();
8718 CanTy->getAs<MemberPointerType>())
8719 CanTy = ResTypeMPtr->getPointeeType();
8823 S.Context.getAuxTargetInfo()->hasInt128Type()))
8830 S.Context.getAuxTargetInfo()->hasInt128Type()))
8839 llvm::SmallSetVector<CanQualType, 2> BitIntCandidates;
8866 // We don't know for sure how many bit-precise candidates were involved, so
8869 assert(ArithmeticTypes.size() - BitIntCandidates.size() <=
8875 /// for '++' and '--' builtin operators.
8879 QualType ParamTypes[2] = {
8884 // Non-volatile version.
8897 // and our candidate type is a non-restrict-qualified pointer.
8898 if (HasRestrict && CandidateTy->isAnyPointerType() &&
8917 /// Helper to add an overload candidate for a binary builtin with types \p L
8919 void AddCandidate(QualType L, QualType R) {
8920 QualType LandR[2] = {L, R};
8958 // VQ T& operator--(VQ T&);
8959 // T operator--(VQ T&, int);
8981 // For every pair (T, VQ), where T is a cv-qualified or
8982 // cv-unqualified object type, and VQ is either volatile or
8986 // T*VQ& operator--(T*VQ&);
8988 // T* operator--(T*VQ&, int);
8992 if (!PtrTy->getPointeeType()->isObjectType())
9005 // For every cv-qualified or cv-unqualified object type T, there
9011 // For every function type T that does not have cv-qualifiers or a
9012 // ref-qualifier, there exist candidate operator functions of the form
9016 QualType PointeeTy = ParamTy->getPointeeType();
9017 if (!PointeeTy->isObjectType() && !PointeeTy->isFunctionType())
9020 if (const FunctionProtoType *Proto =PointeeTy->getAs<FunctionProtoType>())
9021 if (Proto->getMethodQuals() || Proto->getRefQualifier())
9033 // T operator-(T);
9095 QualType ParamTypes[2] = {MemPtrTy, MemPtrTy};
9102 QualType ParamTypes[2] = { NullPtrTy, NullPtrTy };
9123 // [...]the built-in candidates include all of the candidate operator
9125 // do not have the same parameter-type-list as any non-template non-member
9129 // aren't any built-in candidates of record type, and a user-defined operator
9142 if (!C->Viable || !C->Function || C->Function->getNumParams() != 2)
9145 if (C->Function->isFunctionTemplateSpecialization())
9148 // We interpret "same parameter-type-list" as applying to the
9151 bool Reversed = C->isReversed();
9152 QualType FirstParamType = C->Function->getParamDecl(Reversed ? 1 : 0)
9153 ->getType()
9155 QualType SecondParamType = C->Function->getParamDecl(Reversed ? 0 : 1)
9156 ->getType()
9160 if (!FirstParamType->isEnumeralType() ||
9161 !SecondParamType->isEnumeralType())
9164 // Add this operator to the set of known user-defined operators.
9180 if (IsSpaceship && PtrTy->isFunctionPointerType())
9183 QualType ParamTypes[2] = {PtrTy, PtrTy};
9195 QualType ParamTypes[2] = {EnumTy, EnumTy};
9203 // For every cv-qualified or cv-unqualified object type T
9208 // T* operator-(T*, ptrdiff_t);
9217 // ptrdiff_t operator-(T, T);
9222 for (int Arg = 0; Arg < 2; ++Arg) {
9223 QualType AsymmetricParamTypes[2] = {
9228 QualType PointeeTy = PtrTy->getPointeeType();
9229 if (!PointeeTy->isObjectType())
9234 // operator+(T*, ptrdiff_t) or operator-(T*, ptrdiff_t)
9239 // ptrdiff_t operator-(T, T);
9243 QualType ParamTypes[2] = {PtrTy, PtrTy};
9252 // For every pair of promoted arithmetic types L and R, there
9255 // LR operator*(L, R);
9256 // LR operator/(L, R);
9257 // LR operator+(L, R);
9258 // LR operator-(L, R);
9259 // bool operator<(L, R);
9260 // bool operator>(L, R);
9261 // bool operator<=(L, R);
9262 // bool operator>=(L, R);
9263 // bool operator==(L, R);
9264 // bool operator!=(L, R);
9267 // between types L and R.
9271 // For every pair of promoted arithmetic types L and R, there exist
9274 // LR operator?(bool, L, R);
9277 // between types L and R.
9287 QualType LandR[2] = { ArithmeticTypes[Left],
9297 QualType LandR[2] = {Vec1Ty, Vec2Ty};
9303 /// * (M1, M1) -> M1
9304 /// * (M1, M1.getElementType()) -> M1
9305 /// * (M2.getElementType(), M2) -> M2
9306 /// * (M2, M2) -> M2 // Only if M2 is not part of CandidateTypes[0].
9312 AddCandidate(M1, cast<MatrixType>(M1)->getElementType());
9317 AddCandidate(cast<MatrixType>(M2)->getElementType(), M2);
9323 // C++2a [over.built]p14:
9330 // C++2a [over.built]p15:
9332 // For every pair of floating-point types L and R, there exists a candidate
9335 // std::partial_ordering operator<=>(L, R);
9338 // the direction of p0946r0, which allows mixed integral and unscoped-enum
9350 // the mixed overloads `operator<=>(L, R)` where L and R are promoted
9360 // For every pair of promoted integral types L and R, there
9363 // LR operator%(L, R);
9364 // LR operator&(L, R);
9365 // LR operator^(L, R);
9366 // LR operator|(L, R);
9367 // L operator<<(L, R);
9368 // L operator>>(L, R);
9371 // between types L and R.
9380 QualType LandR[2] = { ArithmeticTypes[Left],
9398 for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) {
9425 // For every pair (T, VQ), where T is a cv-qualified or
9426 // cv-unqualified object type and VQ is either volatile or
9430 // T*VQ& operator-=(T*VQ&, ptrdiff_t);
9439 else if (!PtrTy->getPointeeType()->isObjectType())
9442 // non-volatile version
9443 QualType ParamTypes[2] = {
9485 QualType ParamTypes[2] = {
9490 // non-volatile version
9527 // For every triple (L, VQ, R), where L is an arithmetic type,
9532 // VQ L& operator=(VQ L&, R);
9533 // VQ L& operator*=(VQ L&, R);
9534 // VQ L& operator/=(VQ L&, R);
9535 // VQ L& operator+=(VQ L&, R);
9536 // VQ L& operator-=(VQ L&, R);
9544 QualType ParamTypes[2];
9559 // Extension: Add the binary operators =, +=, -=, *=, /= for vector types.
9562 QualType ParamTypes[2];
9564 // Add this built-in operator as a candidate (VQ is empty).
9569 // Add this built-in operator as a candidate (VQ is 'volatile').
9581 // For every triple (L, VQ, R), where L is an integral type, VQ
9585 // VQ L& operator%=(VQ L&, R);
9586 // VQ L& operator<<=(VQ L&, R);
9587 // VQ L& operator>>=(VQ L&, R);
9588 // VQ L& operator&=(VQ L&, R);
9589 // VQ L& operator^=(VQ L&, R);
9590 // VQ L& operator|=(VQ L&, R);
9598 QualType ParamTypes[2];
9627 QualType ParamTypes[2] = { S.Context.BoolTy, S.Context.BoolTy };
9630 /*NumContextualBoolArguments=*/2);
9635 // For every cv-qualified or cv-unqualified object type T there
9640 // T* operator-(T*, ptrdiff_t); [ABOVE]
9645 QualType ParamTypes[2] = {PtrTy, S.Context.getPointerDiffType()};
9646 QualType PointeeType = PtrTy->getPointeeType();
9647 if (!PointeeType->isObjectType())
9655 QualType ParamTypes[2] = {S.Context.getPointerDiffType(), PtrTy};
9656 QualType PointeeType = PtrTy->getPointeeType();
9657 if (!PointeeType->isObjectType())
9668 // type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
9671 // CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
9679 C1 = QualType(Q1.strip(C1Ty->getPointeeType()), 0);
9691 QualType C2 = QualType(mptr->getClass(), 0);
9695 QualType ParamTypes[2] = {PtrTy, MemPtrTy};
9697 QualType T = mptr->getPointeeType();
9715 // For every type T, where T is a pointer, pointer-to-member, or scoped
9724 for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) {
9729 QualType ParamTypes[2] = {PtrTy, PtrTy};
9737 QualType ParamTypes[2] = {MemPtrTy, MemPtrTy};
9743 if (!EnumTy->castAs<EnumType>()->getDecl()->isScoped())
9749 QualType ParamTypes[2] = {EnumTy, EnumTy};
9764 // if the operator we're looking at has built-in operator candidates
9765 // that make use of these types. Also record whether we encounter non-record
9771 if (Args[ArgIdx]->getType()->isAtomicType())
9777 SmallVector<BuiltinCandidateTypeSet, 2> CandidateTypes;
9780 CandidateTypes[ArgIdx].AddTypesConvertedFrom(Args[ArgIdx]->getType(),
9794 // Exit early when no non-record types have been added to the candidate set
9827 // -- For the operator ',', the unary operator '&', the
9828 // operator '->', or the operator 'co_await', the
9829 // built-in candidates set is empty.
9837 case OO_Minus: // '-' is either unary or binary
9897 // -- For the operator ',', the unary operator '&', or the
9898 // operator '->', the built-in candidates set is empty.
9941 if (Args.size() == 2)
9966 // redundant candidates from the set) relies on pointer-equality,
9979 if (Cand->Function) {
9980 Fns.erase(Cand->Function);
9981 if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate())
10013 *this, Args, FTD->getTemplatedDecl())) {
10042 bool Cand1Attr = Cand1->hasAttr<EnableIfAttr>();
10043 bool Cand2Attr = Cand2->hasAttr<EnableIfAttr>();
10050 auto Cand1Attrs = Cand1->specific_attrs<EnableIfAttr>();
10051 auto Cand2Attrs = Cand2->specific_attrs<EnableIfAttr>();
10068 (*Cand1A)->getCond()->Profile(Cand1ID, S.getASTContext(), true);
10069 (*Cand2A)->getCond()->Profile(Cand2ID, S.getASTContext(), true);
10080 if (!Cand1.Function || !Cand1.Function->isMultiVersion() || !Cand2.Function ||
10081 !Cand2.Function->isMultiVersion())
10086 if (Cand1.Function->isInvalidDecl()) {
10087 if (Cand2.Function->isInvalidDecl())
10091 if (Cand2.Function->isInvalidDecl())
10096 bool Cand1CPUDisp = Cand1.Function->hasAttr<CPUDispatchAttr>();
10097 bool Cand2CPUDisp = Cand2.Function->hasAttr<CPUDispatchAttr>();
10098 const auto *Cand1CPUSpec = Cand1.Function->getAttr<CPUSpecificAttr>();
10099 const auto *Cand2CPUSpec = Cand2.Function->getAttr<CPUSpecificAttr>();
10110 if (Cand1CPUSpec->cpus_size() != Cand2CPUSpec->cpus_size())
10111 return Cand1CPUSpec->cpus_size() < Cand2CPUSpec->cpus_size()
10117 Cand1CPUSpec->cpus_begin(), Cand1CPUSpec->cpus_end(),
10118 Cand2CPUSpec->cpus_begin(),
10120 return LHS->getName() == RHS->getName();
10123 assert(FirstDiff.first != Cand1CPUSpec->cpus_end() &&
10124 "Two different cpu-specific versions should not have the same "
10126 return (*FirstDiff.first)->getName() < (*FirstDiff.second)->getName()
10143 if (M->isStatic())
10145 return M->getFunctionObjectParameterReferenceType();
10154 auto PT1 = F1->getPrimaryTemplate();
10155 auto PT2 = F2->getPrimaryTemplate();
10158 declaresSameEntity(PT1->getInstantiatedFromMemberTemplate(),
10159 PT2->getInstantiatedFromMemberTemplate()))
10170 assert(I < F->getNumParams());
10171 return F->getParamDecl(I++)->getType();
10174 unsigned F1NumParams = F1->getNumParams() + isa<CXXMethodDecl>(F1);
10175 unsigned F2NumParams = F2->getNumParams() + isa<CXXMethodDecl>(F2);
10194 /// F1 and F2 are non-template functions with the same
10195 /// non-object-parameter-type-lists, and F1 is more constrained than F2 [...]
10205 if (Fn1->isVariadic() != Fn2->isVariadic())
10217 if (Mem1->getParent() != Mem2->getParent())
10219 // if both are non-static member functions, they have the same types for
10221 if (Mem1->isInstance() && Mem2->isInstance() &&
10223 Mem1->getFunctionObjectParameterReferenceType(),
10224 Mem1->getFunctionObjectParameterReferenceType()))
10230 /// isBetterOverloadCandidate - Determines whether the first overload
10235 // Define viable functions to be better candidates than non-viable
10247 // be triggered if it is emitted. However a wrong-sided function is still
10259 // should take precedence in preference, e.g. the standard-defined preferences
10260 // like argument conversion ranks or enable_if partial-ordering. The
10261 // preference for pass-object-size parameters is probably most similar to a
10262 // type-based-overloading decision and so should take priority.
10274 // -fgpu-exclude-wrong-side-overloads is on since this requires deferring
10289 // over wrong-sided candidates, overloading resolution may change, which
10290 // may result in non-deferrable diagnostics. As a workaround, we let
10291 // implicit HD candidates take equal preference as wrong-sided candidates.
10313 // -- if F is a static member function, ICS1(F) is defined such
10327 // The only ill-formed conversion we allow in C++ is the string literal to
10328 // char* conversion, which is only considered ill-formed after C++11.
10333 // Define functions that don't require ill-formed conversions for a given
10369 // Work around large-scale breakage caused by considering reversed
10394 // -- for some argument j, ICSj(F1) is a better conversion sequence than
10399 // -- the context is an initialization by user-defined conversion
10410 // other. This only distinguishes the results in non-standard, extension
10425 // C++14 [over.match.best]p1 section 2 bullet 3.
10440 // -- F1 is a non-template function and F2 is a function template
10443 Cand1.Function->getPrimaryTemplate();
10445 Cand2.Function->getPrimaryTemplate();
10449 // -- F1 and F2 are function template specializations, and the function
10455 dyn_cast<CXXRecordDecl>(Cand1.FoundDecl->getDeclContext());
10457 dyn_cast<CXXRecordDecl>(Cand2.FoundDecl->getDeclContext());
10459 Cand1.Function->getPrimaryTemplate(),
10460 Cand2.Function->getPrimaryTemplate(), Loc,
10464 Obj1Context ? QualType(Obj1Context->getTypeForDecl(), 0)
10466 Obj2Context ? QualType(Obj2Context->getTypeForDecl(), 0)
10469 return BetterTemplate == Cand1.Function->getPrimaryTemplate();
10473 // -— F1 and F2 are non-template functions with the same
10474 // parameter-type-lists, and F1 is more constrained than F2 [...],
10481 // -- F1 is a constructor for a class D, F2 is a constructor for a base
10493 auto *Cand1Class = cast<CXXRecordDecl>(Cand1.Function->getDeclContext());
10494 auto *Cand2Class = cast<CXXRecordDecl>(Cand2.Function->getDeclContext());
10495 if (Cand1Class->isDerivedFrom(Cand2Class))
10497 if (Cand2Class->isDerivedFrom(Cand1Class))
10502 // -- F2 is a rewritten candidate (12.4.1.2) and F1 is not
10503 // -- F1 and F2 are rewritten candidates, and F2 is a synthesized candidate
10508 // the maximally-rewritten operator (== or <=>).
10512 // Check C++17 tie-breakers for deduction guides.
10517 // -- F1 is generated from a deduction-guide and F2 is not
10518 if (Guide1->isImplicit() != Guide2->isImplicit())
10519 return Guide2->isImplicit();
10521 // -- F1 is the copy deduction candidate(16.3.1.8) and F2 is not
10522 if (Guide1->getDeductionCandidateKind() == DeductionCandidate::Copy)
10524 if (Guide2->getDeductionCandidateKind() == DeductionCandidate::Copy)
10527 // --F1 is generated from a non-template constructor and F2 is generated
10529 const auto *Constructor1 = Guide1->getCorrespondingConstructor();
10530 const auto *Constructor2 = Guide2->getCorrespondingConstructor();
10532 bool isC1Templated = Constructor1->getTemplatedKind() !=
10534 bool isC2Templated = Constructor2->getTemplatedKind() !=
10542 // Check for enable_if value-based overload resolution.
10577 LangAS AS1 = CD1->getMethodQualifiers().getAddressSpace();
10578 LangAS AS2 = CD2->getMethodQualifiers().getAddressSpace();
10606 if (!VA->getDeclContext()->getRedeclContext()->Equals(
10607 VB->getDeclContext()->getRedeclContext()) ||
10609 VA->isExternallyVisible() || VB->isExternallyVisible())
10616 // the same. For non-constant variables, we shouldn't allow it at all.
10617 if (Context.hasSameType(VA->getType(), VB->getType()))
10626 auto *EnumA = cast<EnumDecl>(EA->getDeclContext());
10627 auto *EnumB = cast<EnumDecl>(EB->getDeclContext());
10628 if (EnumA->hasNameForLinkage() || EnumB->hasNameForLinkage() ||
10629 !Context.hasSameType(EnumA->getIntegerType(),
10630 EnumB->getIntegerType()))
10633 return llvm::APSInt::isSameValue(EA->getInitVal(), EB->getInitVal());
10647 Diag(D->getLocation(), diag::note_equivalent_internal_linkage_decl)
10648 << !M << (M ? M->getFullModuleName() : "");
10652 Diag(E->getLocation(), diag::note_equivalent_internal_linkage_decl)
10653 << !M << (M ? M->getFullModuleName() : "");
10662 ->Satisfaction.ContainsErrors;
10682 // [CUDA] HD->H or HD->D calls are technically not allowed by CUDA but
10685 // exclude non-viable overload candidates from consideration based
10689 // We only need to remove wrong-sided candidates here if
10690 // -fgpu-exclude-wrong-side-overloads is off. When
10691 // -fgpu-exclude-wrong-side-overloads is on, all candidates are compared
10698 return Cand->Viable && Cand->Function &&
10699 S.CUDA().IdentifyPreference(Caller, Cand->Function) ==
10705 return Cand->Viable && Cand->Function &&
10706 S.CUDA().IdentifyPreference(Caller, Cand->Function) ==
10716 Cand->Best = false;
10717 if (Cand->Viable) {
10721 } else if (Cand->NotValidBecauseConstraintExprHasError()) {
10739 Best->Best = true;
10746 if (Cand->Viable && !Cand->Best &&
10749 Cand->Best = true;
10751 if (S.isEquivalentInternalLinkageDeclaration(Cand->Function,
10752 Curr->Function))
10753 EquivalentCands.push_back(Cand->Function);
10765 if (Best->Function && Best->Function->isDeleted())
10768 if (auto *M = dyn_cast_or_null<CXXMethodDecl>(Best->Function);
10770 M->isImplicitObjectMemberFunction()) {
10775 S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function,
10809 bool isTemplate = Fn->isTemplateDecl() || Found->isTemplateDecl();
10810 if (FunctionTemplateDecl *FunTmpl = Fn->getPrimaryTemplate()) {
10813 FunTmpl->getTemplateParameters(), *Fn->getTemplateSpecializationArgs());
10823 if (Fn->isImplicit() && Fn->getOverloadedOperator() == OO_EqualEqual)
10830 if (!Ctor->isImplicit()) {
10837 if (Ctor->isDefaultConstructor())
10840 if (Ctor->isMoveConstructor())
10843 assert(Ctor->isCopyConstructor() &&
10851 if (!Meth->isImplicit())
10854 if (Meth->isMoveAssignmentOperator())
10857 if (Meth->isCopyAssignmentOperator())
10871 // FIXME: It'd be nice to only emit a note once per using-decl per overload
10874 S.Diag(FoundDecl->getLocation(),
10876 << Shadow->getNominatedBaseClass();
10883 for (auto *EnableIf : FD->specific_attrs<EnableIfAttr>()) {
10885 if (EnableIf->getCond()->isValueDependent() ||
10886 !EnableIf->getCond()->EvaluateAsBooleanCondition(AlwaysTrue, Ctx))
10896 /// \param Complain - If true, we'll emit a diagnostic
10897 /// \param InOverloadResolution - For the purposes of emitting a diagnostic, are
10899 /// \param Loc - The location of the statement we're complaining about. Ignored
10908 S.Diag(FD->getBeginLoc(),
10916 if (FD->getTrailingRequiresClause()) {
10924 if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) {
10927 FunTmpl->getTemplateParameters(),
10928 *FD->getTemplateSpecializationArgs());
10931 S.Diag(FD->getBeginLoc(),
10943 auto I = llvm::find_if(FD->parameters(), [](const ParmVarDecl *P) {
10944 return P->hasAttr<PassObjectSizeAttr>();
10946 if (I == FD->param_end())
10950 // Add one to ParamNo because it's user-facing
10951 unsigned ParamNo = std::distance(FD->param_begin(), I) + 1;
10953 S.Diag(FD->getLocation(),
10985 const auto *RD = cast<CXXRecordDecl>(Fn->getParent());
10986 if (!RD->isLambda())
10989 CXXMethodDecl *CallOp = RD->getLambdaCallOperator();
10991 CallOp->getType()->castAs<FunctionType>()->getCallConv();
10992 QualType ConvRTy = ConvD->getType()->castAs<FunctionType>()->getReturnType();
10994 ConvRTy->getPointeeType()->castAs<FunctionType>()->getCallConv();
11005 if (Fn->isMultiVersion() && Fn->hasAttr<TargetAttr>() &&
11006 !Fn->getAttr<TargetAttr>()->isDefaultVersion())
11008 if (Fn->isMultiVersion() && Fn->hasAttr<TargetVersionAttr>() &&
11009 !Fn->getAttr<TargetVersionAttr>()->isDefaultVersion())
11021 HandleFunctionTypeMismatch(PD, Fn->getType(), DestType);
11022 Diag(Fn->getLocation(), PD);
11032 // void foo() requires (sizeof(T) > 4) && T::value { } // #2
11035 // #2 to subsume #1, but these constraint are not considered equivalent
11037 // source-level construct. This behavior is quite confusing and we should try
11043 if (!I->Function)
11046 if (auto *Template = I->Function->getPrimaryTemplate())
11047 Template->getAssociatedConstraints(AC);
11049 I->Function->getAssociatedConstraints(AC);
11053 FirstCand = I->Function;
11056 SecondCand = I->Function;
11059 // We have more than one pair of constrained functions - this check is
11079 assert(OverloadedExpr->getType() == Context.OverloadTy);
11081 OverloadExpr::FindResult Ovl = OverloadExpr::find(OverloadedExpr);
11082 OverloadExpr *OvlExpr = Ovl.Expression;
11084 for (UnresolvedSetIterator I = OvlExpr->decls_begin(),
11085 IEnd = OvlExpr->decls_end();
11088 dyn_cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl()) ) {
11089 NoteOverloadCandidate(*I, FunTmpl->getTemplatedDecl(), CRK_None, DestType,
11092 = dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl()) ) {
11113 S.NoteOverloadCandidate(I->first, I->second);
11117 S.Diag(SourceLocation(), diag::note_ovl_too_many_candidates) << int(E - I);
11122 const ImplicitConversionSequence &Conv = Cand->Conversions[I];
11124 assert(Cand->Function && "for now, candidate must be a function");
11125 FunctionDecl *Fn = Cand->Function;
11128 // non-constructor method. Note that 'I' corresponds the
11129 // conversion-slot index.
11135 I--;
11140 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(),
11151 llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) {
11152 return Parm->isParameterPack();
11155 ToParamRange = Fn->getParamDecl(I)->getSourceRange();
11159 Expr *E = FromExpr->IgnoreParens();
11161 E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
11162 DeclarationName Name = cast<OverloadExpr>(E)->getName();
11164 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_overload)
11167 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11171 // Do some hand-waving analysis to see if the non-viability is due
11175 if (CanQual<ReferenceType> RT = CToTy->getAs<ReferenceType>())
11176 CToTy = RT->getPointeeType();
11179 if (CanQual<PointerType> FromPT = CFromTy->getAs<PointerType>())
11180 if (CanQual<PointerType> ToPT = CToTy->getAs<PointerType>()) {
11181 CFromTy = FromPT->getPointeeType();
11182 CToTy = ToPT->getPointeeType();
11193 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace_this)
11197 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace)
11200 << ToQs.getAddressSpace() << ToTy->isReferenceType() << I + 1;
11201 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11206 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_ownership)
11210 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11215 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_gc)
11219 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11227 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr_this)
11229 << FromTy << (CVR - 1);
11231 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr)
11233 << ToParamRange << FromTy << (CVR - 1) << I + 1;
11235 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11241 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_value_category)
11246 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11253 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_list_argument)
11258 ? 2
11260 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11268 if (const PointerType *PTy = TempFromTy->getAs<PointerType>())
11269 TempFromTy = PTy->getPointeeType();
11270 if (TempFromTy->isIncompleteType()) {
11272 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_conv_incomplete)
11275 << (unsigned)(Cand->Fix.Kind);
11277 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11281 // Diagnose base -> derived pointer conversions.
11283 if (const PointerType *FromPtrTy = FromTy->getAs<PointerType>()) {
11284 if (const PointerType *ToPtrTy = ToTy->getAs<PointerType>()) {
11285 if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs(
11286 FromPtrTy->getPointeeType()) &&
11287 !FromPtrTy->getPointeeType()->isIncompleteType() &&
11288 !ToPtrTy->getPointeeType()->isIncompleteType() &&
11289 S.IsDerivedFrom(SourceLocation(), ToPtrTy->getPointeeType(),
11290 FromPtrTy->getPointeeType()))
11294 = FromTy->getAs<ObjCObjectPointerType>()) {
11296 = ToTy->getAs<ObjCObjectPointerType>())
11297 if (const ObjCInterfaceDecl *FromIface = FromPtrTy->getInterfaceDecl())
11298 if (const ObjCInterfaceDecl *ToIface = ToPtrTy->getInterfaceDecl())
11299 if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs(
11300 FromPtrTy->getPointeeType()) &&
11301 FromIface->isSuperClassOf(ToIface))
11302 BaseToDerivedConversion = 2;
11303 } else if (const ReferenceType *ToRefTy = ToTy->getAs<ReferenceType>()) {
11304 if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) &&
11305 !FromTy->isIncompleteType() &&
11306 !ToRefTy->getPointeeType()->isIncompleteType() &&
11307 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) {
11313 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_base_to_derived_conv)
11315 << ToParamRange << (BaseToDerivedConversion - 1) << FromTy << ToTy
11317 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11326 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_arc_conv)
11330 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11336 !checkAddressOfCandidateIsAvailable(S, Cand->Function))
11343 << (unsigned)(Cand->Fix.Kind);
11346 if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) {
11348 for (const FixItHint &HI : Cand->Fix.Hints)
11352 S.Diag(Fn->getLocation(), FDiag);
11354 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11362 FunctionDecl *Fn = Cand->Function;
11363 unsigned MinParams = Fn->getMinRequiredExplicitArguments() +
11364 ((IsAddressOf && !Fn->isStatic()) ? 1 : 0);
11369 // the weird behavior of overloading member and non-member functions.
11371 if (Fn->isInvalidDecl() &&
11372 Fn->getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
11376 assert((Cand->FailureKind == ovl_fail_too_few_arguments) ||
11377 (Cand->FailureKind == ovl_fail_bad_deduction &&
11378 Cand->DeductionFailure.getResult() ==
11381 assert((Cand->FailureKind == ovl_fail_too_many_arguments) ||
11382 (Cand->FailureKind == ovl_fail_bad_deduction &&
11383 Cand->DeductionFailure.getResult() ==
11402 const auto *FnTy = Fn->getType()->castAs<FunctionProtoType>();
11403 unsigned MinParams = Fn->getMinRequiredExplicitArguments() +
11404 ((IsAddressOf && !Fn->isStatic()) ? 1 : 0);
11408 !IsAddressOf && Fn->hasCXXExplicitFunctionObjectParameter();
11411 Fn->getNumNonObjectParams() + ((IsAddressOf && !Fn->isStatic()) ? 1 : 0);
11415 if (MinParams != ParamCount || FnTy->isVariadic() ||
11416 FnTy->isTemplateVariadic())
11419 mode = 2; // "exactly"
11425 mode = 2; // "exactly"
11434 Fn->getParamDecl(HasExplicitObjectParam ? 1 : 0)->getDeclName())
11435 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity_one)
11438 << Fn->getParamDecl(HasExplicitObjectParam ? 1 : 0) << NumFormalArgs
11439 << HasExplicitObjectParam << Fn->getParametersSourceRange();
11441 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
11444 << HasExplicitObjectParam << Fn->getParametersSourceRange();
11452 if (!CheckArityMismatch(S, Cand, NumFormalArgs, Cand->TookAddressOfOverload))
11453 DiagnoseArityMismatch(S, Cand->FoundDecl, Cand->Function, NumFormalArgs,
11454 Cand->TookAddressOfOverload);
11458 if (TemplateDecl *TD = Templated->getDescribedTemplate())
11464 /// Diagnose a failed template-argument deduction.
11487 S.Diag(Templated->getLocation(),
11489 << ParamD->getDeclName();
11496 S.Diag(Templated->getLocation(),
11498 << ParamD->getDeclName()
11499 << (DeductionFailure.getFirstArg()->pack_size() + 1)
11509 QualType Param = DeductionFailure.getFirstArg()->getAsType();
11515 QualType NonCanonParam = Qs.apply(S.Context, TParam->getTypeForDecl());
11522 QualType Arg = DeductionFailure.getSecondArg()->getAsType();
11524 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_underqualified)
11525 << ParamD->getDeclName() << Arg << NonCanonParam;
11537 // different types for a non-type template parameter.
11540 DeductionFailure.getFirstArg()->getNonTypeTemplateArgumentType();
11542 DeductionFailure.getSecondArg()->getNonTypeTemplateArgumentType();
11544 S.Diag(Templated->getLocation(),
11546 << ParamD->getDeclName() << *DeductionFailure.getFirstArg() << T1
11554 which = 2;
11560 if (DeductionFailure.getFirstArg()->getKind() == TemplateArgument::Pack &&
11561 DeductionFailure.getSecondArg()->getKind() == TemplateArgument::Pack &&
11562 DeductionFailure.getFirstArg()->pack_size() !=
11563 DeductionFailure.getSecondArg()->pack_size()) {
11567 S.Diag(Templated->getLocation(),
11569 << which << ParamD->getDeclName() << *DeductionFailure.getFirstArg()
11577 if (ParamD->getDeclName())
11578 S.Diag(Templated->getLocation(),
11580 << ParamD->getDeclName();
11584 index = TTP->getIndex();
11587 index = NTTP->getIndex();
11589 index = cast<TemplateTemplateParmDecl>(ParamD)->getIndex();
11590 S.Diag(Templated->getLocation(),
11603 getDescribedTemplate(Templated)->getTemplateParameters(), *Args);
11606 S.Diag(Templated->getLocation(),
11611 static_cast<CNSInfo*>(DeductionFailure.Data)->Satisfaction);
11620 S.Diag(Templated->getLocation(),
11632 getDescribedTemplate(Templated)->getTemplateParameters(), *Args);
11639 if (PDiag && PDiag->second.getDiagID() ==
11641 // FIXME: Use the source range of the condition, and the fully-qualified
11643 S.Diag(PDiag->first, diag::note_ovl_candidate_disabled_by_enable_if)
11649 if (PDiag && PDiag->second.getDiagID() ==
11651 S.Diag(Templated->getLocation(),
11653 << PDiag->second.getStringArg(0) << TemplateArgString;
11664 R = SourceRange(PDiag->first, PDiag->first);
11665 PDiag->second.EmitToString(S.getDiagnostics(), SFINAEArgString);
11668 S.Diag(Templated->getLocation(),
11683 getDescribedTemplate(Templated)->getTemplateParameters(), *Args);
11688 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_deduced_mismatch)
11707 if (FirstTN.getAsTemplateDecl()->getName() ==
11708 SecondTN.getAsTemplateDecl()->getName()) {
11712 // 2) The diagnostic printer only attempts to find a better
11715 S.Diag(Templated->getLocation(),
11731 S.Diag(Templated->getLocation(),
11739 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_bad_deduction);
11743 S.Diag(Templated->getLocation(),
11749 /// Diagnose a failed template-argument deduction, for function calls.
11753 TemplateDeductionResult TDK = Cand->DeductionFailure.getResult();
11759 DiagnoseBadDeduction(S, Cand->FoundDecl, Cand->Function, // pattern
11760 Cand->DeductionFailure, NumArgs, TakingCandidateAddress);
11766 FunctionDecl *Callee = Cand->Function;
11773 ClassifyOverloadCandidate(S, Cand->FoundDecl, Callee,
11774 Cand->getRewriteKind(), FnDesc);
11776 S.Diag(Callee->getLocation(), diag::note_ovl_candidate_bad_target)
11784 if (Meth != nullptr && Meth->isImplicit()) {
11785 CXXRecordDecl *ParentClass = Meth->getParent();
11809 if (Meth->getNumParams()) {
11811 Meth->getParamDecl(0)->getType()->getAs<ReferenceType>()) {
11812 ConstRHS = RT->getPointeeType().isConstQualified();
11823 FunctionDecl *Callee = Cand->Function;
11824 EnableIfAttr *Attr = static_cast<EnableIfAttr*>(Cand->DeductionFailure.Data);
11826 S.Diag(Callee->getLocation(),
11828 << Attr->getCond()->getSourceRange() << Attr->getMessage();
11832 ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(Cand->Function);
11836 switch (Cand->Function->getDeclKind()) {
11844 Kind = Cand->Function->isImplicit() ? 0 : 2;
11850 // Note the location of the first (in-class) declaration; a redeclaration
11851 // (particularly an out-of-class definition) will typically lack the
11854 FunctionDecl *First = Cand->Function->getFirstDecl();
11855 if (FunctionDecl *Pattern = First->getTemplateInstantiationPattern())
11856 First = Pattern->getFirstDecl();
11858 S.Diag(First->getLocation(),
11861 << (ES.getExpr() ? ES.getExpr()->getSourceRange() : SourceRange());
11869 DG->getDeclName().getCXXDeductionGuideTemplate();
11872 if (!(DG->isImplicit() || (OriginTemplate && OriginTemplate->isTypeAlias())))
11876 FunctionTemplateDecl *Template = DG->getDescribedFunctionTemplate();
11880 DG->getTemplateInstantiationPattern(/*ForDefinition=*/false);
11882 // The implicit deduction guide is built on an explicit non-template
11885 // FIXME: Add a test once https://github.com/llvm/llvm-project/pull/96686
11887 assert(OriginTemplate->isTypeAlias() &&
11888 "Non-template implicit deduction guides are only possible for "
11890 DG->print(OS);
11891 S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide)
11895 Template = Pattern->getDescribedFunctionTemplate();
11899 Template->print(OS);
11900 S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide)
11914 /// It would be great to be able to express per-candidate problems
11923 FunctionDecl *Fn = Cand->Function;
11930 if (S.getLangOpts().OpenCL && Fn->isImplicit() &&
11931 Cand->FailureKind != ovl_fail_bad_conversion)
11936 if (Cand->TookAddressOfOverload &&
11937 !Cand->Function->hasCXXExplicitFunctionObjectParameter() &&
11938 !Cand->Function->isStatic())
11942 if (Cand->Viable) {
11943 if (Fn->isDeleted()) {
11946 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn,
11947 Cand->getRewriteKind(), FnDesc);
11949 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_deleted)
11951 << (Fn->isDeleted() ? (Fn->isDeletedAsWritten() ? 1 : 2) : 0);
11952 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11957 S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind());
11972 switch (Cand->FailureKind) {
11982 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_illegal_constructor)
11983 << (Fn->getPrimaryTemplate() ? 1 : 0);
11984 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
11991 S.Diag(Fn->getLocation(),
11994 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
12001 return S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind());
12004 unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0);
12005 for (unsigned N = Cand->Conversions.size(); I != N; ++I)
12006 if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad())
12010 // when user-conversion overload fails. Figure out how to handle
12012 return S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind());
12026 if (cast<CXXConstructorDecl>(Fn)->isCopyOrMoveConstructor())
12028 S.Diag(Fn->getLocation(),
12030 << (Fn->getPrimaryTemplate() ? 1 : 0)
12031 << Fn->getParamDecl(0)->getType()->isRValueReferenceType();
12032 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
12036 bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function);
12048 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn,
12049 Cand->getRewriteKind(), FnDesc);
12051 S.Diag(Fn->getLocation(),
12064 if (shouldSkipNotingLambdaConversionDecl(Cand->Surrogate))
12070 QualType FnType = Cand->Surrogate->getConversionType();
12075 FnType->getAs<LValueReferenceType>()) {
12076 FnType = FnTypeRef->getPointeeType();
12079 FnType->getAs<RValueReferenceType>()) {
12080 FnType = FnTypeRef->getPointeeType();
12083 if (const PointerType *FnTypePtr = FnType->getAs<PointerType>()) {
12084 FnType = FnTypePtr->getPointeeType();
12088 FnType = QualType(FnType->getAs<FunctionType>(), 0);
12094 if (!Cand->Viable &&
12095 Cand->FailureKind == ovl_fail_constraints_not_satisfied) {
12096 S.Diag(Cand->Surrogate->getLocation(),
12098 << Cand->Surrogate;
12100 if (S.CheckFunctionConstraints(Cand->Surrogate, Satisfaction))
12103 S.Diag(Cand->Surrogate->getLocation(), diag::note_ovl_surrogate_cand)
12111 assert(Cand->Conversions.size() <= 2 && "builtin operator is not binary");
12115 TypeStr += Cand->BuiltinParamTypes[0].getAsString();
12116 if (Cand->Conversions.size() == 1) {
12121 TypeStr += Cand->BuiltinParamTypes[1].getAsString();
12129 for (const ImplicitConversionSequence &ICS : Cand->Conversions) {
12139 if (Cand->Function)
12140 return Cand->Function->getLocation();
12141 if (Cand->IsSurrogate)
12142 return Cand->Surrogate->getLocation();
12151 llvm_unreachable("non-deduction failure while diagnosing bad deduction");
12160 return 2;
12198 // If there are too many or too few arguments, that's the high-order bit we
12200 if (C->FailureKind == ovl_fail_too_many_arguments ||
12201 C->FailureKind == ovl_fail_too_few_arguments)
12202 return static_cast<OverloadFailureKind>(C->FailureKind);
12204 if (C->Function) {
12205 if (NumArgs > C->Function->getNumParams() && !C->Function->isVariadic())
12207 if (NumArgs < C->Function->getMinRequiredArguments())
12211 return static_cast<OverloadFailureKind>(C->FailureKind);
12214 bool operator()(const OverloadCandidate *L,
12216 // Fast-path this check.
12217 if (L == R) return false;
12220 if (L->Viable) {
12221 if (!R->Viable) return true;
12223 if (int Ord = CompareConversions(*L, *R))
12226 } else if (R->Viable)
12229 assert(L->Viable == R->Viable);
12231 // Criteria by which we can sort non-viable candidates:
12232 if (!L->Viable) {
12233 OverloadFailureKind LFailureKind = EffectiveFailureKind(L);
12241 int LDist = std::abs((int)L->getNumParams() - (int)NumArgs);
12242 int RDist = std::abs((int)R->getNumParams() - (int)NumArgs);
12245 // Sort non-surrogates before surrogates.
12246 return !L->IsSurrogate && R->IsSurrogate;
12260 // 2. Bad conversions come first and are ordered by the number
12268 unsigned numLFixes = L->Fix.NumConversionsFixed;
12269 unsigned numRFixes = R->Fix.NumConversionsFixed;
12277 if (int Ord = CompareConversions(*L, *R))
12286 if (L->DeductionFailure.Result != R->DeductionFailure.Result) {
12287 unsigned LRank = RankDeductionFailure(L->DeductionFailure);
12288 unsigned RRank = RankDeductionFailure(R->DeductionFailure);
12299 SourceLocation LLoc = GetLocationForCandidate(L);
12312 return L < R;
12339 // Returns -1 if conversions in L are considered better.
12342 int CompareConversions(const OverloadCandidate &L,
12347 assert(L.Conversions.size() == R.Conversions.size());
12348 for (unsigned I = 0, N = L.Conversions.size(); I != N; ++I) {
12349 auto LS = L.IgnoreObjectArgument && I == 0
12351 : ConversionSignals::ForSequence(L.Conversions[I]);
12357 ? -1
12367 /// CompleteNonViableCandidate - Normally, overload resolution only
12374 assert(!Cand->Viable);
12377 if (Cand->FailureKind != ovl_fail_bad_conversion)
12383 Cand->Fix.setConversionChecker(TryCopyInitialization);
12386 unsigned ConvCount = Cand->Conversions.size();
12387 for (unsigned ConvIdx = (Cand->IgnoreObjectArgument ? 1 : 0); /**/;
12390 if (Cand->Conversions[ConvIdx].isInitialized() &&
12391 Cand->Conversions[ConvIdx].isBad()) {
12392 Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S);
12404 bool Reversed = Cand->isReversed();
12406 if (Cand->IsSurrogate) {
12408 = Cand->Surrogate->getConversionType().getNonReferenceType();
12409 if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>())
12410 ConvType = ConvPtrType->getPointeeType();
12411 ParamTypes = ConvType->castAs<FunctionProtoType>()->getParamTypes();
12414 } else if (Cand->Function) {
12416 Cand->Function->getType()->castAs<FunctionProtoType>()->getParamTypes();
12417 if (isa<CXXMethodDecl>(Cand->Function) &&
12418 !isa<CXXConstructorDecl>(Cand->Function) && !Reversed) {
12422 Cand->Function->getDeclName().getCXXOverloadedOperator() != OO_Call &&
12423 Cand->Function->getDeclName().getCXXOverloadedOperator() !=
12431 ParamTypes = Cand->BuiltinParamTypes;
12435 for (unsigned ParamIdx = Reversed ? ParamTypes.size() - 1 : 0;
12437 ++ConvIdx, ++ArgIdx, ParamIdx += (Reversed ? -1 : 1)) {
12439 if (Cand->Conversions[ConvIdx].isInitialized()) {
12442 if (ParamTypes[ParamIdx]->isDependentType())
12443 Cand->Conversions[ConvIdx].setAsIdentityConversion(
12444 Args[ArgIdx]->getType());
12446 Cand->Conversions[ConvIdx] =
12453 if (!Unfixable && Cand->Conversions[ConvIdx].isBad())
12454 Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S);
12457 Cand->Conversions[ConvIdx].setEllipsis();
12474 if (!Cand->Viable) {
12475 if (!Cand->Function && !Cand->IsSurrogate) {
12476 // This a non-viable builtin candidate. We do not, in general,
12485 if (!Cand->Viable)
12490 if (!Cand->Best)
12508 // Defer diagnostic for CUDA/HIP if there are wrong-sided candidates or
12515 Cand.Function->template hasAttr<CUDAHostAttr>() &&
12516 Cand.Function->template hasAttr<CUDADeviceAttr>());
12538 if (Arg->getType()->isWebAssemblyTableType())
12566 if (Cand->Function)
12569 else if (Cand->IsSurrogate)
12572 assert(Cand->Viable &&
12573 "Non-viable built-in candidates are not added to Cands.");
12576 // ambiguous user-defined conversion.
12597 << int(E - I);
12602 return Cand->Specialization ? Cand->Specialization->getLocation()
12611 bool operator()(const TemplateSpecCandidate *L,
12613 // Fast-path this check.
12614 if (L == R)
12620 if (L->DeductionFailure.Result != R->DeductionFailure.Result)
12621 return RankDeductionFailure(L->DeductionFailure) <
12622 RankDeductionFailure(R->DeductionFailure);
12625 SourceLocation LLoc = GetLocationForCandidate(L);
12650 i->DeductionFailure.Destroy();
12659 /// NoteCandidates - When no template specialization match is found, prints
12660 /// diagnostic messages containing the non-matching specializations that form
12663 /// OCD == OCD_AllCandidates and Cand->Viable == false.
12671 if (Cand->Specialization)
12673 // Otherwise, this is a non-matching builtin candidate. We do not,
12695 assert(Cand->Specialization &&
12696 "Non-matching built-in candidates are not added to Cands.");
12697 Cand->NoteDeductionFailure(S, ForTakingAddress);
12701 S.Diag(Loc, diag::note_ovl_too_many_candidates) << int(E - I);
12704 // [PossiblyAFunctionType] --> [Return]
12705 // NonFunctionType --> NonFunctionType
12706 // R (A) --> R(A)
12707 // R (*)(A) --> R (A)
12708 // R (&)(A) --> R (A)
12709 // R (S::*)(A) --> R (A)
12713 PossiblyAFunctionType->getAs<PointerType>())
12714 Ret = ToTypePtr->getPointeeType();
12716 PossiblyAFunctionType->getAs<ReferenceType>())
12717 Ret = ToTypeRef->getPointeeType();
12719 PossiblyAFunctionType->getAs<MemberPointerType>())
12720 Ret = MemTypePtr->getPointeeType();
12728 if (S.getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() &&
12732 auto *FPT = FD->getType()->castAs<FunctionProtoType>();
12734 isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) &&
12743 // - allows us to avoid passing around all those ugly parameters
12771 !!TargetType->getAs<MemberPointerType>()),
12777 FailedCandidates(OvlExpr->getNameLoc(), /*ForTakingAddress=*/true) {
12780 if (TargetFunctionType->isFunctionType()) {
12782 if (!UME->isImplicitAccess() &&
12785 } else if (OvlExpr->hasExplicitTemplateArgs()) {
12790 if (!Method->isStatic()) {
12791 // If the target type is a non-function type and the function found
12792 // is a non-static member function, pretend as if that was the
12807 if (OvlExpr->hasExplicitTemplateArgs())
12808 OvlExpr->copyTemplateArgumentsInto(OvlExplicitTemplateArgs);
12830 return Context.hasSameUnqualifiedType(TargetFunctionType, FD->getType()) ||
12831 S.IsFunctionConversion(FD->getType(), TargetFunctionType, Discard);
12848 // Same algorithm as overload resolution -- one pass to pick the "best",
12852 if (isBetterCandidate(I->second, Best->second))
12855 const FunctionDecl *BestFn = Best->second;
12871 return TargetFunctionType->isFunctionType();
12876 // R (*)(A) --> R (A), IsNonStaticMemberFunction = false
12877 // R (&)(A) --> R (A), IsNonStaticMemberFunction = false
12878 // R (S::*)(A) --> R (A), IsNonStaticMemberFunction = true
12887 = dyn_cast<CXXMethodDecl>(FunctionTemplate->getTemplatedDecl())) {
12888 // Skip non-static function templates when converting to pointer, and
12891 Method->isStatic() || Method->isExplicitObjectMemberFunction();
12912 .set(CurAccessFunPair, FunctionTemplate->getTemplatedDecl(),
12918 // compatible pointer-to-function arguments that would be adjusted by ICS.
12921 Context.getCanonicalType(Specialization->getType()),
12934 // Skip non-static functions when converting to pointer, and static
12937 Method->isStatic() || Method->isExplicitObjectMemberFunction();
12947 if (!(Caller && Caller->isImplicit()) &&
12951 if (FunDecl->isMultiVersion()) {
12952 const auto *TA = FunDecl->getAttr<TargetAttr>();
12953 if (TA && !TA->isDefaultVersion())
12955 const auto *TVA = FunDecl->getAttr<TargetVersionAttr>();
12956 if (TVA && !TVA->isDefaultVersion())
12962 if (completeFunctionType(S, FunDecl, SourceExpr->getBeginLoc(),
12975 CurAccessFunPair, cast<FunctionDecl>(FunDecl->getCanonicalDecl())));
12988 // member, don't try to convert it to a pointer-to-member type.
12992 for (UnresolvedSetIterator I = OvlExpr->decls_begin(),
12993 E = OvlExpr->decls_end();
12996 NamedDecl *Fn = (*I)->getUnderlyingDecl();
12999 // Non-member functions and static member functions match
13000 // targets of type "pointer-to-function" or "reference-to-function."
13002 // type "pointer-to-member-function."
13009 // If we have explicit template arguments supplied, skip non-templates.
13010 else if (!OvlExpr->hasExplicitTemplateArgs() &&
13026 // two-pass algorithm (similar to the one used to identify the
13038 SourceExpr->getBeginLoc(), S.PDiag(),
13040 << Matches[0].second->getDeclName(),
13047 Matches[0].first = Matches[Result - MatchesCopy.begin()].first;
13056 // eliminated if the set also contains a non-template function, [...]
13058 if (Matches[I].second->getPrimaryTemplate() == nullptr)
13061 Matches[I] = Matches[--N];
13075 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_no_viable)
13076 << OvlExpr->getName() << TargetFunctionType
13077 << OvlExpr->getSourceRange();
13083 // the function templates, and diagnose the non-template candidates
13085 for (UnresolvedSetIterator I = OvlExpr->decls_begin(),
13086 IEnd = OvlExpr->decls_end();
13089 dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl()))
13093 FailedCandidates.NoteCandidates(S, OvlExpr->getBeginLoc());
13106 S.Diag(OvlExpr->getNameLoc(), diag::err_addr_ovl_no_qualifier)
13107 << TargetType << OvlExpr->getSourceRange();
13115 S.Diag(OvlExpr->getBeginLoc(),
13117 << OvlExpr->getSourceRange();
13121 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_not_func_ptrref)
13122 << OvlExpr->getName() << TargetType;
13127 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_ambiguous)
13128 << OvlExpr->getName() << OvlExpr->getSourceRange();
13133 bool hadMultipleCandidates() const { return (OvlExpr->getNumDecls() > 1); }
13155 assert(AddressOfExpr->getType() == Context.OverloadTy);
13173 if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>())
13174 ResolveExceptionSpec(AddressOfExpr->getExprLoc(), FPT);
13192 OverloadExpr *Ovl = R.Expression;
13196 SmallVector<FunctionDecl *, 2> AmbiguousDecls;
13201 return static_cast<int>(CUDA().IdentifyPreference(Caller, FD1)) -
13208 for (auto I = Ovl->decls_begin(), E = Ovl->decls_end(); I != E; ++I) {
13209 auto *FD = dyn_cast<FunctionDecl>(I->getUnderlyingDecl());
13223 // We have more than one result - see if it is more constrained than the
13249 // FD is more constrained - replace Result with it.
13278 assert(E->getType() == Context.OverloadTy && "SrcExpr must be an overload");
13282 if (!Found || Found->isCPUDispatchMultiVersion() ||
13283 Found->isCPUSpecificMultiVersion())
13289 DiagnoseUseOfDecl(Found, E->getExprLoc());
13295 if (DoFunctionPointerConversion && Fixed->getType()->isFunctionType())
13303 OverloadExpr *ovl, bool Complain, DeclAccessPair *FoundResult,
13312 // If we didn't actually find any template-ids, we're done.
13313 if (!ovl->hasExplicitTemplateArgs())
13317 ovl->copyTemplateArgumentsInto(ExplicitTemplateArgs);
13322 for (UnresolvedSetIterator I = ovl->decls_begin(),
13323 E = ovl->decls_end(); I != E; ++I) {
13329 // template-id is an lvalue for the function template specialization.
13331 = cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl());
13340 TemplateDeductionInfo Info(ovl->getNameLoc());
13347 FailedTSC->addCandidate().set(
13348 I.getPair(), FunctionTemplate->getTemplatedDecl(),
13358 Diag(ovl->getExprLoc(), diag::err_addr_ovl_ambiguous)
13359 << ovl->getName();
13360 NoteAllOverloadCandidates(ovl);
13370 completeFunctionType(*this, Matched, ovl->getExprLoc(), Complain))
13380 assert(SrcExpr.get()->getType() == Context.OverloadTy);
13382 OverloadExpr::FindResult ovl = OverloadExpr::find(SrcExpr.get());
13387 ovl.Expression, /*complain*/ false, &found)) {
13388 if (DiagnoseUseOfDecl(fn, SrcExpr.get()->getBeginLoc())) {
13397 if (!ovl.HasFormOfMemberPointer &&
13399 cast<CXXMethodDecl>(fn)->isInstance()) {
13402 Diag(ovl.Expression->getExprLoc(),
13404 << 0 << ovl.Expression->getSourceRange();
13407 // static and non-static candidates (otherwise the expression
13419 // If desired, do function-to-pointer decay.
13433 << ovl.Expression->getName()
13436 << ovl.Expression->getQualifierLoc().getSourceRange();
13460 Callee = cast<UsingShadowDecl>(Callee)->getTargetDecl();
13467 // Prevent ill-formed function decls to be added as overload candidates.
13468 if (!isa<FunctionProtoType>(Func->getType()->getAs<FunctionType>()))
13502 // -- a declaration of a class member, or
13504 // -- a block-scope function declaration that is not a
13505 // using-declaration, or
13507 // -- a declaration that is neither a function or a function
13512 if (ULE->requiresADL()) {
13513 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
13514 E = ULE->decls_end(); I != E; ++I) {
13515 assert(!(*I)->getDeclContext()->isRecord());
13517 !(*I)->getDeclContext()->isFunctionOrMethod());
13518 assert((*I)->getUnderlyingDecl()->isFunctionOrFunctionTemplate());
13526 if (ULE->hasExplicitTemplateArgs()) {
13527 ULE->copyTemplateArgumentsInto(TABuffer);
13531 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
13532 E = ULE->decls_end(); I != E; ++I)
13537 if (ULE->requiresADL())
13538 AddArgumentDependentLookupCandidates(ULE->getName(), ULE->getExprLoc(),
13564 /// Attempt to recover from an ill-formed use of a non-dependent name in a
13565 /// template, where the non-dependent name was declared after the template
13567 /// correctly implement two-stage name lookup.
13578 for (DeclContext *DC = SemaRef.CurContext; DC; DC = DC->getParent()) {
13579 if (DC->isTransparentContext())
13596 // We either found non-function declarations or a best viable function
13597 // at class scope. A class-scope lookup result disables ADL. Don't
13604 R.addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess());
13630 if (Std && Std->Encloses(*it))
13637 NS->getQualifiedNameAsString().find("__") != std::string::npos)
13647 SemaRef.Diag(Best->Function->getLocation(),
13651 SemaRef.Diag(Best->Function->getLocation(),
13658 SemaRef.Diag(Best->Function->getLocation(),
13660 << R.getLookupName() << 2;
13673 /// Attempt to recover from ill-formed use of a non-dependent operator in a
13674 /// template, where the non-dependent operator was declared after the template
13722 // template <typename T> auto foo(T t) -> decltype(foo(t)) {}
13723 // template <typename T> auto foo(T t) -> decltype(foo(&t)) {}
13729 SS.Adopt(ULE->getQualifierLoc());
13730 SourceLocation TemplateKWLoc = ULE->getTemplateKeywordLoc();
13734 if (ULE->hasExplicitTemplateArgs()) {
13735 ULE->copyTemplateArgumentsInto(TABuffer);
13739 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
13742 if (DiagnoseTwoPhaseLookup(SemaRef, Fn->getExprLoc(), SS, R,
13745 // OK, diagnosed a two-phase lookup issue.
13786 if ((*R.begin())->isCXXClassMember())
13813 if (ULE->requiresADL()) {
13815 assert(!ULE->getQualifier() && "qualified name with ADL");
13820 if (ULE->decls_begin() != ULE->decls_end() &&
13821 ULE->decls_begin() + 1 == ULE->decls_end() &&
13822 (F = dyn_cast<FunctionDecl>(*ULE->decls_begin())) &&
13823 F->getBuiltinID() && F->isImplicit())
13838 // functions, including those from argument-dependent lookup.
13842 CurContext->isDependentContext() && !isSFINAEContext() &&
13846 if (CandidateSet->empty() ||
13847 CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best) ==
13856 CE->markDependentForPostponedNameLookup();
13862 if (CandidateSet->empty())
13877 if (Candidate.Function->isInvalidDecl())
13879 QualType T = Candidate.Function->getReturnType();
13907 if (Value.isNull() || Value->isUndeducedType())
13912 /// FinishOverloadedCallExpr - given an OverloadCandidateSet, builds and returns
13927 FunctionDecl *FDecl = (*Best)->Function;
13928 SemaRef.CheckUnresolvedLookupAccess(ULE, (*Best)->FoundDecl);
13929 if (SemaRef.DiagnoseUseOfDecl(FDecl, ULE->getNameLoc()))
13932 SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl);
13937 /*IsExecConfig=*/false, (*Best)->IsADLCandidate);
13941 if (*Best != CandidateSet->end() &&
13942 CandidateSet->getKind() ==
13945 dyn_cast_if_present<CXXMethodDecl>((*Best)->Function);
13946 M && M->isImplicitObjectMemberFunction()) {
13947 CandidateSet->NoteCandidates(
13949 Fn->getBeginLoc(),
13960 CandidateSet->empty(),
13969 if (!Arg->getType()->isFunctionType())
13971 if (auto *DRE = dyn_cast<DeclRefExpr>(Arg->IgnoreParenImpCasts())) {
13972 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
13975 Arg->getExprLoc()))
13980 CandidateSet->NoteCandidates(
13982 Fn->getBeginLoc(),
13984 << ULE->getName() << Fn->getSourceRange()),
13990 CandidateSet->NoteCandidates(
13991 PartialDiagnosticAt(Fn->getBeginLoc(),
13993 << ULE->getName() << Fn->getSourceRange()),
13998 FunctionDecl *FDecl = (*Best)->Function;
13999 SemaRef.DiagnoseUseOfDeletedFunction(Fn->getBeginLoc(),
14000 Fn->getSourceRange(), ULE->getName(),
14006 SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl);
14011 /*IsExecConfig=*/false, (*Best)->IsADLCandidate);
14018 return SemaRef.CreateRecoveryExpr(Fn->getBeginLoc(), RParenLoc, SubExprs,
14025 if (I->Viable &&
14026 !S.checkAddressOfFunctionIsAvailable(I->Function, /*Complain=*/false)) {
14027 I->Viable = false;
14028 I->FailureKind = ovl_fail_addr_not_available;
14042 Fn->getExprLoc(), CalleesAddressIsTaken
14058 CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
14062 // the UnresolvedLookupExpr was type-dependent.
14064 const FunctionDecl *FDecl = Best->Function;
14065 if (FDecl && FDecl->isTemplateInstantiation() &&
14066 FDecl->getReturnType()->isUndeducedType()) {
14068 FDecl->getTemplateInstantiationPattern(/*ForDefinition=*/false);
14069 TP && TP->willHaveBody()) {
14097 if (Method->isExplicitObjectMemberFunction())
14105 if (Method->getParent()->isLambda() &&
14106 Method->getConversionType()->isBlockPointerType()) {
14111 if (CE && CE->getCastKind() == CK_NoOp)
14112 SubE = CE->getSubExpr();
14113 SubE = SubE->IgnoreParens();
14115 SubE = BE->getSubExpr();
14125 Exp.get()->getExprLoc(), Exp.get()->getExprLoc(), Method, Exp.get());
14130 Diag(Exp.get()->getExprLoc(), diag::note_lambda_to_block_conv);
14135 QualType ResultType = Method->getReturnType();
14138 if (Method->isExplicitObjectMemberFunction()) {
14141 HadMultipleCandidates, E->getBeginLoc());
14146 ResultType, VK, Exp.get()->getEndLoc(),
14152 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
14157 Exp.get()->getEndLoc(),
14162 Method->getType()->castAs<FunctionProtoType>()))
14165 return CheckForImmediateInvocation(CE, CE->getDirectCallee());
14181 Expr *Args[2] = { Input, nullptr };
14184 // For post-increment and post-decrement, add the implicit '0' as
14185 // the second argument, so that we know this is a post-increment or
14186 // post-decrement.
14191 NumArgs = 2;
14196 if (Input->isTypeDependent()) {
14244 // We found a built-in operator or an overloaded operator.
14245 FunctionDecl *FnDecl = Best->Function;
14254 CheckMemberOperatorAccess(OpLoc, Input, nullptr, Best->FoundDecl);
14257 if (Method->isExplicitObjectMemberFunction())
14261 Input, /*Qualifier=*/nullptr, Best->FoundDecl, Method);
14270 FnDecl->getParamDecl(0)),
14279 ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, Best->FoundDecl,
14286 QualType ResultTy = FnDecl->getReturnType();
14293 CurFPFeatureOverrides(), Best->IsADLCandidate);
14295 if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl))
14299 FnDecl->getType()->castAs<FunctionProtoType>()))
14303 // We matched a built-in operator. Convert the arguments, then
14304 // break out so that we will build the appropriate built-in
14307 Input, Best->BuiltinParamTypes[0], Best->Conversions[0], AA_Passing,
14318 // a non-member function. Check for non-member operators which were
14325 // built-in operator, which will produce an error message for us.
14333 << Input->getType() << Input->getSourceRange()),
14344 StringLiteral *Msg = Best->Function->getDeletedMessage();
14349 << (Msg ? Msg->getString() : StringRef())
14350 << Input->getSourceRange()),
14358 // built-in operator. In either case, fall through to trying to
14359 // build a built-in operation.
14394 // performed for an assignment operator (nor for operator[] nor operator->,
14413 // incorrect; a builtin candidate could be hidden by a non-viable candidate,
14432 Expr *Args[2] = { LHS, RHS };
14440 // If either side is type-dependent, create an appropriate dependent
14442 if (Args[0]->isTypeDependent() || Args[1]->isTypeDependent()) {
14471 // create a built-in binary operator.
14487 // Always do placeholder-like conversions on the RHS.
14491 // Do placeholder-like conversion on the LHS; note that we should
14493 assert(Args[0]->getObjectKind() != OK_ObjCProperty);
14498 // if the left-hand side is a class or enumeration type. This is actually
14500 // various built-in candidates, but as DR507 points out, this can lead to
14503 if (Opc == BO_Assign && !Args[0]->getType()->isOverloadableType())
14520 // We found a built-in operator or an overloaded operator.
14521 FunctionDecl *FnDecl = Best->Function;
14523 bool IsReversed = Best->isReversed();
14529 if (FnDecl->isInvalidDecl())
14537 FnDecl->getDeclName().getCXXOverloadedOperator();
14539 // C++2a [over.match.oper]p9:
14542 if (Best->RewriteKind && ChosenOp == OO_EqualEqual &&
14543 !FnDecl->getReturnType()->isBooleanType()) {
14545 FnDecl->getReturnType()->isIntegralOrUnscopedEnumerationType();
14548 << FnDecl->getReturnType() << BinaryOperator::getOpcodeStr(Opc)
14549 << Args[0]->getSourceRange() << Args[1]->getSourceRange();
14550 Diag(FnDecl->getLocation(), diag::note_declared_at);
14565 for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) {
14568 Best->Conversions[ArgIdx]) ==
14583 << Args[0]->getType() << Args[1]->getType() << AmbiguousWithSelf
14584 << Args[0]->getSourceRange() << Args[1]->getSourceRange();
14586 Diag(FnDecl->getLocation(),
14594 !MD->isConst() &&
14595 !MD->hasCXXExplicitFunctionObjectParameter() &&
14597 MD->getFunctionObjectParameterType(),
14598 MD->getParamDecl(0)->getType().getNonReferenceType()) &&
14600 MD->getFunctionObjectParameterType(),
14601 Args[0]->getType()) &&
14603 MD->getFunctionObjectParameterType(),
14604 Args[1]->getType()))
14605 Diag(FnDecl->getLocation(),
14608 Diag(FnDecl->getLocation(),
14611 Diag(F->getLocation(),
14621 diagnoseNullableToNonnullConversion(Args[0]->getType(),
14622 Args[1]->getType(), OpLoc);
14626 // Best->Access is only meaningful for class members.
14627 CheckMemberOperatorAccess(OpLoc, Args[0], Args[1], Best->FoundDecl);
14631 if (Method->isExplicitObjectMemberFunction()) {
14636 Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method);
14640 Context, FnDecl->getParamDecl(ParamIdx)),
14651 FnDecl->getParamDecl(0)),
14659 FnDecl->getParamDecl(1)),
14669 Best->FoundDecl, Base,
14675 QualType ResultTy = FnDecl->getReturnType();
14680 ArrayRef<const Expr *> ArgsArray(Args, 2);
14687 CurFPFeatureOverrides(), Best->IsADLCandidate);
14690 Method && Method->isImplicitObjectMemberFunction()) {
14696 if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall,
14707 QualType ThisType = Context.getPointerType(ImplicitThis->getType());
14709 cast<CXXMethodDecl>(FnDecl)->getFunctionObjectParameterType());
14716 isa<CXXMethodDecl>(FnDecl), OpLoc, TheCall->getSourceRange(),
14729 if ((Best->RewriteKind & CRK_DifferentOperator) ||
14759 if (Best->RewriteKind != CRK_None)
14764 // We matched a built-in operator. Convert the arguments, then
14765 // break out so that we will build the appropriate built-in
14768 Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0],
14775 Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1],
14788 // built-in operator and interpreted according to clause 5.
14792 // When defaulting an 'operator<=>', we can try to synthesize a three-way
14802 // operator do not fall through to handling in built-in, but report that
14810 if (Args[0]->getType()->isRecordType() &&
14814 << Args[0]->getSourceRange() << Args[1]->getSourceRange();
14815 if (Args[0]->getType()->isIncompleteType()) {
14817 << Args[0]->getType()
14818 << Args[0]->getSourceRange() << Args[1]->getSourceRange();
14822 // a non-member function. Check for non-member operators which were
14828 // No viable function; try to create a built-in operation, which will
14829 // produce an error. Then, show the non-viable candidates.
14842 << Args[0]->getType()
14843 << Args[1]->getType()
14844 << Args[0]->getSourceRange()
14845 << Args[1]->getSourceRange()),
14851 if (isImplicitlyDeleted(Best->Function)) {
14852 FunctionDecl *DeletedFD = Best->Function;
14856 << Args[0]->getType()
14861 << Args[0]->getType() << DeletedFD;
14870 StringLiteral *Msg = Best->Function->getDeletedMessage();
14875 << getOperatorSpelling(Best->Function->getDeclName()
14877 << (Msg != nullptr) << (Msg ? Msg->getString() : StringRef())
14878 << Args[0]->getSourceRange() << Args[1]->getSourceRange()),
14885 // We matched a built-in operator; build it.
14893 Context.CompCategories.lookupInfoForType(DefaultedFn->getReturnType());
14895 // synthesize a three-way comparison. Let the caller diagnose this.
14901 assert(LHS->isGLValue() && RHS->isGLValue() &&
14909 OpaqueValueExpr(LHS->getExprLoc(), LHS->getType(), LHS->getValueKind(),
14910 LHS->getObjectKind(), LHS);
14912 OpaqueValueExpr(RHS->getExprLoc(), RHS->getType(), RHS->getValueKind(),
14913 RHS->getObjectKind(), RHS);
14926 if (Info->isPartial()) {
14938 { {Eq, Info->isStrong() ? ComparisonCategoryResult::Equal
14945 int I = Info->isPartial() ? 3 : 2;
14949 for (; I >= 0; --I) {
14951 auto *VI = Info->lookupValueInfo(Comparisons[I].Result);
14956 BuildDeclarationNameExpr(CXXScopeSpec(), DeclarationNameInfo(), VI->VD);
14974 Context, OrigLHS, OrigRHS, BO_Cmp, Result.get()->getType(),
14975 Result.get()->getValueKind(), Result.get()->getObjectKind(), OpLoc,
14978 return PseudoObjectExpr::Create(Context, SyntacticForm, SemanticForm, 2);
14985 const auto *Proto = Method->getType()->castAs<FunctionProtoType>();
14986 unsigned NumParams = Proto->getNumParams();
15001 S.Context, Method->getParamDecl(i)),
15007 S.BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i));
15024 SmallVector<Expr *, 2> Args;
15034 : SourceRange(ArgExpr.front()->getBeginLoc(),
15035 ArgExpr.back()->getEndLoc());
15037 // If either side is type-dependent, create an appropriate dependent
15070 if (Args.size() == 2)
15079 // We found a built-in operator or an overloaded operator.
15080 FunctionDecl *FnDecl = Best->Function;
15086 CheckMemberOperatorAccess(LLoc, Args[0], ArgExpr, Best->FoundDecl);
15090 SmallVector<Expr *, 2> MethodArgs;
15093 if (Method->isExplicitObjectMemberFunction()) {
15102 Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method);
15118 *this, FnDecl, Best->FoundDecl, Base, HadMultipleCandidates,
15124 QualType ResultTy = FnDecl->getReturnType();
15132 if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl))
15136 Method->getType()->castAs<FunctionProtoType>()))
15142 // We matched a built-in operator. Convert the arguments, then
15143 // break out so that we will build the appropriate built-in
15146 Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0],
15153 Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1],
15167 << Args[0]->getType() << /*subscript*/ 0
15168 << Args[0]->getSourceRange() << Range)
15170 << Args[0]->getType() << Args[0]->getSourceRange() << Range);
15177 if (Args.size() == 2) {
15181 << "[]" << Args[0]->getType() << Args[1]->getType()
15182 << Args[0]->getSourceRange() << Range),
15188 << Args[0]->getType()
15189 << Args[0]->getSourceRange() << Range),
15195 StringLiteral *Msg = Best->Function->getDeletedMessage();
15200 << (Msg ? Msg->getString() : StringRef())
15201 << Args[0]->getSourceRange() << Range),
15207 // We matched a built-in operator; build it.
15217 assert(MemExprE->getType() == Context.BoundMemberTy ||
15218 MemExprE->getType() == Context.OverloadTy);
15222 Expr *NakedMemExpr = MemExprE->IgnoreParens();
15224 // Determine whether this is a call to a pointer-to-member function.
15226 assert(op->getType() == Context.BoundMemberTy);
15227 assert(op->getOpcode() == BO_PtrMemD || op->getOpcode() == BO_PtrMemI);
15230 op->getRHS()->getType()->castAs<MemberPointerType>()->getPointeeType();
15232 const FunctionProtoType *proto = fnType->castAs<FunctionProtoType>();
15233 QualType resultType = proto->getCallResultType(Context);
15234 ExprValueKind valueKind = Expr::getValueKindForType(proto->getReturnType());
15238 Qualifiers funcQuals = proto->getMethodQuals();
15240 QualType objectType = op->getLHS()->getType();
15241 if (op->getOpcode() == BO_PtrMemI)
15242 objectType = objectType->castAs<PointerType>()->getPointeeType();
15245 Qualifiers difference = objectQuals - funcQuals;
15253 << (qualsString.find(' ') == std::string::npos ? 1 : 2);
15258 CurFPFeatureOverrides(), proto->getNumParams());
15260 if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getBeginLoc(),
15281 return CreateRecoveryExpr(MemExprE->getBeginLoc(), RParenLoc, SubExprs,
15299 Method = cast<CXXMethodDecl>(MemExpr->getMemberDecl());
15300 FoundDecl = MemExpr->getFoundDecl();
15301 Qualifier = MemExpr->getQualifier();
15305 Qualifier = UnresExpr->getQualifier();
15307 QualType ObjectType = UnresExpr->getBaseType();
15309 = UnresExpr->isArrow()? Expr::Classification::makeSimpleLValue()
15310 : UnresExpr->getBase()->Classify(Context);
15313 OverloadCandidateSet CandidateSet(UnresExpr->getMemberLoc(),
15318 if (UnresExpr->hasExplicitTemplateArgs()) {
15319 UnresExpr->copyTemplateArgumentsInto(TemplateArgsBuffer);
15323 for (UnresolvedMemberExpr::decls_iterator I = UnresExpr->decls_begin(),
15324 E = UnresExpr->decls_end(); I != E; ++I) {
15329 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(Func->getDeclContext());
15331 Func = cast<UsingShadowDecl>(Func)->getTargetDecl();
15335 M && M->hasCXXExplicitFunctionObjectParameter())
15339 M->getTemplatedDecl()->hasCXXExplicitFunctionObjectParameter())
15352 // non-template member function.
15370 DeclarationName DeclName = UnresExpr->getMemberName();
15376 switch (CandidateSet.BestViableFunction(*this, UnresExpr->getBeginLoc(),
15379 Method = cast<CXXMethodDecl>(Best->Function);
15380 FoundDecl = Best->FoundDecl;
15381 CheckUnresolvedMemberAccess(UnresExpr, Best->FoundDecl);
15382 if (DiagnoseUseOfOverloadedDecl(Best->FoundDecl, UnresExpr->getNameLoc()))
15391 DiagnoseUseOfOverloadedDecl(Method, UnresExpr->getNameLoc()))
15399 UnresExpr->getMemberLoc(),
15401 << DeclName << MemExprE->getSourceRange()),
15406 PartialDiagnosticAt(UnresExpr->getMemberLoc(),
15408 << DeclName << MemExprE->getSourceRange()),
15413 UnresExpr->getMemberLoc(), MemExprE->getSourceRange(), DeclName,
15414 CandidateSet, Best->Function, Args, /*IsMember=*/true);
15428 // build a non-member call based on that function.
15429 if (Method->isStatic()) {
15434 MemExpr = cast<MemberExpr>(MemExprE->IgnoreParens());
15437 QualType ResultType = Method->getReturnType();
15442 const auto *Proto = Method->getType()->castAs<FunctionProtoType>();
15446 if (Method->isExplicitObjectMemberFunction()) {
15447 if (PrepareExplicitObjectArgument(*this, Method, MemExpr->getBase(), Args,
15454 HadMultipleCandidates, MemExpr->getExprLoc());
15460 CurFPFeatureOverrides(), Proto->getNumParams());
15462 // Convert the object argument (for a non-static member function call).
15466 MemExpr->getBase(), Qualifier, FoundDecl, Method);
15469 MemExpr->setBase(ObjectArg.get());
15472 Proto->getNumParams());
15476 if (CheckCallReturnType(Method->getReturnType(), MemExpr->getMemberLoc(),
15492 // that here, so it will not hide previous -- and more relevant -- errors.
15496 Diag(MemE->getMemberLoc(),
15498 << Method << Method->getSourceRange();
15499 Diag(Method->getLocation(),
15501 << Attr->getCond()->getSourceRange() << Attr->getMessage();
15507 TheCall->getDirectCallee()->isPureVirtual()) {
15508 const FunctionDecl *MD = TheCall->getDirectCallee();
15510 if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts()) &&
15511 MemExpr->performsVirtualDispatch(getLangOpts())) {
15512 Diag(MemExpr->getBeginLoc(),
15514 << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext)
15515 << MD->getParent();
15517 Diag(MD->getBeginLoc(), diag::note_previous_decl) << MD->getDeclName();
15519 Diag(MemExpr->getBeginLoc(), diag::note_pure_qualified_call_kext)
15520 << MD->getParent() << MD->getDeclName();
15524 if (auto *DD = dyn_cast<CXXDestructorDecl>(TheCall->getDirectCallee())) {
15525 // a->A::f() doesn't go through the vtable, except in AppleKext mode.
15526 bool CallCanBeVirtual = !MemExpr->hasQualifier() || getLangOpts().AppleKext;
15527 CheckVirtualDtorCall(DD, MemExpr->getBeginLoc(), /*IsDelete=*/false,
15529 MemExpr->getMemberLoc());
15533 TheCall->getDirectCallee());
15549 assert(Object.get()->getType()->isRecordType() &&
15553 // If the primary-expression E in the function call syntax
15563 if (RequireCompleteType(LParenLoc, Object.get()->getType(),
15567 const auto *Record = Object.get()->getType()->castAs<RecordType>();
15569 LookupQualifiedName(R, Record->getDecl());
15574 AddMethodCandidate(Oper.getPair(), Object.get()->getType(),
15575 Object.get()->Classify(Context), Args, CandidateSet,
15586 // showing 2 failed overloads instead of one.
15588 if (CandidateSet.size() == 1 && Record->getAsCXXRecordDecl()->isLambda()) {
15596 // In addition, for each (non-explicit in C++0x) conversion function
15599 // operator conversion-type-id () cv-qualifier;
15601 // where cv-qualifier is the same cv-qualification as, or a
15602 // greater cv-qualification than, cv, and where conversion-type-id
15613 cast<CXXRecordDecl>(Record->getDecl())->getVisibleConversionFunctions();
15617 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext());
15619 D = cast<UsingShadowDecl>(D)->getTargetDecl();
15627 if (!Conv->isExplicit()) {
15630 QualType ConvType = Conv->getConversionType().getNonReferenceType();
15631 if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>())
15632 ConvType = ConvPtrType->getPointeeType();
15634 if (const FunctionProtoType *Proto = ConvType->getAs<FunctionProtoType>())
15646 switch (CandidateSet.BestViableFunction(*this, Object.get()->getBeginLoc(),
15657 << Object.get()->getType() << /*call*/ 1
15658 << Object.get()->getSourceRange())
15660 << Object.get()->getType() << Object.get()->getSourceRange());
15662 PartialDiagnosticAt(Object.get()->getBeginLoc(), PD), *this,
15669 PartialDiagnosticAt(Object.get()->getBeginLoc(),
15671 << Object.get()->getType()
15672 << Object.get()->getSourceRange()),
15679 // 2. we already issue err_deleted_function_use for this later on anyway.
15680 StringLiteral *Msg = Best->Function->getDeletedMessage();
15682 PartialDiagnosticAt(Object.get()->getBeginLoc(),
15684 << Object.get()->getType() << (Msg != nullptr)
15685 << (Msg ? Msg->getString() : StringRef())
15686 << Object.get()->getSourceRange()),
15697 if (Best->Function == nullptr) {
15702 Best->Conversions[0].UserDefined.ConversionFunction);
15705 Best->FoundDecl);
15706 if (DiagnoseUseOfDecl(Best->FoundDecl, LParenLoc))
15708 assert(Conv == Best->FoundDecl.getDecl() &&
15709 "Found Decl & conversion-to-functionptr should be same, right?!");
15716 ExprResult Call = BuildCXXMemberCallExpr(Object.get(), Best->FoundDecl,
15722 Context, Call.get()->getType(), CK_UserDefinedConversion, Call.get(),
15728 CheckMemberOperatorAccess(LParenLoc, Object.get(), nullptr, Best->FoundDecl);
15733 CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function);
15736 if (Method->isInvalidDecl())
15739 const auto *Proto = Method->getType()->castAs<FunctionProtoType>();
15740 unsigned NumParams = Proto->getNumParams();
15745 ExprResult NewFn = CreateFunctionRefExpr(*this, Method, Best->FoundDecl,
15759 if (Method->isExplicitObjectMemberFunction()) {
15763 Object.get(), /*Qualifier=*/nullptr, Best->FoundDecl, Method);
15775 if (Proto->isVariadic()) {
15791 QualType ResultTy = Method->getReturnType();
15799 if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
15811 assert(Base->getType()->isRecordType() &&
15812 "left-hand side must have class type");
15817 SourceLocation Loc = Base->getExprLoc();
15821 // [...] An expression x->m is interpreted as (x.operator->())->m
15822 // for a class object x of type T if T::operator->() exists and if
15829 if (RequireCompleteType(Loc, Base->getType(),
15834 LookupQualifiedName(R, Base->getType()->castAs<RecordType>()->getDecl());
15839 AddMethodCandidate(Oper.getPair(), Base->getType(), Base->Classify(Context),
15856 QualType BaseType = Base->getType();
15864 << BaseType << Base->getSourceRange();
15865 if (BaseType->isRecordType() && !BaseType->isPointerType()) {
15871 << "operator->" << Base->getSourceRange();
15879 << "->" << Base->getType()
15880 << Base->getSourceRange()),
15885 StringLiteral *Msg = Best->Function->getDeletedMessage();
15888 << "->" << (Msg != nullptr)
15889 << (Msg ? Msg->getString() : StringRef())
15890 << Base->getSourceRange()),
15896 CheckMemberOperatorAccess(OpLoc, Base, nullptr, Best->FoundDecl);
15899 CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function);
15901 if (Method->isExplicitObjectMemberFunction()) {
15908 Base, /*Qualifier=*/nullptr, Best->FoundDecl, Method);
15915 ExprResult FnExpr = CreateFunctionRefExpr(*this, Method, Best->FoundDecl,
15920 QualType ResultTy = Method->getReturnType();
15928 if (CheckCallReturnType(Method->getReturnType(), OpLoc, TheCall, Method))
15932 Method->getType()->castAs<FunctionProtoType>()))
15976 FunctionDecl *FD = Best->Function;
15977 ExprResult Fn = CreateFunctionRefExpr(*this, FD, Best->FoundDecl,
15984 // Check the argument types. This should almost always be a no-op, except
15985 // that array-to-pointer decay is applied to string literals.
15986 Expr *ConvArgs[2];
15989 InitializedEntity::InitializeParameter(Context, FD->getParamDecl(ArgIdx)),
15996 QualType ResultTy = FD->getReturnType();
16004 if (CheckCallReturnType(FD->getReturnType(), UDSuffixLoc, UDL, FD))
16022 CandidateSet->clear(OverloadCandidateSet::CSK_Normal);
16025 BuildMemberReferenceExpr(Range, Range->getType(), Loc,
16037 if (CallExpr->isInvalid()) {
16051 if (CandidateSet->empty() || CandidateSetError) {
16057 CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best);
16067 if (CallExpr->isInvalid() || OverloadResult != OR_Success) {
16079 FixOverloadedFunctionReference(PE->getSubExpr(), Found, Fn);
16082 if (SubExpr.get() == PE->getSubExpr())
16086 ParenExpr(PE->getLParen(), PE->getRParen(), SubExpr.get());
16091 FixOverloadedFunctionReference(ICE->getSubExpr(), Found, Fn);
16094 assert(Context.hasSameType(ICE->getSubExpr()->getType(),
16095 SubExpr.get()->getType()) &&
16097 assert(ICE->path_empty() && "fixing up hierarchy conversion?");
16098 if (SubExpr.get() == ICE->getSubExpr())
16101 return ImplicitCastExpr::Create(Context, ICE->getType(), ICE->getCastKind(),
16102 SubExpr.get(), nullptr, ICE->getValueKind(),
16107 if (!GSE->isResultDependent()) {
16109 FixOverloadedFunctionReference(GSE->getResultExpr(), Found, Fn);
16112 if (SubExpr.get() == GSE->getResultExpr())
16117 ArrayRef<Expr *> A = GSE->getAssocExprs();
16119 unsigned ResultIdx = GSE->getResultIndex();
16122 if (GSE->isExprPredicate())
16124 Context, GSE->getGenericLoc(), GSE->getControllingExpr(),
16125 GSE->getAssocTypeSourceInfos(), AssocExprs, GSE->getDefaultLoc(),
16126 GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(),
16129 Context, GSE->getGenericLoc(), GSE->getControllingType(),
16130 GSE->getAssocTypeSourceInfos(), AssocExprs, GSE->getDefaultLoc(),
16131 GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(),
16140 assert(UnOp->getOpcode() == UO_AddrOf &&
16143 if (!Method->isImplicitObjectMemberFunction()) {
16145 // explicit object member functions is a (non-member) function pointer.
16151 FixOverloadedFunctionReference(UnOp->getSubExpr(), Found, Fn);
16154 if (SubExpr.get() == UnOp->getSubExpr())
16157 if (CheckUseOfCXXMethodAsAddressOfOperand(UnOp->getBeginLoc(),
16163 assert(cast<DeclRefExpr>(SubExpr.get())->getQualifier() &&
16170 = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext()));
16172 = Context.getMemberPointerType(Fn->getType(), ClassType.getTypePtr());
16175 (void)isCompleteType(UnOp->getOperatorLoc(), MemPtrType);
16179 UnOp->getOperatorLoc(), false,
16184 FixOverloadedFunctionReference(UnOp->getSubExpr(), Found, Fn);
16187 if (SubExpr.get() == UnOp->getSubExpr())
16190 return CreateBuiltinUnaryOp(UnOp->getOperatorLoc(), UO_AddrOf,
16197 if (ULE->hasExplicitTemplateArgs()) {
16198 ULE->copyTemplateArgumentsInto(TemplateArgsBuffer);
16202 QualType Type = Fn->getType();
16204 getLangOpts().CPlusPlus && !Fn->hasCXXExplicitFunctionObjectParameter()
16209 if (unsigned BID = Fn->getBuiltinID()) {
16217 Fn, Type, ValueKind, ULE->getNameInfo(), ULE->getQualifierLoc(),
16218 Found.getDecl(), ULE->getTemplateKeywordLoc(), TemplateArgs);
16219 DRE->setHadMultipleCandidates(ULE->getNumDecls() > 1);
16226 if (MemExpr->hasExplicitTemplateArgs()) {
16227 MemExpr->copyTemplateArgumentsInto(TemplateArgsBuffer);
16235 if (MemExpr->isImplicitAccess()) {
16236 if (cast<CXXMethodDecl>(Fn)->isStatic()) {
16238 Fn, Fn->getType(), VK_LValue, MemExpr->getNameInfo(),
16239 MemExpr->getQualifierLoc(), Found.getDecl(),
16240 MemExpr->getTemplateKeywordLoc(), TemplateArgs);
16241 DRE->setHadMultipleCandidates(MemExpr->getNumDecls() > 1);
16244 SourceLocation Loc = MemExpr->getMemberLoc();
16245 if (MemExpr->getQualifier())
16246 Loc = MemExpr->getQualifierLoc().getBeginLoc();
16248 BuildCXXThisExpr(Loc, MemExpr->getBaseType(), /*IsImplicit=*/true);
16251 Base = MemExpr->getBase();
16255 if (cast<CXXMethodDecl>(Fn)->isStatic()) {
16257 type = Fn->getType();
16264 Base, MemExpr->isArrow(), MemExpr->getOperatorLoc(),
16265 MemExpr->getQualifierLoc(), MemExpr->getTemplateKeywordLoc(), Fn, Found,
16266 /*HadMultipleCandidates=*/true, MemExpr->getMemberNameInfo(),
16283 if (Function->isVariadic())
16286 dyn_cast<FunctionProtoType>(Function->getFunctionType()))
16287 if (Proto->isTemplateVariadic())
16289 if (auto *Pattern = Function->getTemplateInstantiationPattern())
16291 dyn_cast<FunctionProtoType>(Pattern->getFunctionType()))
16292 if (Proto->isTemplateVariadic())
16302 StringLiteral *Msg = Fn->getDeletedMessage();
16306 << (Msg ? Msg->getString() : StringRef())