Lines Matching +full:end +full:- +full:of +full:- +full:conversion
1 //===--- SemaOverload.cpp - C++ Overloading -------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
60 return llvm::any_of(FD->parameters(), [](const ParmVarDecl *P) { in functionHasPassObjectSizeParams()
61 return P->hasAttr<PassObjectSizeAttr>(); in functionHasPassObjectSizeParams()
81 DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo); in CreateFunctionRefExpr()
83 DRE->setHadMultipleCandidates(true); in CreateFunctionRefExpr()
86 if (auto *FPT = DRE->getType()->getAs<FunctionProtoType>()) { in CreateFunctionRefExpr()
87 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { in CreateFunctionRefExpr()
89 DRE->setType(Fn->getType()); in CreateFunctionRefExpr()
92 return S.ImpCastExprToType(DRE, S.Context.getPointerType(DRE->getType()), in CreateFunctionRefExpr()
129 /// GetConversionRank - Retrieve the implicit conversion rank
130 /// corresponding to the given implicit conversion kind.
159 ICR_Exact_Match, // NOTE(gbiv): This may not be completely right -- in GetConversionRank()
162 ICR_Exact_Match, // NOTE(ctopper): This may not be completely right -- in GetConversionRank()
195 /// GetImplicitConversionName - Return the name of this kind of
196 /// implicit conversion.
199 "No conversion", in GetImplicitConversionName()
200 "Lvalue-to-rvalue", in GetImplicitConversionName()
201 "Array-to-pointer", in GetImplicitConversionName()
202 "Function-to-pointer", in GetImplicitConversionName()
203 "Function pointer conversion", in GetImplicitConversionName()
208 "Integral conversion", in GetImplicitConversionName()
209 "Floating conversion", in GetImplicitConversionName()
210 "Complex conversion", in GetImplicitConversionName()
211 "Floating-integral conversion", in GetImplicitConversionName()
212 "Pointer conversion", in GetImplicitConversionName()
213 "Pointer-to-member conversion", in GetImplicitConversionName()
214 "Boolean conversion", in GetImplicitConversionName()
215 "Compatible-types conversion", in GetImplicitConversionName()
216 "Derived-to-base conversion", in GetImplicitConversionName()
217 "Vector conversion", in GetImplicitConversionName()
218 "SVE Vector conversion", in GetImplicitConversionName()
219 "RVV Vector conversion", in GetImplicitConversionName()
221 "Complex-real conversion", in GetImplicitConversionName()
222 "Block Pointer conversion", in GetImplicitConversionName()
223 "Transparent Union Conversion", in GetImplicitConversionName()
224 "Writeback conversion", in GetImplicitConversionName()
225 "OpenCL Zero Event Conversion", in GetImplicitConversionName()
226 "OpenCL Zero Queue Conversion", in GetImplicitConversionName()
227 "C specific type conversion", in GetImplicitConversionName()
228 "Incompatible pointer conversion", in GetImplicitConversionName()
229 "Fixed point conversion", in GetImplicitConversionName()
231 "Non-decaying array conversion", in GetImplicitConversionName()
238 /// StandardConversionSequence - Set the standard conversion
239 /// sequence to the identity conversion.
257 /// getRank - Retrieve the rank of this standard conversion sequence
258 /// (C++ 13.3.3.1.1p3). The rank is the largest rank of each of the
273 /// isPointerConversionToBool - Determines whether this conversion is
274 /// a conversion of a pointer or pointer-to-member to bool. This is
275 /// used as part of the ranking of standard conversion sequences
279 // array-to-pointer or function-to-pointer implicit conversions, so in isPointerConversionToBool()
282 if (getToType(1)->isBooleanType() && in isPointerConversionToBool()
283 (getFromType()->isPointerType() || in isPointerConversionToBool()
284 getFromType()->isMemberPointerType() || in isPointerConversionToBool()
285 getFromType()->isObjCObjectPointerType() || in isPointerConversionToBool()
286 getFromType()->isBlockPointerType() || in isPointerConversionToBool()
293 /// isPointerConversionToVoidPointer - Determines whether this
294 /// conversion is a conversion of a pointer to a void pointer. This is
295 /// used as part of the ranking of standard conversion sequences (C++
304 // array-to-pointer implicit conversion, so check for its presence in isPointerConversionToVoidPointer()
305 // and redo the conversion to get a pointer. in isPointerConversionToVoidPointer()
309 if (Second == ICK_Pointer_Conversion && FromType->isAnyPointerType()) in isPointerConversionToVoidPointer()
310 if (const PointerType* ToPtrType = ToType->getAs<PointerType>()) in isPointerConversionToVoidPointer()
311 return ToPtrType->getPointeeType()->isVoidType(); in isPointerConversionToVoidPointer()
316 /// Skip any implicit casts which could be either part of a narrowing conversion
317 /// or after one in an implicit conversion.
324 const_cast<Expr *>(IgnoreNarrowingConversion(Ctx, EWC->getSubExpr())); in IgnoreNarrowingConversion()
325 return ExprWithCleanups::Create(Ctx, Inner, EWC->cleanupsHaveSideEffects(), in IgnoreNarrowingConversion()
326 EWC->getObjects()); in IgnoreNarrowingConversion()
330 switch (ICE->getCastKind()) { in IgnoreNarrowingConversion()
339 Converted = ICE->getSubExpr(); in IgnoreNarrowingConversion()
350 /// Check if this standard conversion sequence represents a narrowing
351 /// conversion, according to C++11 [dcl.init.list]p7.
354 /// \param Converted The result of applying this standard conversion sequence.
355 /// \param ConstantValue If this is an NK_Constant_Narrowing conversion, the
356 /// value of the expression prior to the narrowing conversion.
357 /// \param ConstantType If this is an NK_Constant_Narrowing conversion, the
358 /// type of the expression prior to the narrowing conversion.
359 /// \param IgnoreFloatToIntegralConversion If true type-narrowing conversions
368 // A narrowing conversion is an implicit conversion ... in getNarrowingKind()
372 // A conversion to an enumeration type is narrowing if the conversion to in getNarrowingKind()
373 // the underlying type is narrowing. This only arises for expressions of in getNarrowingKind()
375 if (auto *ET = ToType->getAs<EnumType>()) in getNarrowingKind()
376 ToType = ET->getDecl()->getIntegerType(); in getNarrowingKind()
381 if (FromType->isRealFloatingType()) in getNarrowingKind()
383 if (FromType->isIntegralOrUnscopedEnumerationType()) in getNarrowingKind()
385 // -- from a pointer type or pointer-to-member type to bool, or in getNarrowingKind()
388 // -- from a floating-point type to an integer type, or in getNarrowingKind()
390 // -- from an integer type or unscoped enumeration type to a floating-point in getNarrowingKind()
392 // value after conversion will fit into the target type and will produce in getNarrowingKind()
396 if (FromType->isRealFloatingType() && ToType->isIntegralType(Ctx)) { in getNarrowingKind()
398 } else if (FromType->isIntegralOrUnscopedEnumerationType() && in getNarrowingKind()
399 ToType->isRealFloatingType()) { in getNarrowingKind()
403 assert(Initializer && "Unknown conversion expression"); in getNarrowingKind()
405 // If it's value-dependent, we can't tell whether it's narrowing. in getNarrowingKind()
406 if (Initializer->isValueDependent()) in getNarrowingKind()
410 Initializer->getIntegerConstantExpr(Ctx)) { in getNarrowingKind()
413 Result.convertFromAPInt(*IntConstantValue, IntConstantValue->isSigned(), in getNarrowingKind()
420 // If the resulting value is different, this was a narrowing conversion. in getNarrowingKind()
423 ConstantType = Initializer->getType(); in getNarrowingKind()
433 // -- from long double to double or float, or from double to float, except in getNarrowingKind()
435 // conversion is within the range of values that can be represented (even in getNarrowingKind()
438 if (FromType->isRealFloatingType() && ToType->isRealFloatingType() && in getNarrowingKind()
443 // If it's value-dependent, we can't tell whether it's narrowing. in getNarrowingKind()
444 if (Initializer->isValueDependent()) in getNarrowingKind()
448 if ((Ctx.getLangOpts().C23 && Initializer->EvaluateAsRValue(R, Ctx)) || in getNarrowingKind()
449 Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)) { in getNarrowingKind()
466 // Quiet NaNs are considered the same value, regardless of in getNarrowingKind()
472 ConstantType = Initializer->getType(); in getNarrowingKind()
476 // If there was no overflow, the source value is within the range of in getNarrowingKind()
479 ConstantType = Initializer->getType(); in getNarrowingKind()
489 // -- from an integer type or unscoped enumeration type to an integer type in getNarrowingKind()
490 // that cannot represent all the values of the original type, except where in getNarrowingKind()
492 // conversion will fit into the target type and will produce the original in getNarrowingKind()
496 assert(FromType->isIntegralOrUnscopedEnumerationType()); in getNarrowingKind()
497 assert(ToType->isIntegralOrUnscopedEnumerationType()); in getNarrowingKind()
498 const bool FromSigned = FromType->isSignedIntegerOrEnumerationType(); in getNarrowingKind()
500 const bool ToSigned = ToType->isSignedIntegerOrEnumerationType(); in getNarrowingKind()
506 // Not all values of FromType can be represented in ToType. in getNarrowingKind()
509 // If it's value-dependent, we can't tell whether it's narrowing. in getNarrowingKind()
510 if (Initializer->isValueDependent()) in getNarrowingKind()
514 if (!(OptInitializerValue = Initializer->getIntegerConstantExpr(Ctx))) { in getNarrowingKind()
521 // Negative -> unsigned is narrowing. Otherwise, more bits is never in getNarrowingKind()
530 // Convert the initializer to and from the target width and signed-ness. in getNarrowingKind()
536 // If the result is different, this was a narrowing conversion. in getNarrowingKind()
541 ConstantType = Initializer->getType(); in getNarrowingKind()
549 if (FromType->isComplexType() && !ToType->isComplexType()) in getNarrowingKind()
557 if (Initializer->EvaluateAsRValue(R, Ctx)) { in getNarrowingKind()
562 // value, the unqualified versions of the type of the initializer and in getNarrowingKind()
563 // the corresponding real type of the object declared shall be in getNarrowingKind()
566 ConstantType = Initializer->getType(); in getNarrowingKind()
573 // Other kinds of conversions are not narrowings. in getNarrowingKind()
578 /// dump - Print this standard conversion sequence to standard
590 OS << " -> "; in dump()
606 OS << " -> "; in dump()
617 /// dump - Print this user-defined conversion sequence to standard
623 OS << " -> "; in dump()
630 OS << " -> "; in dump()
635 /// dump - Print this implicit conversion sequence to standard
640 OS << "Worst list element conversion: "; in dump()
643 OS << "Standard conversion: "; in dump()
647 OS << "User-defined conversion: "; in dump()
651 OS << "Ellipsis conversion"; in dump()
654 OS << "Ambiguous conversion"; in dump()
657 OS << "Bad conversion"; in dump()
692 // information and the index of the problematic call argument.
705 /// Convert from Sema's representation of template deduction information
706 /// to the form used in overload-candidate information.
733 Saved->FirstArg = Info.FirstArg; in MakeDeductionFailureInfo()
734 Saved->SecondArg = Info.SecondArg; in MakeDeductionFailureInfo()
735 Saved->TemplateArgs = Info.takeSugared(); in MakeDeductionFailureInfo()
736 Saved->CallArgIndex = Info.CallArgIndex; in MakeDeductionFailureInfo()
744 Saved->FirstArg = Info.FirstArg; in MakeDeductionFailureInfo()
745 Saved->SecondArg = Info.SecondArg; in MakeDeductionFailureInfo()
756 Saved->Param = Info.Param; in MakeDeductionFailureInfo()
757 Saved->FirstArg = Info.FirstArg; in MakeDeductionFailureInfo()
758 Saved->SecondArg = Info.SecondArg; in MakeDeductionFailureInfo()
775 Saved->TemplateArgs = Info.takeSugared(); in MakeDeductionFailureInfo()
776 Saved->Satisfaction = Info.AssociatedConstraintsSatisfaction; in MakeDeductionFailureInfo()
817 Diag->~PartialDiagnosticAt(); in Destroy()
826 Diag->~PartialDiagnosticAt(); in Destroy()
867 return static_cast<DFIParamWithArguments*>(Data)->Param; in getTemplateParameter()
897 return static_cast<DFIDeducedMismatchArgs*>(Data)->TemplateArgs; in getTemplateArgumentList()
903 return static_cast<CNSInfo*>(Data)->TemplateArgs; in getTemplateArgumentList()
935 return &static_cast<DFIArguments*>(Data)->FirstArg; in getFirstArg()
967 return &static_cast<DFIArguments*>(Data)->SecondArg; in getSecondArg()
982 return static_cast<DFIDeducedMismatchArgs*>(Data)->CallArgIndex; in getCallArgIndex()
993 if (X->getNumParams() != Y->getNumParams()) in FunctionsCorrespond()
998 for (unsigned I = 0; I < X->getNumParams(); ++I) in FunctionsCorrespond()
999 if (!Ctx.hasSameUnqualifiedType(X->getParamDecl(I)->getType(), in FunctionsCorrespond()
1000 Y->getParamDecl(I)->getType())) in FunctionsCorrespond()
1002 if (auto *FTX = X->getDescribedFunctionTemplate()) { in FunctionsCorrespond()
1003 auto *FTY = Y->getDescribedFunctionTemplate(); in FunctionsCorrespond()
1006 if (!Ctx.isSameTemplateParameterList(FTX->getTemplateParameters(), in FunctionsCorrespond()
1007 FTY->getTemplateParameters())) in FunctionsCorrespond()
1015 assert(EqFD->getOverloadedOperator() == in shouldAddReversedEqEq()
1018 // A non-template function or function template F named operator== is a in shouldAddReversedEqEq()
1020 // in the scope S from the instantiation context of the operator expression in shouldAddReversedEqEq()
1023 // scope of the class type of o if F is a class member, and the namespace in shouldAddReversedEqEq()
1024 // scope of which F is a member otherwise. A function template specialization in shouldAddReversedEqEq()
1030 // If F is a class member, search scope is class type of first operand. in shouldAddReversedEqEq()
1031 QualType RHS = FirstOperand->getType(); in shouldAddReversedEqEq()
1032 auto *RHSRec = RHS->getAs<RecordType>(); in shouldAddReversedEqEq()
1037 S.LookupQualifiedName(Members, RHSRec->getDecl()); in shouldAddReversedEqEq()
1040 if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction())) in shouldAddReversedEqEq()
1044 // Otherwise the search scope is the namespace scope of which F is a member. in shouldAddReversedEqEq()
1045 for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) { in shouldAddReversedEqEq()
1046 auto *NotEqFD = Op->getAsFunction(); in shouldAddReversedEqEq()
1048 NotEqFD = UD->getUnderlyingDecl()->getAsFunction(); in shouldAddReversedEqEq()
1050 declaresSameEntity(cast<Decl>(EqFD->getEnclosingNamespaceContext()), in shouldAddReversedEqEq()
1051 cast<Decl>(Op->getLexicalDeclContext()))) in shouldAddReversedEqEq()
1066 auto Op = FD->getOverloadedOperator(); in shouldAddReversed()
1076 // match than the non-reversed version. in shouldAddReversed()
1077 return FD->getNumNonObjectParams() != 2 || in shouldAddReversed()
1078 !S.Context.hasSameUnqualifiedType(FD->getParamDecl(0)->getType(), in shouldAddReversed()
1079 FD->getParamDecl(1)->getType()) || in shouldAddReversed()
1080 FD->hasAttr<EnableIfAttr>(); in shouldAddReversed()
1084 for (iterator i = begin(), e = end(); i != e; ++i) { in destroyCandidates()
1085 for (auto &C : i->Conversions) in destroyCandidates()
1087 if (!i->Viable && i->FailureKind == ovl_fail_bad_deduction) in destroyCandidates()
1088 i->DeductionFailure.Destroy(); in destroyCandidates()
1111 assert(E->hasPlaceholderType(BuiltinType::ARCUnbridgedCast)); in save()
1119 i = Entries.begin(), e = Entries.end(); i != e; ++i) in restore()
1120 *i->Addr = i->Saved; in restore()
1125 /// checkPlaceholderForOverload - Do any interesting placeholder-like
1135 if (const BuiltinType *placeholder = E->getType()->getAsPlaceholderType()) { in checkPlaceholderForOverload()
1138 if (placeholder->getKind() == BuiltinType::Overload) return false; in checkPlaceholderForOverload()
1142 if (placeholder->getKind() == BuiltinType::ARCUnbridgedCast && in checkPlaceholderForOverload()
1144 unbridgedCasts->save(S, E); in checkPlaceholderForOverload()
1161 /// checkArgPlaceholdersForOverload - Check a set of call operands for
1175 for (LookupResult::iterator I = Old.begin(), E = Old.end(); in CheckOverload()
1187 OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl(); in CheckOverload()
1190 // A using-declaration does not conflict with another declaration in CheckOverload()
1191 // if one of them is hidden. in CheckOverload()
1201 (OldIsUsingDecl || NewIsUsingDecl) && CurContext->isRecord() && in CheckOverload()
1202 !New->getFriendObjectKind(); in CheckOverload()
1204 if (FunctionDecl *OldF = OldD->getAsFunction()) { in CheckOverload()
1238 if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) { in CheckOverload()
1253 // -- if the name of the friend is a qualified or unqualified template-id, in CheckOverload()
1255 // -- if the name of the friend is a qualified-id and a matching in CheckOverload()
1256 // non-template function is found in the specified class or namespace, in CheckOverload()
1258 // -- if the name of the friend is a qualified-id and a matching function in CheckOverload()
1260 // declaration refers to the deduced specialization of that function in CheckOverload()
1262 // -- the name shall be an unqualified-id [...] in CheckOverload()
1264 // third bullet. If the type of the friend is dependent, skip this lookup in CheckOverload()
1266 if (New->getFriendObjectKind() && New->getQualifier() && in CheckOverload()
1267 !New->getDescribedFunctionTemplate() && in CheckOverload()
1268 !New->getDependentSpecializationInfo() && in CheckOverload()
1269 !New->getType()->isDependentType()) { in CheckOverload()
1274 New->setInvalidDecl(); in CheckOverload()
1291 if (New->isMain()) in IsOverloadOrOverrideImpl()
1295 if (New->isMSVCRTEntryPoint()) in IsOverloadOrOverrideImpl()
1300 FunctionTemplateDecl *OldTemplate = Old->getDescribedFunctionTemplate(); in IsOverloadOrOverrideImpl()
1301 FunctionTemplateDecl *NewTemplate = New->getDescribedFunctionTemplate(); in IsOverloadOrOverrideImpl()
1305 // and with normal (non-template) functions. in IsOverloadOrOverrideImpl()
1309 // Is the function New an overload of the function Old? in IsOverloadOrOverrideImpl()
1310 QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType()); in IsOverloadOrOverrideImpl()
1311 QualType NewQType = SemaRef.Context.getCanonicalType(New->getType()); in IsOverloadOrOverrideImpl()
1313 // Compare the signatures (C++ 1.3.10) of the two functions to in IsOverloadOrOverrideImpl()
1317 // If either of these functions is a K&R-style function (no in IsOverloadOrOverrideImpl()
1326 // The signature of a function includes the types of its in IsOverloadOrOverrideImpl()
1328 // of the ellipsis; see C++ DR 357). in IsOverloadOrOverrideImpl()
1329 if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic()) in IsOverloadOrOverrideImpl()
1332 // For member-like friends, the enclosing class is part of the signature. in IsOverloadOrOverrideImpl()
1333 if ((New->isMemberLikeConstrainedFriend() || in IsOverloadOrOverrideImpl()
1334 Old->isMemberLikeConstrainedFriend()) && in IsOverloadOrOverrideImpl()
1335 !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext())) in IsOverloadOrOverrideImpl()
1341 // references to non-instantiated entities during constraint substitution. in IsOverloadOrOverrideImpl()
1347 // The signature of a function template consists of its function in IsOverloadOrOverrideImpl()
1349 // of the template parameters are significant only for establishing the in IsOverloadOrOverrideImpl()
1350 // relationship between the template parameters and the rest of the in IsOverloadOrOverrideImpl()
1356 NewTemplate, NewTemplate->getTemplateParameters(), OldTemplate, in IsOverloadOrOverrideImpl()
1357 OldTemplate->getTemplateParameters(), false, Sema::TPL_TemplateMatch); in IsOverloadOrOverrideImpl()
1359 Old->getDeclaredReturnType(), New->getDeclaredReturnType()); in IsOverloadOrOverrideImpl()
1360 // FIXME(GH58571): Match template parameter list even for non-constrained in IsOverloadOrOverrideImpl()
1364 NewTemplate->getTemplateParameters()->hasAssociatedConstraints() || in IsOverloadOrOverrideImpl()
1365 OldTemplate->getTemplateParameters()->hasAssociatedConstraints(); in IsOverloadOrOverrideImpl()
1367 // The set of declarations named by a using-declarator that inhabits a in IsOverloadOrOverrideImpl()
1369 // templates of a base class that "correspond" to (and thus would in IsOverloadOrOverrideImpl()
1370 // conflict with) a declaration of a function or function template in in IsOverloadOrOverrideImpl()
1389 // the implicit object parameter are of the same type. in IsOverloadOrOverrideImpl()
1392 if (M->isExplicitObjectMemberFunction()) in IsOverloadOrOverrideImpl()
1395 // We do not allow overloading based off of '__restrict'. in IsOverloadOrOverrideImpl()
1400 // or non-static member function). Add it now, on the assumption that this in IsOverloadOrOverrideImpl()
1401 // is a redeclaration of OldMethod. in IsOverloadOrOverrideImpl()
1403 (M->isConstexpr() || M->isConsteval()) && in IsOverloadOrOverrideImpl()
1419 if (OldMethod->isImplicitObjectMemberFunction() && in IsOverloadOrOverrideImpl()
1420 OldMethod->getParent() != NewMethod->getParent()) { in IsOverloadOrOverrideImpl()
1422 SemaRef.Context.getTypeDeclType(OldMethod->getParent()) in IsOverloadOrOverrideImpl()
1433 if (Base->isLValueReferenceType()) in IsOverloadOrOverrideImpl()
1434 return D->isLValueReferenceType(); in IsOverloadOrOverrideImpl()
1435 return Base->isRValueReferenceType() == D->isRValueReferenceType(); in IsOverloadOrOverrideImpl()
1439 // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself. in IsOverloadOrOverrideImpl()
1443 if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier()) in IsOverloadOrOverrideImpl()
1445 if (OldMethod->isExplicitObjectMemberFunction() || in IsOverloadOrOverrideImpl()
1446 NewMethod->isExplicitObjectMemberFunction()) in IsOverloadOrOverrideImpl()
1448 if (!UseMemberUsingDeclRules && (OldMethod->getRefQualifier() == RQ_None || in IsOverloadOrOverrideImpl()
1449 NewMethod->getRefQualifier() == RQ_None)) { in IsOverloadOrOverrideImpl()
1450 SemaRef.Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload) in IsOverloadOrOverrideImpl()
1451 << NewMethod->getRefQualifier() << OldMethod->getRefQualifier(); in IsOverloadOrOverrideImpl()
1452 SemaRef.Diag(OldMethod->getLocation(), diag::note_previous_declaration); in IsOverloadOrOverrideImpl()
1458 if (OldMethod && OldMethod->isExplicitObjectMemberFunction()) in IsOverloadOrOverrideImpl()
1460 if (NewMethod && NewMethod->isExplicitObjectMemberFunction()) in IsOverloadOrOverrideImpl()
1463 if (OldType->getNumParams() - OldParamsOffset != in IsOverloadOrOverrideImpl()
1464 NewType->getNumParams() - NewParamsOffset || in IsOverloadOrOverrideImpl()
1466 {OldType->param_type_begin() + OldParamsOffset, in IsOverloadOrOverrideImpl()
1467 OldType->param_type_end()}, in IsOverloadOrOverrideImpl()
1468 {NewType->param_type_begin() + NewParamsOffset, in IsOverloadOrOverrideImpl()
1469 NewType->param_type_end()}, in IsOverloadOrOverrideImpl()
1474 if (OldMethod && NewMethod && !OldMethod->isStatic() && in IsOverloadOrOverrideImpl()
1475 !NewMethod->isStatic()) { in IsOverloadOrOverrideImpl()
1478 auto NewObjectType = New->getFunctionObjectParameterReferenceType(); in IsOverloadOrOverrideImpl()
1479 auto OldObjectType = Old->getFunctionObjectParameterReferenceType(); in IsOverloadOrOverrideImpl()
1482 return F->getRefQualifier() == RQ_None && in IsOverloadOrOverrideImpl()
1483 !F->isExplicitObjectMemberFunction(); in IsOverloadOrOverrideImpl()
1499 if (!UseOverrideRules || (!NewMethod->isExplicitObjectMemberFunction() && in IsOverloadOrOverrideImpl()
1500 !OldMethod->isExplicitObjectMemberFunction())) in IsOverloadOrOverrideImpl()
1506 New->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) { in IsOverloadOrOverrideImpl()
1507 Expr *NewRC = New->getTrailingRequiresClause(), in IsOverloadOrOverrideImpl()
1508 *OldRC = Old->getTrailingRequiresClause(); in IsOverloadOrOverrideImpl()
1516 if (NewMethod && OldMethod && OldMethod->isImplicitObjectMemberFunction() && in IsOverloadOrOverrideImpl()
1517 NewMethod->isImplicitObjectMemberFunction()) { in IsOverloadOrOverrideImpl()
1523 // consider it to be a function-level modifier for the sake of function in IsOverloadOrOverrideImpl()
1530 // enable_if attributes are an order-sensitive part of the signature. in IsOverloadOrOverrideImpl()
1532 NewI = New->specific_attr_begin<EnableIfAttr>(), in IsOverloadOrOverrideImpl()
1533 NewE = New->specific_attr_end<EnableIfAttr>(), in IsOverloadOrOverrideImpl()
1534 OldI = Old->specific_attr_begin<EnableIfAttr>(), in IsOverloadOrOverrideImpl()
1535 OldE = Old->specific_attr_end<EnableIfAttr>(); in IsOverloadOrOverrideImpl()
1540 NewI->getCond()->Profile(NewID, SemaRef.Context, true); in IsOverloadOrOverrideImpl()
1541 OldI->getCond()->Profile(OldID, SemaRef.Context, true); in IsOverloadOrOverrideImpl()
1547 // Don't allow overloading of destructors. (In theory we could, but it in IsOverloadOrOverrideImpl()
1556 // Allow overloading of functions with same signature and different CUDA in IsOverloadOrOverrideImpl()
1582 /// Tries a user-defined conversion from From to ToType.
1584 /// Produces an implicit conversion sequence for when a standard conversion
1597 // We're not in the case above, so there is no conversion that in TryUserDefinedConversion()
1603 // Attempt user-defined conversion. in TryUserDefinedConversion()
1604 OverloadCandidateSet Conversions(From->getExprLoc(), in TryUserDefinedConversion()
1613 // A conversion of an expression of class type to the same class in TryUserDefinedConversion()
1614 // type is given Exact Match rank, and a conversion of an in TryUserDefinedConversion()
1615 // expression of class type to a base class of that type is in TryUserDefinedConversion()
1616 // given Conversion rank, in spite of the fact that a copy in TryUserDefinedConversion()
1617 // constructor (i.e., a user-defined conversion function) is in TryUserDefinedConversion()
1622 = S.Context.getCanonicalType(From->getType().getUnqualifiedType()); in TryUserDefinedConversion()
1625 if (Constructor->isCopyConstructor() && in TryUserDefinedConversion()
1627 S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) { in TryUserDefinedConversion()
1628 // Turn this into a "standard" conversion sequence, so that it in TryUserDefinedConversion()
1629 // gets ranked with standard conversion sequences. in TryUserDefinedConversion()
1633 ICS.Standard.setFromType(From->getType()); in TryUserDefinedConversion()
1645 ICS.Ambiguous.setFromType(From->getType()); in TryUserDefinedConversion()
1648 Cand != Conversions.end(); ++Cand) in TryUserDefinedConversion()
1649 if (Cand->Best) in TryUserDefinedConversion()
1650 ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function); in TryUserDefinedConversion()
1662 /// TryImplicitConversion - Attempt to perform an implicit conversion
1664 /// function returns an implicit conversion sequence that can be used
1670 /// this routine would produce an implicit conversion sequence to
1671 /// describe the initialization of f from i, which will be a standard
1672 /// conversion sequence containing an lvalue-to-rvalue conversion (C++
1673 /// 4.1) followed by a floating-integral conversion (C++ 4.9).
1675 /// Note that this routine only determines how the conversion can be
1676 /// performed; it does not actually perform the conversion. As such,
1677 /// it will not produce any diagnostics if no conversion is available,
1678 /// but will instead return an implicit conversion sequence of kind
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
1687 /// writeback conversion, which allows __autoreleasing id* parameters to
1710 // A conversion of an expression of class type to the same class in TryImplicitConversion()
1711 // type is given Exact Match rank, and a conversion of an in TryImplicitConversion()
1712 // expression of class type to a base class of that type is in TryImplicitConversion()
1713 // given Conversion rank, in spite of the fact that a copy/move in TryImplicitConversion()
1714 // constructor (i.e., a user-defined conversion function) is in TryImplicitConversion()
1716 QualType FromType = From->getType(); in TryImplicitConversion()
1717 if (ToType->getAs<RecordType>() && FromType->getAs<RecordType>() && in TryImplicitConversion()
1719 S.IsDerivedFrom(From->getBeginLoc(), FromType, ToType))) { in TryImplicitConversion()
1731 // Determine whether this is considered a derived-to-base conversion. in TryImplicitConversion()
1763 // Objective-C ARC: Determine whether we will allow the writeback conversion. in PerformImplicitConversion()
1768 ObjC().CheckObjCBridgeRelatedConversions(From->getBeginLoc(), ToType, in PerformImplicitConversion()
1769 From->getType(), From); in PerformImplicitConversion()
1785 // Permit the conversion F(t __attribute__((noreturn))) -> F(t) in IsFunctionConversion()
1786 // or F(t noexcept) -> F(t) in IsFunctionConversion()
1787 // where F adds one of the following at most once: in IsFunctionConversion()
1788 // - a pointer in IsFunctionConversion()
1789 // - a member pointer in IsFunctionConversion()
1790 // - a block pointer in IsFunctionConversion()
1794 Type::TypeClass TyClass = CanTo->getTypeClass(); in IsFunctionConversion()
1795 if (TyClass != CanFrom->getTypeClass()) return false; in IsFunctionConversion()
1798 CanTo = CanTo.castAs<PointerType>()->getPointeeType(); in IsFunctionConversion()
1799 CanFrom = CanFrom.castAs<PointerType>()->getPointeeType(); in IsFunctionConversion()
1801 CanTo = CanTo.castAs<BlockPointerType>()->getPointeeType(); in IsFunctionConversion()
1802 CanFrom = CanFrom.castAs<BlockPointerType>()->getPointeeType(); in IsFunctionConversion()
1806 // A function pointer conversion cannot change the class of the function. in IsFunctionConversion()
1807 if (ToMPT->getClass() != FromMPT->getClass()) in IsFunctionConversion()
1809 CanTo = ToMPT->getPointeeType(); in IsFunctionConversion()
1810 CanFrom = FromMPT->getPointeeType(); in IsFunctionConversion()
1815 TyClass = CanTo->getTypeClass(); in IsFunctionConversion()
1816 if (TyClass != CanFrom->getTypeClass()) return false; in IsFunctionConversion()
1822 FunctionType::ExtInfo FromEInfo = FromFn->getExtInfo(); in IsFunctionConversion()
1825 FunctionType::ExtInfo ToEInfo = ToFn->getExtInfo(); in IsFunctionConversion()
1838 if (FromFPT->isNothrow() && !ToFPT->isNothrow()) { in IsFunctionConversion()
1846 // Convert FromFPT's ExtParameterInfo if necessary. The conversion is valid in IsFunctionConversion()
1847 // only if the ExtParameterInfo lists of the two function prototypes can be in IsFunctionConversion()
1854 FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo(); in IsFunctionConversion()
1857 QualType QT = Context.getFunctionType(FromFPT->getReturnType(), in IsFunctionConversion()
1858 FromFPT->getParamTypes(), ExtInfo); in IsFunctionConversion()
1859 FromFn = QT->getAs<FunctionType>(); in IsFunctionConversion()
1866 // alter FromFn (because of the way PerformImplicitConversion works). in IsFunctionConversion()
1872 const auto FromFX = FromFPT->getFunctionEffects(); in IsFunctionConversion()
1873 const auto ToFX = ToFPT->getFunctionEffects(); in IsFunctionConversion()
1875 FunctionProtoType::ExtProtoInfo ExtInfo = FromFPT->getExtProtoInfo(); in IsFunctionConversion()
1878 FromFPT->getReturnType(), FromFPT->getParamTypes(), ExtInfo); in IsFunctionConversion()
1879 FromFn = QT->getAs<FunctionType>(); in IsFunctionConversion()
1895 /// Determine whether the conversion from FromType to ToType is a valid
1896 /// floating point conversion.
1900 if (!FromType->isRealFloatingType() || !ToType->isRealFloatingType()) in IsFloatingPointConversion()
1903 // if their representation is different until there is back end support in IsFloatingPointConversion()
1904 // We of course allow this conversion if long double is really double. in IsFloatingPointConversion()
1907 if ((FromType->isBFloat16Type() && in IsFloatingPointConversion()
1908 (ToType->isFloat16Type() || ToType->isHalfType())) || in IsFloatingPointConversion()
1909 (ToType->isBFloat16Type() && in IsFloatingPointConversion()
1910 (FromType->isFloat16Type() || FromType->isHalfType()))) in IsFloatingPointConversion()
1913 // Conversions between IEEE-quad and IBM-extended semantics are not in IsFloatingPointConversion()
1941 if (ToType->isBooleanType() && FromType->isArithmeticType()) { in IsVectorElementConversion()
1946 if ((FromType->isRealFloatingType() && ToType->isIntegralType(S.Context)) || in IsVectorElementConversion()
1947 (FromType->isIntegralOrUnscopedEnumerationType() && in IsVectorElementConversion()
1948 ToType->isRealFloatingType())) { in IsVectorElementConversion()
1958 if (FromType->isIntegralOrUnscopedEnumerationType() && in IsVectorElementConversion()
1959 ToType->isIntegralType(S.Context)) { in IsVectorElementConversion()
1967 /// Determine whether the conversion from FromType to ToType is a valid
1968 /// vector conversion.
1970 /// \param ICK Will be set to the vector conversion kind, if this is a vector
1971 /// conversion.
1976 // We need at least one of these types to be a vector type to have a vector in IsVectorConversion()
1977 // conversion. in IsVectorConversion()
1978 if (!ToType->isVectorType() && !FromType->isVectorType()) in IsVectorConversion()
1986 if (auto *ToExtType = ToType->getAs<ExtVectorType>()) { in IsVectorConversion()
1987 if (auto *FromExtType = FromType->getAs<ExtVectorType>()) { in IsVectorConversion()
1988 // HLSL allows implicit truncation of vector types. in IsVectorConversion()
1990 unsigned FromElts = FromExtType->getNumElements(); in IsVectorConversion()
1991 unsigned ToElts = ToExtType->getNumElements(); in IsVectorConversion()
1999 QualType FromElTy = FromExtType->getElementType(); in IsVectorConversion()
2000 QualType ToElTy = ToExtType->getElementType(); in IsVectorConversion()
2006 // identity conversion. in IsVectorConversion()
2011 if (FromType->isArithmeticType()) { in IsVectorConversion()
2014 QualType ToElTy = ToExtType->getElementType(); in IsVectorConversion()
2022 if (ToType->isSVESizelessBuiltinType() || in IsVectorConversion()
2023 FromType->isSVESizelessBuiltinType()) in IsVectorConversion()
2030 if (ToType->isRVVSizelessBuiltinType() || in IsVectorConversion()
2031 FromType->isRVVSizelessBuiltinType()) in IsVectorConversion()
2038 // We can perform the conversion between vector types in the following cases: in IsVectorConversion()
2040 // 2)lax vector conversions are permitted and the vector types are of the in IsVectorConversion()
2042 // 3)the destination type does not have the ARM MVE strict-polymorphism in IsVectorConversion()
2043 // attribute, which inhibits lax vector conversion for overload resolution in IsVectorConversion()
2045 if (ToType->isVectorType() && FromType->isVectorType()) { in IsVectorConversion()
2048 !ToType->hasAttr(attr::ArmMveStrictPolymorphism))) { in IsVectorConversion()
2054 S.Diag(From->getBeginLoc(), diag::warn_deprecated_lax_vec_conv_all) in IsVectorConversion()
2070 /// IsStandardConversion - Determines whether there is a standard
2071 /// conversion sequence (C++ [conv], C++ [over.ics.scs]) from the
2072 /// expression From to the type ToType. Standard conversion sequences
2073 /// only consider non-class types; for conversions that involve class
2074 /// types, use TryImplicitConversion. If a conversion exists, SCS will
2075 /// contain the standard conversion sequence required to perform this
2076 /// conversion and this routine will return true. Otherwise, this
2077 /// routine will return false and the value of SCS is unspecified.
2083 QualType FromType = From->getType(); in IsStandardConversion()
2094 (FromType->isRecordType() || ToType->isRecordType())) in IsStandardConversion()
2097 // The first conversion can be an lvalue-to-rvalue conversion, in IsStandardConversion()
2098 // array-to-pointer conversion, or function-to-pointer conversion in IsStandardConversion()
2106 // We were able to resolve the address of the overloaded function, in IsStandardConversion()
2107 // so we can convert to the type of that function. in IsStandardConversion()
2108 FromType = Fn->getType(); in IsStandardConversion()
2111 // we can sometimes resolve &foo<int> regardless of ToType, so check in IsStandardConversion()
2119 // otherwise, only a boolean conversion is standard in IsStandardConversion()
2120 if (!ToType->isBooleanType()) in IsStandardConversion()
2124 // Check if the "from" expression is taking the address of an overloaded in IsStandardConversion()
2125 // function and recompute the FromType accordingly. Take advantage of the in IsStandardConversion()
2126 // fact that non-static member functions *must* have such an address-of in IsStandardConversion()
2129 if (Method && !Method->isStatic() && in IsStandardConversion()
2130 !Method->isExplicitObjectMemberFunction()) { in IsStandardConversion()
2131 assert(isa<UnaryOperator>(From->IgnoreParens()) && in IsStandardConversion()
2132 "Non-unary operator on non-static member address"); in IsStandardConversion()
2133 assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode() in IsStandardConversion()
2135 "Non-address-of operator on non-static member address"); in IsStandardConversion()
2137 = S.Context.getTypeDeclType(Method->getParent()).getTypePtr(); in IsStandardConversion()
2139 } else if (isa<UnaryOperator>(From->IgnoreParens())) { in IsStandardConversion()
2140 assert(cast<UnaryOperator>(From->IgnoreParens())->getOpcode() == in IsStandardConversion()
2142 "Non-address-of operator for overloaded function expression"); in IsStandardConversion()
2149 // Lvalue-to-rvalue conversion (C++11 4.1): in IsStandardConversion()
2150 // A glvalue (3.10) of a non-function, non-array type T can in IsStandardConversion()
2152 bool argIsLValue = From->isGLValue(); in IsStandardConversion()
2153 if (argIsLValue && !FromType->canDecayToPointerType() && in IsStandardConversion()
2158 // ... if the lvalue has atomic type, the value has the non-atomic version in IsStandardConversion()
2159 // of the type of the lvalue ... in IsStandardConversion()
2160 if (const AtomicType *Atomic = FromType->getAs<AtomicType>()) in IsStandardConversion()
2161 FromType = Atomic->getValueType(); in IsStandardConversion()
2163 // If T is a non-class type, the type of the rvalue is the in IsStandardConversion()
2164 // cv-unqualified version of T. Otherwise, the type of the rvalue in IsStandardConversion()
2168 } else if (S.getLangOpts().HLSL && FromType->isConstantArrayType() && in IsStandardConversion()
2169 ToType->isArrayParameterType()) { in IsStandardConversion()
2181 } else if (FromType->isArrayType()) { in IsStandardConversion()
2182 // Array-to-pointer conversion (C++ 4.2) in IsStandardConversion()
2185 // An lvalue or rvalue of type "array of N T" or "array of unknown in IsStandardConversion()
2186 // bound of T" can be converted to an rvalue of type "pointer to in IsStandardConversion()
2191 // This conversion is deprecated in C++03 (D.4) in IsStandardConversion()
2194 // For the purpose of ranking in overload resolution in IsStandardConversion()
2195 // (13.3.3.1.1), this conversion is considered an in IsStandardConversion()
2196 // array-to-pointer conversion followed by a qualification in IsStandardConversion()
2197 // conversion (4.4). (C++ 4.2p2) in IsStandardConversion()
2204 } else if (FromType->isFunctionType() && argIsLValue) { in IsStandardConversion()
2205 // Function-to-pointer conversion (C++ 4.3). in IsStandardConversion()
2208 if (auto *DRE = dyn_cast<DeclRefExpr>(From->IgnoreParenCasts())) in IsStandardConversion()
2209 if (auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl())) in IsStandardConversion()
2213 // An lvalue of function type T can be converted to an rvalue of in IsStandardConversion()
2223 // The second conversion can be an integral promotion, floating in IsStandardConversion()
2224 // point promotion, integral conversion, floating point conversion, in IsStandardConversion()
2225 // floating-integral conversion, pointer conversion, in IsStandardConversion()
2226 // pointer-to-member conversion, or boolean conversion (C++ 4p1). in IsStandardConversion()
2227 // For overloading in C, this can also be a "compatible-type" in IsStandardConversion()
2228 // conversion. in IsStandardConversion()
2233 // The unqualified versions of the types are the same: there's no in IsStandardConversion()
2234 // conversion to do. in IsStandardConversion()
2248 } else if (ToType->isBooleanType() && in IsStandardConversion()
2249 (FromType->isArithmeticType() || in IsStandardConversion()
2250 FromType->isAnyPointerType() || in IsStandardConversion()
2251 FromType->isBlockPointerType() || in IsStandardConversion()
2252 FromType->isMemberPointerType())) { in IsStandardConversion()
2256 } else if (FromType->isIntegralOrUnscopedEnumerationType() && in IsStandardConversion()
2257 ToType->isIntegralType(S.Context)) { in IsStandardConversion()
2261 } else if (FromType->isAnyComplexType() && ToType->isAnyComplexType()) { in IsStandardConversion()
2265 } else if ((FromType->isAnyComplexType() && ToType->isArithmeticType()) || in IsStandardConversion()
2266 (ToType->isAnyComplexType() && FromType->isArithmeticType())) { in IsStandardConversion()
2267 // Complex-real conversions (C99 6.3.1.7) in IsStandardConversion()
2274 } else if ((FromType->isRealFloatingType() && in IsStandardConversion()
2275 ToType->isIntegralType(S.Context)) || in IsStandardConversion()
2276 (FromType->isIntegralOrUnscopedEnumerationType() && in IsStandardConversion()
2277 ToType->isRealFloatingType())) { in IsStandardConversion()
2279 // Floating-integral conversions (C++ 4.9). in IsStandardConversion()
2313 // tryAtomicConversion has updated the standard conversion sequence in IsStandardConversion()
2316 } else if (ToType->isEventT() && in IsStandardConversion()
2317 From->isIntegerConstantExpr(S.getASTContext()) && in IsStandardConversion()
2318 From->EvaluateKnownConstInt(S.getASTContext()) == 0) { in IsStandardConversion()
2321 } else if (ToType->isQueueT() && in IsStandardConversion()
2322 From->isIntegerConstantExpr(S.getASTContext()) && in IsStandardConversion()
2323 (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) { in IsStandardConversion()
2326 } else if (ToType->isSamplerT() && in IsStandardConversion()
2327 From->isIntegerConstantExpr(S.getASTContext())) { in IsStandardConversion()
2330 } else if ((ToType->isFixedPointType() && in IsStandardConversion()
2331 FromType->isConvertibleToFixedPointType()) || in IsStandardConversion()
2332 (FromType->isFixedPointType() && in IsStandardConversion()
2333 ToType->isConvertibleToFixedPointType())) { in IsStandardConversion()
2337 // No second conversion required. in IsStandardConversion()
2342 // The third conversion can be a function pointer conversion or a in IsStandardConversion()
2343 // qualification conversion (C++ [conv.fctptr], [conv.qual]). in IsStandardConversion()
2346 // Function pointer conversions (removing 'noexcept') including removal of in IsStandardConversion()
2355 // No conversion required in IsStandardConversion()
2360 // [...] Any difference in top-level cv-qualification is in IsStandardConversion()
2362 // a conversion. [...] in IsStandardConversion()
2378 // this is a bad conversion sequence, unless we're resolving an overload in C. in IsStandardConversion()
2394 // incompatible pointer. Note that an IncompatiblePointer conversion can drop in IsStandardConversion()
2405 // First can only be an lvalue conversion, so we pretend that this was the in IsStandardConversion()
2406 // second conversion. First should already be valid from earlier in the in IsStandardConversion()
2412 // conversion. This could also be ICK_Qualification, but it's simpler to just in IsStandardConversion()
2413 // lump everything in with the second conversion, and we don't gain anything in IsStandardConversion()
2427 const RecordType *UT = ToType->getAsUnionType(); in IsTransparentUnionStandardConversion()
2428 if (!UT || !UT->getDecl()->hasAttr<TransparentUnionAttr>()) in IsTransparentUnionStandardConversion()
2431 RecordDecl *UD = UT->getDecl(); in IsTransparentUnionStandardConversion()
2432 // It's compatible if the expression matches any of the fields. in IsTransparentUnionStandardConversion()
2433 for (const auto *it : UD->fields()) { in IsTransparentUnionStandardConversion()
2434 if (IsStandardConversion(S, From, it->getType(), InOverloadResolution, SCS, in IsTransparentUnionStandardConversion()
2436 ToType = it->getType(); in IsTransparentUnionStandardConversion()
2444 const BuiltinType *To = ToType->getAs<BuiltinType>(); in IsIntegralPromotion()
2445 // All integers are built-in. in IsIntegralPromotion()
2450 // An rvalue of type char, signed char, unsigned char, short int, or in IsIntegralPromotion()
2451 // unsigned short int can be converted to an rvalue of type int if in IsIntegralPromotion()
2452 // int can represent all the values of the source type; otherwise, in IsIntegralPromotion()
2453 // the source rvalue can be converted to an rvalue of type unsigned in IsIntegralPromotion()
2455 if (Context.isPromotableIntegerType(FromType) && !FromType->isBooleanType() && in IsIntegralPromotion()
2456 !FromType->isEnumeralType()) { in IsIntegralPromotion()
2458 (FromType->isSignedIntegerType() || in IsIntegralPromotion()
2462 return To->getKind() == BuiltinType::Int; in IsIntegralPromotion()
2465 return To->getKind() == BuiltinType::UInt; in IsIntegralPromotion()
2469 // A prvalue of an unscoped enumeration type whose underlying type is not in IsIntegralPromotion()
2470 // fixed (7.2) can be converted to an rvalue a prvalue of the first of the in IsIntegralPromotion()
2471 // following types that can represent all the values of the enumeration in IsIntegralPromotion()
2474 // long long int. If none of the types in that list can represent all the in IsIntegralPromotion()
2475 // values of the enumeration, an rvalue a prvalue of an unscoped enumeration in IsIntegralPromotion()
2476 // type can be converted to an rvalue a prvalue of the extended integer type in IsIntegralPromotion()
2477 // with lowest integer conversion rank (4.13) greater than the rank of long in IsIntegralPromotion()
2478 // long in which all the values of the enumeration can be represented. If in IsIntegralPromotion()
2481 // A prvalue of an unscoped enumeration type whose underlying type is fixed in IsIntegralPromotion()
2482 // can be converted to a prvalue of its underlying type. Moreover, if in IsIntegralPromotion()
2483 // integral promotion can be applied to its underlying type, a prvalue of an in IsIntegralPromotion()
2485 // converted to a prvalue of the promoted underlying type. in IsIntegralPromotion()
2486 if (const EnumType *FromEnumType = FromType->getAs<EnumType>()) { in IsIntegralPromotion()
2487 // C++0x 7.2p9: Note that this implicit enum to int conversion is not in IsIntegralPromotion()
2489 if (FromEnumType->getDecl()->isScoped()) in IsIntegralPromotion()
2492 // We can perform an integral promotion to the underlying type of the enum, in IsIntegralPromotion()
2495 // the bitfield-ness of the actual source expression. in IsIntegralPromotion()
2496 if (FromEnumType->getDecl()->isFixed()) { in IsIntegralPromotion()
2497 QualType Underlying = FromEnumType->getDecl()->getIntegerType(); in IsIntegralPromotion()
2502 // We have already pre-calculated the promotion type, so this is trivial. in IsIntegralPromotion()
2503 if (ToType->isIntegerType() && in IsIntegralPromotion()
2504 isCompleteType(From->getBeginLoc(), FromType)) in IsIntegralPromotion()
2506 ToType, FromEnumType->getDecl()->getPromotionType()); in IsIntegralPromotion()
2509 // If the bit-field has an enumerated type, it is treated as any other in IsIntegralPromotion()
2510 // value of that type for promotion purposes. in IsIntegralPromotion()
2512 // ... so do not fall through into the bit-field checks below in C++. in IsIntegralPromotion()
2518 // A prvalue of type char16_t, char32_t, or wchar_t (3.9.1) can be converted in IsIntegralPromotion()
2519 // to an rvalue a prvalue of the first of the following types that can in IsIntegralPromotion()
2520 // represent all the values of its underlying type: int, unsigned int, in IsIntegralPromotion()
2522 // If none of the types in that list can represent all the values of its in IsIntegralPromotion()
2523 // underlying type, an rvalue a prvalue of type char16_t, char32_t, in IsIntegralPromotion()
2524 // or wchar_t can be converted to an rvalue a prvalue of its underlying in IsIntegralPromotion()
2526 if (FromType->isAnyCharacterType() && !FromType->isCharType() && in IsIntegralPromotion()
2527 ToType->isIntegerType()) { in IsIntegralPromotion()
2530 bool FromIsSigned = FromType->isSignedIntegerType(); in IsIntegralPromotion()
2534 // order. Try each of these types. in IsIntegralPromotion()
2544 FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) { in IsIntegralPromotion()
2553 // An rvalue for an integral bit-field (9.6) can be converted to an in IsIntegralPromotion()
2554 // rvalue of type int if int can represent all the values of the in IsIntegralPromotion()
2555 // bit-field; otherwise, it can be converted to unsigned int if in IsIntegralPromotion()
2556 // unsigned int can represent all the values of the bit-field. If in IsIntegralPromotion()
2557 // the bit-field is larger yet, no integral promotion applies to in IsIntegralPromotion()
2558 // it. If the bit-field has an enumerated type, it is treated as any in IsIntegralPromotion()
2559 // other value of that type for promotion purposes (C++ 4.5p3). in IsIntegralPromotion()
2560 // FIXME: We should delay checking of bit-fields until we actually perform the in IsIntegralPromotion()
2561 // conversion. in IsIntegralPromotion()
2563 // FIXME: In C, only bit-fields of types _Bool, int, or unsigned int may be in IsIntegralPromotion()
2564 // promoted, per C11 6.3.1.1/2. We promote all bit-fields (including enum in IsIntegralPromotion()
2565 // bit-fields and those whose underlying type is larger than int) for GCC in IsIntegralPromotion()
2568 if (FieldDecl *MemberDecl = From->getSourceBitField()) { in IsIntegralPromotion()
2570 if (FromType->isIntegralType(Context) && in IsIntegralPromotion()
2572 MemberDecl->getBitWidth()->getIntegerConstantExpr(Context))) { in IsIntegralPromotion()
2573 llvm::APSInt ToSize(BitWidth->getBitWidth(), BitWidth->isUnsigned()); in IsIntegralPromotion()
2578 (FromType->isSignedIntegerType() && *BitWidth <= ToSize)) { in IsIntegralPromotion()
2579 return To->getKind() == BuiltinType::Int; in IsIntegralPromotion()
2584 if (FromType->isUnsignedIntegerType() && *BitWidth <= ToSize) { in IsIntegralPromotion()
2585 return To->getKind() == BuiltinType::UInt; in IsIntegralPromotion()
2593 // An rvalue of type bool can be converted to an rvalue of type int, in IsIntegralPromotion()
2595 if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) { in IsIntegralPromotion()
2599 // In HLSL an rvalue of integral type can be promoted to an rvalue of a larger in IsIntegralPromotion()
2601 if (Context.getLangOpts().HLSL && FromType->isIntegerType() && in IsIntegralPromotion()
2602 ToType->isIntegerType()) in IsIntegralPromotion()
2609 if (const BuiltinType *FromBuiltin = FromType->getAs<BuiltinType>()) in IsFloatingPointPromotion()
2610 if (const BuiltinType *ToBuiltin = ToType->getAs<BuiltinType>()) { in IsFloatingPointPromotion()
2611 /// An rvalue of type float can be converted to an rvalue of type in IsFloatingPointPromotion()
2613 if (FromBuiltin->getKind() == BuiltinType::Float && in IsFloatingPointPromotion()
2614 ToBuiltin->getKind() == BuiltinType::Double) in IsFloatingPointPromotion()
2621 (FromBuiltin->getKind() == BuiltinType::Float || in IsFloatingPointPromotion()
2622 FromBuiltin->getKind() == BuiltinType::Double) && in IsFloatingPointPromotion()
2623 (ToBuiltin->getKind() == BuiltinType::LongDouble || in IsFloatingPointPromotion()
2624 ToBuiltin->getKind() == BuiltinType::Float128 || in IsFloatingPointPromotion()
2625 ToBuiltin->getKind() == BuiltinType::Ibm128)) in IsFloatingPointPromotion()
2628 // In HLSL, `half` promotes to `float` or `double`, regardless of whether in IsFloatingPointPromotion()
2630 if (getLangOpts().HLSL && FromBuiltin->getKind() == BuiltinType::Half && in IsFloatingPointPromotion()
2631 (ToBuiltin->getKind() == BuiltinType::Float || in IsFloatingPointPromotion()
2632 ToBuiltin->getKind() == BuiltinType::Double)) in IsFloatingPointPromotion()
2637 FromBuiltin->getKind() == BuiltinType::Half && in IsFloatingPointPromotion()
2638 ToBuiltin->getKind() == BuiltinType::Float) in IsFloatingPointPromotion()
2646 const ComplexType *FromComplex = FromType->getAs<ComplexType>(); in IsComplexPromotion()
2650 const ComplexType *ToComplex = ToType->getAs<ComplexType>(); in IsComplexPromotion()
2654 return IsFloatingPointPromotion(FromComplex->getElementType(), in IsComplexPromotion()
2655 ToComplex->getElementType()) || in IsComplexPromotion()
2656 IsIntegralPromotion(nullptr, FromComplex->getElementType(), in IsComplexPromotion()
2657 ToComplex->getElementType()); in IsComplexPromotion()
2660 /// BuildSimilarlyQualifiedPointerType - In a pointer conversion from
2663 /// if non-empty, will be a pointer to ToType that may or may not have
2664 /// the right set of qualifiers on its pointee.
2671 assert((FromPtr->getTypeClass() == Type::Pointer || in BuildSimilarlyQualifiedPointerType()
2672 FromPtr->getTypeClass() == Type::ObjCObjectPointer) && in BuildSimilarlyQualifiedPointerType()
2673 "Invalid similarly-qualified pointer type"); in BuildSimilarlyQualifiedPointerType()
2675 /// Conversions to 'id' subsume cv-qualifier conversions. in BuildSimilarlyQualifiedPointerType()
2676 if (ToType->isObjCIdType() || ToType->isObjCQualifiedIdType()) in BuildSimilarlyQualifiedPointerType()
2680 = Context.getCanonicalType(FromPtr->getPointeeType()); in BuildSimilarlyQualifiedPointerType()
2687 // Exact qualifier match -> return the pointer type we're converting to. in BuildSimilarlyQualifiedPointerType()
2712 // Handle value-dependent integral null pointer constants correctly. in isNullPointerConstantForConversion()
2713 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903 in isNullPointerConstantForConversion()
2714 if (Expr->isValueDependent() && !Expr->isTypeDependent() && in isNullPointerConstantForConversion()
2715 Expr->getType()->isIntegerType() && !Expr->getType()->isEnumeralType()) in isNullPointerConstantForConversion()
2718 return Expr->isNullPointerConstant(Context, in isNullPointerConstantForConversion()
2732 // Conversion from a null pointer constant to any Objective-C pointer type. in IsPointerConversion()
2733 if (ToType->isObjCObjectPointerType() && in IsPointerConversion()
2740 if (FromType->isBlockPointerType() && ToType->isPointerType() && in IsPointerConversion()
2741 ToType->castAs<PointerType>()->getPointeeType()->isVoidType()) { in IsPointerConversion()
2747 if (ToType->isBlockPointerType() && in IsPointerConversion()
2753 // If the left-hand-side is nullptr_t, the right side can be a null in IsPointerConversion()
2755 if (ToType->isNullPtrType() && in IsPointerConversion()
2761 const PointerType* ToTypePtr = ToType->getAs<PointerType>(); in IsPointerConversion()
2772 // , including objective-c pointers. in IsPointerConversion()
2773 QualType ToPointeeType = ToTypePtr->getPointeeType(); in IsPointerConversion()
2774 if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType() && in IsPointerConversion()
2777 FromType->castAs<ObjCObjectPointerType>(), ToPointeeType, ToType, in IsPointerConversion()
2781 const PointerType *FromTypePtr = FromType->getAs<PointerType>(); in IsPointerConversion()
2785 QualType FromPointeeType = FromTypePtr->getPointeeType(); in IsPointerConversion()
2788 // pointer conversion, so don't do all of the work below. in IsPointerConversion()
2792 // An rvalue of type "pointer to cv T," where T is an object type, in IsPointerConversion()
2793 // can be converted to an rvalue of type "pointer to cv void" (C++ in IsPointerConversion()
2795 if (FromPointeeType->isIncompleteOrObjectType() && in IsPointerConversion()
2796 ToPointeeType->isVoidType()) { in IsPointerConversion()
2804 // MSVC allows implicit function to void* type conversion. in IsPointerConversion()
2805 if (getLangOpts().MSVCCompat && FromPointeeType->isFunctionType() && in IsPointerConversion()
2806 ToPointeeType->isVoidType()) { in IsPointerConversion()
2813 // When we're overloading in C, we allow a special kind of pointer in IsPointerConversion()
2814 // conversion for compatible-but-not-identical pointee types. in IsPointerConversion()
2825 // An rvalue of type "pointer to cv D," where D is a class type, in IsPointerConversion()
2826 // can be converted to an rvalue of type "pointer to cv B," where in IsPointerConversion()
2827 // B is a base class (clause 10) of D. If B is an inaccessible in IsPointerConversion()
2828 // (clause 11) or ambiguous (10.2) base class of D, a program that in IsPointerConversion()
2829 // necessitates this conversion is ill-formed. The result of the in IsPointerConversion()
2830 // conversion is a pointer to the base class sub-object of the in IsPointerConversion()
2832 // the null pointer value of the destination type. in IsPointerConversion()
2836 if (getLangOpts().CPlusPlus && FromPointeeType->isRecordType() && in IsPointerConversion()
2837 ToPointeeType->isRecordType() && in IsPointerConversion()
2839 IsDerivedFrom(From->getBeginLoc(), FromPointeeType, ToPointeeType)) { in IsPointerConversion()
2846 if (FromPointeeType->isVectorType() && ToPointeeType->isVectorType() && in IsPointerConversion()
2877 // The set of qualifiers on the type we're converting from. in isObjCPointerConversion()
2882 ToType->getAs<ObjCObjectPointerType>(); in isObjCPointerConversion()
2884 FromType->getAs<ObjCObjectPointerType>(); in isObjCPointerConversion()
2888 // then this is not a pointer conversion. in isObjCPointerConversion()
2889 if (Context.hasSameUnqualifiedType(ToObjCPtr->getPointeeType(), in isObjCPointerConversion()
2890 FromObjCPtr->getPointeeType())) in isObjCPointerConversion()
2893 // Conversion between Objective-C pointers. in isObjCPointerConversion()
2895 const ObjCInterfaceType* LHS = ToObjCPtr->getInterfaceType(); in isObjCPointerConversion()
2896 const ObjCInterfaceType* RHS = FromObjCPtr->getInterfaceType(); in isObjCPointerConversion()
2898 !ToObjCPtr->getPointeeType().isAtLeastAsQualifiedAs( in isObjCPointerConversion()
2899 FromObjCPtr->getPointeeType())) in isObjCPointerConversion()
2902 ToObjCPtr->getPointeeType(), in isObjCPointerConversion()
2909 // Okay: this is some kind of implicit downcast of Objective-C in isObjCPointerConversion()
2914 ToObjCPtr->getPointeeType(), in isObjCPointerConversion()
2922 if (const PointerType *ToCPtr = ToType->getAs<PointerType>()) in isObjCPointerConversion()
2923 ToPointeeType = ToCPtr->getPointeeType(); in isObjCPointerConversion()
2925 ToType->getAs<BlockPointerType>()) { in isObjCPointerConversion()
2928 if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) { in isObjCPointerConversion()
2932 ToPointeeType = ToBlockPtr->getPointeeType(); in isObjCPointerConversion()
2934 else if (FromType->getAs<BlockPointerType>() && in isObjCPointerConversion()
2935 ToObjCPtr && ToObjCPtr->isObjCBuiltinType()) { in isObjCPointerConversion()
2945 if (const PointerType *FromCPtr = FromType->getAs<PointerType>()) in isObjCPointerConversion()
2946 FromPointeeType = FromCPtr->getPointeeType(); in isObjCPointerConversion()
2948 FromType->getAs<BlockPointerType>()) in isObjCPointerConversion()
2949 FromPointeeType = FromBlockPtr->getPointeeType(); in isObjCPointerConversion()
2954 // is an Objective-C conversion. in isObjCPointerConversion()
2955 if (FromPointeeType->isPointerType() && ToPointeeType->isPointerType() && in isObjCPointerConversion()
2958 // We always complain about this conversion. in isObjCPointerConversion()
2964 // Allow conversion of pointee being objective-c pointer to another one; in isObjCPointerConversion()
2966 if (FromPointeeType->getAs<ObjCObjectPointerType>() && in isObjCPointerConversion()
2967 ToPointeeType->getAs<ObjCObjectPointerType>() && in isObjCPointerConversion()
2977 // differences in the argument and result types are in Objective-C in isObjCPointerConversion()
2978 // pointer conversions. If so, we permit the conversion (but in isObjCPointerConversion()
2981 = FromPointeeType->getAs<FunctionProtoType>(); in isObjCPointerConversion()
2983 = ToPointeeType->getAs<FunctionProtoType>(); in isObjCPointerConversion()
2986 // Objective-C pointer conversion. in isObjCPointerConversion()
2993 if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() || in isObjCPointerConversion()
2994 FromFunctionType->isVariadic() != ToFunctionType->isVariadic() || in isObjCPointerConversion()
2995 FromFunctionType->getMethodQuals() != ToFunctionType->getMethodQuals()) in isObjCPointerConversion()
2999 if (Context.getCanonicalType(FromFunctionType->getReturnType()) == in isObjCPointerConversion()
3000 Context.getCanonicalType(ToFunctionType->getReturnType())) { in isObjCPointerConversion()
3002 } else if (isObjCPointerConversion(FromFunctionType->getReturnType(), in isObjCPointerConversion()
3003 ToFunctionType->getReturnType(), in isObjCPointerConversion()
3005 // Okay, we have an Objective-C pointer conversion. in isObjCPointerConversion()
3013 for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams(); in isObjCPointerConversion()
3015 QualType FromArgType = FromFunctionType->getParamType(ArgIdx); in isObjCPointerConversion()
3016 QualType ToArgType = ToFunctionType->getParamType(ArgIdx); in isObjCPointerConversion()
3022 // Okay, we have an Objective-C pointer conversion. in isObjCPointerConversion()
3031 // We had an Objective-C conversion. Allow this pointer in isObjCPointerConversion()
3032 // conversion, but complain about it. in isObjCPointerConversion()
3046 ToType->getAs<BlockPointerType>()) in IsBlockPointerConversion()
3047 ToPointeeType = ToBlockPtr->getPointeeType(); in IsBlockPointerConversion()
3053 FromType->getAs<BlockPointerType>()) in IsBlockPointerConversion()
3054 FromPointeeType = FromBlockPtr->getPointeeType(); in IsBlockPointerConversion()
3058 // differences in the argument and result types are in Objective-C in IsBlockPointerConversion()
3059 // pointer conversions. If so, we permit the conversion. in IsBlockPointerConversion()
3062 = FromPointeeType->getAs<FunctionProtoType>(); in IsBlockPointerConversion()
3064 = ToPointeeType->getAs<FunctionProtoType>(); in IsBlockPointerConversion()
3074 if (FromFunctionType->getNumParams() != ToFunctionType->getNumParams() || in IsBlockPointerConversion()
3075 FromFunctionType->isVariadic() != ToFunctionType->isVariadic()) in IsBlockPointerConversion()
3078 FunctionType::ExtInfo FromEInfo = FromFunctionType->getExtInfo(); in IsBlockPointerConversion()
3079 FunctionType::ExtInfo ToEInfo = ToFunctionType->getExtInfo(); in IsBlockPointerConversion()
3084 if (Context.hasSameType(FromFunctionType->getReturnType(), in IsBlockPointerConversion()
3085 ToFunctionType->getReturnType())) { in IsBlockPointerConversion()
3088 QualType RHS = FromFunctionType->getReturnType(); in IsBlockPointerConversion()
3089 QualType LHS = ToFunctionType->getReturnType(); in IsBlockPointerConversion()
3090 if ((!getLangOpts().CPlusPlus || !RHS->isRecordType()) && in IsBlockPointerConversion()
3100 // Okay, we have an Objective-C pointer conversion. in IsBlockPointerConversion()
3107 for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumParams(); in IsBlockPointerConversion()
3110 QualType FromArgType = FromFunctionType->getParamType(ArgIdx); in IsBlockPointerConversion()
3111 QualType ToArgType = ToFunctionType->getParamType(ArgIdx); in IsBlockPointerConversion()
3118 // Okay, we have an Objective-C pointer conversion. in IsBlockPointerConversion()
3148 if (auto *FPT = FromType->getAs<FunctionProtoType>()) in tryGetFunctionProtoType()
3151 if (auto *MPT = FromType->getAs<MemberPointerType>()) in tryGetFunctionProtoType()
3152 return MPT->getPointeeType()->getAs<FunctionProtoType>(); in tryGetFunctionProtoType()
3166 if (FromType->isMemberPointerType() && ToType->isMemberPointerType()) { in HandleFunctionTypeMismatch()
3167 const auto *FromMember = FromType->castAs<MemberPointerType>(), in HandleFunctionTypeMismatch()
3168 *ToMember = ToType->castAs<MemberPointerType>(); in HandleFunctionTypeMismatch()
3169 if (!Context.hasSameType(FromMember->getClass(), ToMember->getClass())) { in HandleFunctionTypeMismatch()
3170 PDiag << ft_different_class << QualType(ToMember->getClass(), 0) in HandleFunctionTypeMismatch()
3171 << QualType(FromMember->getClass(), 0); in HandleFunctionTypeMismatch()
3174 FromType = FromMember->getPointeeType(); in HandleFunctionTypeMismatch()
3175 ToType = ToMember->getPointeeType(); in HandleFunctionTypeMismatch()
3178 if (FromType->isPointerType()) in HandleFunctionTypeMismatch()
3179 FromType = FromType->getPointeeType(); in HandleFunctionTypeMismatch()
3180 if (ToType->isPointerType()) in HandleFunctionTypeMismatch()
3181 ToType = ToType->getPointeeType(); in HandleFunctionTypeMismatch()
3187 // Don't print extra info for non-specialized template functions. in HandleFunctionTypeMismatch()
3188 if (FromType->isInstantiationDependentType() && in HandleFunctionTypeMismatch()
3189 !FromType->getAs<TemplateSpecializationType>()) { in HandleFunctionTypeMismatch()
3209 if (FromFunction->getNumParams() != ToFunction->getNumParams()) { in HandleFunctionTypeMismatch()
3210 PDiag << ft_parameter_arity << ToFunction->getNumParams() in HandleFunctionTypeMismatch()
3211 << FromFunction->getNumParams(); in HandleFunctionTypeMismatch()
3219 << ToFunction->getParamType(ArgPos) in HandleFunctionTypeMismatch()
3220 << FromFunction->getParamType(ArgPos); in HandleFunctionTypeMismatch()
3225 if (!Context.hasSameType(FromFunction->getReturnType(), in HandleFunctionTypeMismatch()
3226 ToFunction->getReturnType())) { in HandleFunctionTypeMismatch()
3227 PDiag << ft_return_type << ToFunction->getReturnType() in HandleFunctionTypeMismatch()
3228 << FromFunction->getReturnType(); in HandleFunctionTypeMismatch()
3232 if (FromFunction->getMethodQuals() != ToFunction->getMethodQuals()) { in HandleFunctionTypeMismatch()
3233 PDiag << ft_qualifer_mismatch << ToFunction->getMethodQuals() in HandleFunctionTypeMismatch()
3234 << FromFunction->getMethodQuals(); in HandleFunctionTypeMismatch()
3240 if (cast<FunctionProtoType>(FromFunction->getCanonicalTypeUnqualified()) in HandleFunctionTypeMismatch()
3241 ->isNothrow() != in HandleFunctionTypeMismatch()
3242 cast<FunctionProtoType>(ToFunction->getCanonicalTypeUnqualified()) in HandleFunctionTypeMismatch()
3243 ->isNothrow()) { in HandleFunctionTypeMismatch()
3256 "Can't compare parameters of functions with different number of " in FunctionParamTypesAreEqual()
3260 // Reverse iterate over the parameters of `OldType` if `Reversed` is true. in FunctionParamTypesAreEqual()
3261 size_t J = Reversed ? (llvm::size(New) - Idx - 1) : Idx; in FunctionParamTypesAreEqual()
3268 Context.removePtrSizeAddrSpace((New.begin() + J)->getUnqualifiedType()); in FunctionParamTypesAreEqual()
3282 return FunctionParamTypesAreEqual(OldType->param_types(), in FunctionParamTypesAreEqual()
3283 NewType->param_types(), ArgPos, Reversed); in FunctionParamTypesAreEqual()
3291 if (OldFunction->getNumNonObjectParams() != in FunctionNonObjectParamTypesAreEqual()
3292 NewFunction->getNumNonObjectParams()) in FunctionNonObjectParamTypesAreEqual()
3296 unsigned(OldFunction->hasCXXExplicitFunctionObjectParameter()); in FunctionNonObjectParamTypesAreEqual()
3298 unsigned(NewFunction->hasCXXExplicitFunctionObjectParameter()); in FunctionNonObjectParamTypesAreEqual()
3300 auto *OldPT = cast<FunctionProtoType>(OldFunction->getFunctionType()); in FunctionNonObjectParamTypesAreEqual()
3301 auto *NewPT = cast<FunctionProtoType>(NewFunction->getFunctionType()); in FunctionNonObjectParamTypesAreEqual()
3303 return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore), in FunctionNonObjectParamTypesAreEqual()
3304 NewPT->param_types().slice(NewIgnore), in FunctionNonObjectParamTypesAreEqual()
3313 QualType FromType = From->getType(); in CheckPointerConversion()
3318 if (Diagnose && !IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() && in CheckPointerConversion()
3319 From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) == in CheckPointerConversion()
3321 if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy)) in CheckPointerConversion()
3322 DiagRuntimeBehavior(From->getExprLoc(), From, in CheckPointerConversion()
3324 << ToType << From->getSourceRange()); in CheckPointerConversion()
3326 Diag(From->getExprLoc(), diag::warn_non_literal_null_pointer) in CheckPointerConversion()
3327 << ToType << From->getSourceRange(); in CheckPointerConversion()
3329 if (const PointerType *ToPtrType = ToType->getAs<PointerType>()) { in CheckPointerConversion()
3330 if (const PointerType *FromPtrType = FromType->getAs<PointerType>()) { in CheckPointerConversion()
3331 QualType FromPointeeType = FromPtrType->getPointeeType(), in CheckPointerConversion()
3332 ToPointeeType = ToPtrType->getPointeeType(); in CheckPointerConversion()
3334 if (FromPointeeType->isRecordType() && ToPointeeType->isRecordType() && in CheckPointerConversion()
3336 // We must have a derived-to-base conversion. Check an in CheckPointerConversion()
3337 // ambiguous or inaccessible conversion. in CheckPointerConversion()
3346 From->getExprLoc(), From->getSourceRange(), DeclarationName(), in CheckPointerConversion()
3350 // The conversion was successful. in CheckPointerConversion()
3355 FromPointeeType->isFunctionType() && ToPointeeType->isVoidType()) { in CheckPointerConversion()
3358 Diag(From->getExprLoc(), diag::ext_ms_impcast_fn_obj) in CheckPointerConversion()
3359 << From->getSourceRange(); in CheckPointerConversion()
3363 ToType->getAs<ObjCObjectPointerType>()) { in CheckPointerConversion()
3365 FromType->getAs<ObjCObjectPointerType>()) { in CheckPointerConversion()
3366 // Objective-C++ conversions are always okay. in CheckPointerConversion()
3367 // FIXME: We should have a different class of conversions for the in CheckPointerConversion()
3368 // Objective-C++ implicit conversions. in CheckPointerConversion()
3369 if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType()) in CheckPointerConversion()
3371 } else if (FromType->isBlockPointerType()) { in CheckPointerConversion()
3376 } else if (ToType->isBlockPointerType()) { in CheckPointerConversion()
3377 if (!FromType->isBlockPointerType()) in CheckPointerConversion()
3383 if (From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) in CheckPointerConversion()
3393 const MemberPointerType *ToTypePtr = ToType->getAs<MemberPointerType>(); in IsMemberPointerConversion()
3398 if (From->isNullPointerConstant(Context, in IsMemberPointerConversion()
3406 const MemberPointerType *FromTypePtr = FromType->getAs<MemberPointerType>(); in IsMemberPointerConversion()
3410 // A pointer to member of B can be converted to a pointer to member of D, in IsMemberPointerConversion()
3412 QualType FromClass(FromTypePtr->getClass(), 0); in IsMemberPointerConversion()
3413 QualType ToClass(ToTypePtr->getClass(), 0); in IsMemberPointerConversion()
3416 IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass)) { in IsMemberPointerConversion()
3417 ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(), in IsMemberPointerConversion()
3429 QualType FromType = From->getType(); in CheckMemberPointerConversion()
3430 const MemberPointerType *FromPtrType = FromType->getAs<MemberPointerType>(); in CheckMemberPointerConversion()
3432 // This must be a null pointer to member pointer conversion in CheckMemberPointerConversion()
3433 assert(From->isNullPointerConstant(Context, in CheckMemberPointerConversion()
3440 const MemberPointerType *ToPtrType = ToType->getAs<MemberPointerType>(); in CheckMemberPointerConversion()
3444 QualType FromClass = QualType(FromPtrType->getClass(), 0); in CheckMemberPointerConversion()
3445 QualType ToClass = QualType(ToPtrType->getClass(), 0); in CheckMemberPointerConversion()
3448 assert(FromClass->isRecordType() && "Pointer into non-class."); in CheckMemberPointerConversion()
3449 assert(ToClass->isRecordType() && "Pointer into non-class."); in CheckMemberPointerConversion()
3454 IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass, Paths); in CheckMemberPointerConversion()
3462 Diag(From->getExprLoc(), diag::err_ambiguous_memptr_conv) in CheckMemberPointerConversion()
3463 << 0 << FromClass << ToClass << PathDisplayStr << From->getSourceRange(); in CheckMemberPointerConversion()
3468 Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual) in CheckMemberPointerConversion()
3470 << From->getSourceRange(); in CheckMemberPointerConversion()
3475 CheckBaseClassAccess(From->getExprLoc(), FromClass, ToClass, in CheckMemberPointerConversion()
3479 // Must be a base to derived member conversion. in CheckMemberPointerConversion()
3485 /// Determine whether the lifetime conversion between the two given
3497 /// Perform a single iteration of the loop for checking if a qualification
3498 /// conversion is valid.
3500 /// Specifically, check whether any change between the qualifiers of \p
3502 /// outer layer is const-qualified.
3513 // Objective-C ARC: in isQualificationConversionStep()
3514 // Check Objective-C lifetime conversions. in isQualificationConversionStep()
3523 // Objective-C lifetime qualifiers. in isQualificationConversionStep()
3528 // Allow addition/removal of GC attributes but not changing GC attributes. in isQualificationConversionStep()
3535 // -- for every j > 0, if const is in cv 1,j then const is in cv in isQualificationConversionStep()
3541 // - in top level it is only valid to convert to addr space that is a in isQualificationConversionStep()
3542 // superset in all cases apart from C-style casts where we allow in isQualificationConversionStep()
3544 // - in non-top levels it is not a valid conversion. in isQualificationConversionStep()
3551 // -- if the cv 1,j and cv 2,j are different, then const is in in isQualificationConversionStep()
3557 // The following wording is from C++20, where the result of the conversion in isQualificationConversionStep()
3559 // -- if [...] P1,i [...] is "array of unknown bound of", P3,i is in isQualificationConversionStep()
3560 // "array of unknown bound of" in isQualificationConversionStep()
3561 if (FromType->isIncompleteArrayType() && !ToType->isIncompleteArrayType()) in isQualificationConversionStep()
3564 // -- if the resulting P3,i is different from P1,i [...], then const is in isQualificationConversionStep()
3566 if (!CStyle && FromType->isConstantArrayType() && in isQualificationConversionStep()
3567 ToType->isIncompleteArrayType() && !PreviousToQualsIncludeConst) in isQualificationConversionStep()
3570 // Keep track of whether all prior cv-qualifiers in the "to" type in isQualificationConversionStep()
3585 // qualification conversion. in IsQualificationConversion()
3590 // A conversion can add cv-qualifiers at levels other than the first in IsQualificationConversion()
3591 // in multi-level pointers, subject to the following rules: [...] in IsQualificationConversion()
3604 // of times. If we unwrapped any pointers, and if FromType and in IsQualificationConversion()
3606 // qualifiers above), then this is a qualification conversion. in IsQualificationConversion()
3610 /// - Determine whether this is a conversion from a scalar type to an
3613 /// If successful, updates \c SCS's second and third steps in the conversion
3614 /// sequence to finish the conversion.
3619 const AtomicType *ToAtomic = ToType->getAs<AtomicType>(); in tryAtomicConversion()
3624 if (!IsStandardConversion(S, From, ToAtomic->getValueType(), in tryAtomicConversion()
3641 const auto *CtorType = Constructor->getType()->castAs<FunctionProtoType>(); in isFirstArgumentCompatibleWithType()
3642 if (CtorType->getNumParams() > 0) { in isFirstArgumentCompatibleWithType()
3643 QualType FirstArg = CtorType->getParamType(0); in isFirstArgumentCompatibleWithType()
3662 bool Usable = !Info.Constructor->isInvalidDecl() && in IsInitializerListConstructorConversion()
3683 CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) { in IsInitializerListConstructorConversion()
3686 // Record the standard conversion we used and the conversion function. in IsInitializerListConstructorConversion()
3687 CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Best->Function); in IsInitializerListConstructorConversion()
3688 QualType ThisType = Constructor->getFunctionObjectParameterType(); in IsInitializerListConstructorConversion()
3693 User.FoundConversionFunction = Best->FoundDecl; in IsInitializerListConstructorConversion()
3709 /// Determines whether there is a user-defined conversion sequence
3711 /// ToType. If such a conversion exists, User will contain the
3712 /// user-defined conversion sequence that performs such a conversion
3716 /// \param AllowExplicit true if the conversion should consider C++0x
3717 /// "explicit" conversion functions as well as non-explicit conversion
3720 /// \param AllowObjCConversionOnExplicit true if the conversion should
3721 /// allow an extra Objective-C pointer conversion on uses of explicit
3736 // If the type we are conversion to is a class type, enumerate its in IsUserDefinedConversion()
3738 if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) { in IsUserDefinedConversion()
3740 // When objects of class type are direct-initialized (8.5), or in IsUserDefinedConversion()
3741 // copy-initialized from an expression of the same or a in IsUserDefinedConversion()
3743 // constructor. [...] For copy-initialization, the candidate in IsUserDefinedConversion()
3744 // functions are all the converting constructors (12.3.1) of in IsUserDefinedConversion()
3745 // that class. The argument list is the expression-list within in IsUserDefinedConversion()
3746 // the parentheses of the initializer. in IsUserDefinedConversion()
3747 if (S.Context.hasSameUnqualifiedType(ToType, From->getType()) || in IsUserDefinedConversion()
3748 (From->getType()->getAs<RecordType>() && in IsUserDefinedConversion()
3749 S.IsDerivedFrom(From->getBeginLoc(), From->getType(), ToType))) in IsUserDefinedConversion()
3752 if (!S.isCompleteType(From->getExprLoc(), ToType)) { in IsUserDefinedConversion()
3755 = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) { in IsUserDefinedConversion()
3761 // But first, see if there is an init-list-constructor that will work. in IsUserDefinedConversion()
3771 // If we're list-initializing, we pass the individual elements as in IsUserDefinedConversion()
3773 Args = InitList->getInits(); in IsUserDefinedConversion()
3774 NumArgs = InitList->getNumInits(); in IsUserDefinedConversion()
3783 bool Usable = !Info.Constructor->isInvalidDecl(); in IsUserDefinedConversion()
3785 Usable = Usable && Info.Constructor->isConvertingConstructor( in IsUserDefinedConversion()
3790 // if the target is the first parameter of a constructor [of class in IsUserDefinedConversion()
3792 // phase of [over.match.list] when the initializer list has exactly in IsUserDefinedConversion()
3794 // conversion is to X or reference to cv X, user-defined conversion in IsUserDefinedConversion()
3810 // Allow one user-defined conversion when user specifies a in IsUserDefinedConversion()
3811 // From->ToType conversion via an static cast (c-style, etc). in IsUserDefinedConversion()
3822 // Enumerate conversion functions, if we're allowed to. in IsUserDefinedConversion()
3824 } else if (!S.isCompleteType(From->getBeginLoc(), From->getType())) { in IsUserDefinedConversion()
3825 // No conversion functions from incomplete types. in IsUserDefinedConversion()
3827 From->getType()->getAs<RecordType>()) { in IsUserDefinedConversion()
3829 = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) { in IsUserDefinedConversion()
3830 // Add all of the conversion functions as candidates. in IsUserDefinedConversion()
3831 const auto &Conversions = FromRecordDecl->getVisibleConversionFunctions(); in IsUserDefinedConversion()
3832 for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { in IsUserDefinedConversion()
3835 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); in IsUserDefinedConversion()
3837 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in IsUserDefinedConversion()
3842 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in IsUserDefinedConversion()
3863 CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) { in IsUserDefinedConversion()
3866 // Record the standard conversion we used and the conversion function. in IsUserDefinedConversion()
3868 = dyn_cast<CXXConstructorDecl>(Best->Function)) { in IsUserDefinedConversion()
3870 // If the user-defined conversion is specified by a in IsUserDefinedConversion()
3871 // constructor (12.3.1), the initial standard conversion in IsUserDefinedConversion()
3873 // the argument of the constructor. in IsUserDefinedConversion()
3879 if (Best->Conversions[0].isEllipsis()) in IsUserDefinedConversion()
3882 User.Before = Best->Conversions[0].Standard; in IsUserDefinedConversion()
3888 User.FoundConversionFunction = Best->FoundDecl; in IsUserDefinedConversion()
3890 User.After.setFromType(Constructor->getFunctionObjectParameterType()); in IsUserDefinedConversion()
3894 if (CXXConversionDecl *Conversion in IsUserDefinedConversion() local
3895 = dyn_cast<CXXConversionDecl>(Best->Function)) { in IsUserDefinedConversion()
3898 // [...] If the user-defined conversion is specified by a in IsUserDefinedConversion()
3899 // conversion function (12.3.2), the initial standard in IsUserDefinedConversion()
3900 // conversion sequence converts the source type to the in IsUserDefinedConversion()
3901 // implicit object parameter of the conversion function. in IsUserDefinedConversion()
3902 User.Before = Best->Conversions[0].Standard; in IsUserDefinedConversion()
3904 User.ConversionFunction = Conversion; in IsUserDefinedConversion()
3905 User.FoundConversionFunction = Best->FoundDecl; in IsUserDefinedConversion()
3909 // The second standard conversion sequence converts the in IsUserDefinedConversion()
3910 // result of the user-defined conversion to the target type in IsUserDefinedConversion()
3911 // for the sequence. Since an implicit conversion sequence in IsUserDefinedConversion()
3913 // initialization by user-defined conversion apply when in IsUserDefinedConversion()
3914 // selecting the best user-defined conversion for a in IsUserDefinedConversion()
3915 // user-defined conversion sequence (see 13.3.3 and in IsUserDefinedConversion()
3917 User.After = Best->FinalConversion; in IsUserDefinedConversion()
3920 llvm_unreachable("Not a constructor or conversion function?"); in IsUserDefinedConversion()
3935 OverloadCandidateSet CandidateSet(From->getExprLoc(), in DiagnoseMultipleUserDefinedConversion()
3950 Diag(From->getBeginLoc(), diag::err_typecheck_ambiguous_condition) in DiagnoseMultipleUserDefinedConversion()
3951 << From->getType() << ToType << From->getSourceRange(); in DiagnoseMultipleUserDefinedConversion()
3953 if (!RequireCompleteType(From->getBeginLoc(), ToType, in DiagnoseMultipleUserDefinedConversion()
3955 From->getType(), From->getSourceRange())) in DiagnoseMultipleUserDefinedConversion()
3956 Diag(From->getBeginLoc(), diag::err_typecheck_nonviable_condition) in DiagnoseMultipleUserDefinedConversion()
3957 << false << From->getType() << From->getSourceRange() << ToType; in DiagnoseMultipleUserDefinedConversion()
3966 // conversion-operator return value 'points' to, or nullptr.
3969 const FunctionType *ConvFuncTy = Conv->getType()->castAs<FunctionType>(); in getConversionOpReturnTyAsFunction()
3971 ConvFuncTy->getReturnType()->getAs<PointerType>(); in getConversionOpReturnTyAsFunction()
3976 return RetPtrTy->getPointeeType()->getAs<FunctionType>(); in getConversionOpReturnTyAsFunction()
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()) in compareConversionFunctions()
3993 // Objective-C++: in compareConversionFunctions()
3994 // If both conversion functions are implicitly-declared conversions from in compareConversionFunctions()
3996 // respectively, always prefer the conversion to a function pointer, in compareConversionFunctions()
4000 bool Block1 = Conv1->getConversionType()->isBlockPointerType(); in compareConversionFunctions()
4001 bool Block2 = Conv2->getConversionType()->isBlockPointerType(); in compareConversionFunctions()
4007 // In order to support multiple calling conventions for the lambda conversion in compareConversionFunctions()
4009 // different), prefer the 'free' mechanism, followed by the calling-convention in compareConversionFunctions()
4010 // of operator(). The latter is in place to support the MSVC-like solution of in compareConversionFunctions()
4011 // defining ALL of the possible conversions in regards to calling-convention. in compareConversionFunctions()
4016 Conv1FuncRet->getCallConv() != Conv2FuncRet->getCallConv()) { in compareConversionFunctions()
4017 CallingConv Conv1CC = Conv1FuncRet->getCallConv(); in compareConversionFunctions()
4018 CallingConv Conv2CC = Conv2FuncRet->getCallConv(); in compareConversionFunctions()
4020 CXXMethodDecl *CallOp = Conv2->getParent()->getLambdaCallOperator(); in compareConversionFunctions()
4021 const auto *CallOpProto = CallOp->getType()->castAs<FunctionProtoType>(); in compareConversionFunctions()
4024 CallOp->getType()->castAs<FunctionType>()->getCallConv(); in compareConversionFunctions()
4026 CallOpProto->isVariadic(), /*IsCXXMethod=*/false); in compareConversionFunctions()
4028 CallOpProto->isVariadic(), /*IsCXXMethod=*/true); in compareConversionFunctions()
4049 /// CompareImplicitConversionSequences - Compare two implicit
4050 /// conversion sequences to determine whether one is better than the
4057 // (C++ 13.3.3.2p2): When comparing the basic forms of implicit in CompareImplicitConversionSequences()
4058 // conversion sequences (as defined in 13.3.3.1) in CompareImplicitConversionSequences()
4059 // -- a standard conversion sequence (13.3.3.1.1) is a better in CompareImplicitConversionSequences()
4060 // conversion sequence than a user-defined conversion sequence or in CompareImplicitConversionSequences()
4061 // an ellipsis conversion sequence, and in CompareImplicitConversionSequences()
4062 // -- a user-defined conversion sequence (13.3.3.1.2) is a better in CompareImplicitConversionSequences()
4063 // conversion sequence than an ellipsis conversion sequence in CompareImplicitConversionSequences()
4067 // For the purpose of ranking implicit conversion sequences as in CompareImplicitConversionSequences()
4068 // described in 13.3.3.2, the ambiguous conversion sequence is in CompareImplicitConversionSequences()
4069 // treated as a user-defined sequence that is indistinguishable in CompareImplicitConversionSequences()
4070 // from any other user-defined conversion sequence. in CompareImplicitConversionSequences()
4072 // String literal to 'char *' conversion has been deprecated in C++03. It has in CompareImplicitConversionSequences()
4073 // been removed from C++11. We still accept this conversion, if it happens at in CompareImplicitConversionSequences()
4074 // the best viable function. Otherwise, this conversion is considered worse in CompareImplicitConversionSequences()
4075 // than ellipsis conversion. Consider this as an extension; this is not in the in CompareImplicitConversionSequences()
4084 // conversion is better than string-literal to char* conversion (since there in CompareImplicitConversionSequences()
4085 // is no such conversion in C++11). If there was no #1 at all or #1 couldn't in CompareImplicitConversionSequences()
4087 // If the best viable function has this conversion, a warning will be issued in CompareImplicitConversionSequences()
4093 // Ill-formedness must not differ in CompareImplicitConversionSequences()
4104 // The following checks require both conversion sequences to be of in CompareImplicitConversionSequences()
4112 // Two implicit conversion sequences of the same form are in CompareImplicitConversionSequences()
4113 // indistinguishable conversion sequences unless one of the in CompareImplicitConversionSequences()
4116 // List-initialization sequence L1 is a better conversion sequence than in CompareImplicitConversionSequences()
4117 // list-initialization sequence L2 if: in CompareImplicitConversionSequences()
4118 // - L1 converts to std::initializer_list<X> for some X and L2 does not, or, in CompareImplicitConversionSequences()
4120 // — L1 and L2 convert to arrays of the same element type, and either the in CompareImplicitConversionSequences()
4121 // number of elements n_1 initialized by L1 is less than the number of in CompareImplicitConversionSequences()
4123 // an array of unknown bound and L1 does not, in CompareImplicitConversionSequences()
4124 // even if one of the other rules in this paragraph would otherwise apply. in CompareImplicitConversionSequences()
4143 if (S.Context.hasSameUnqualifiedType(CAT1->getElementType(), in CompareImplicitConversionSequences()
4144 CAT2->getElementType())) { in CompareImplicitConversionSequences()
4145 // Both to arrays of the same element type in CompareImplicitConversionSequences()
4146 if (CAT1->getSize() != CAT2->getSize()) in CompareImplicitConversionSequences()
4148 return CAT1->getSize().ult(CAT2->getSize()) in CompareImplicitConversionSequences()
4162 // Standard conversion sequence S1 is a better conversion sequence than in CompareImplicitConversionSequences()
4163 // standard conversion sequence S2 if [...] in CompareImplicitConversionSequences()
4167 // User-defined conversion sequence U1 is a better conversion in CompareImplicitConversionSequences()
4168 // sequence than another user-defined conversion sequence U2 if in CompareImplicitConversionSequences()
4169 // they contain the same user-defined conversion function or in CompareImplicitConversionSequences()
4170 // constructor and if the second standard conversion sequence of in CompareImplicitConversionSequences()
4171 // U1 is better than the second standard conversion sequence of in CompareImplicitConversionSequences()
4187 // Per 13.3.3.2p3, compare the given standard conversion sequences to
4188 // determine if one is a proper subset of the other.
4196 // the identity conversion sequence is considered to be a subsequence of in compareStandardConversionSubsets()
4197 // any non-identity conversion sequence in compareStandardConversionSubsets()
4231 /// Determine whether one of the given reference bindings is better
4232 /// than the other based on what kind of bindings they are.
4237 // -- S1 and S2 are reference bindings (8.5.3) and neither refers to an in isBetterReferenceBindingKind()
4238 // implicit object parameter of a non-static member function declared in isBetterReferenceBindingKind()
4239 // without a ref-qualifier, and *either* S1 binds an rvalue reference in isBetterReferenceBindingKind()
4246 // time of this writing) break the standard definition of std::forward in isBetterReferenceBindingKind()
4265 /// Returns kind of fixed enum promotion the \a SCS uses.
4273 if (!FromType->isEnumeralType()) in getFixedEnumPromtion()
4276 EnumDecl *Enum = FromType->castAs<EnumType>()->getDecl(); in getFixedEnumPromtion()
4277 if (!Enum->isFixed()) in getFixedEnumPromtion()
4280 QualType UnderlyingType = Enum->getIntegerType(); in getFixedEnumPromtion()
4287 /// CompareStandardConversionSequences - Compare two standard
4288 /// conversion sequences to determine whether one is better than the
4295 // Standard conversion sequence S1 is a better conversion sequence in CompareStandardConversionSequences()
4296 // than standard conversion sequence S2 if (C++ 13.3.3.2p3): in CompareStandardConversionSequences()
4298 // -- S1 is a proper subsequence of S2 (comparing the conversion in CompareStandardConversionSequences()
4300 // excluding any Lvalue Transformation; the identity conversion in CompareStandardConversionSequences()
4301 // sequence is considered to be a subsequence of any in CompareStandardConversionSequences()
4302 // non-identity conversion sequence) or, if not that, in CompareStandardConversionSequences()
4307 // -- the rank of S1 is better than the rank of S2 (by the rules in CompareStandardConversionSequences()
4316 // (C++ 13.3.3.2p4): Two conversion sequences with the same rank in CompareStandardConversionSequences()
4317 // are indistinguishable unless one of the following rules in CompareStandardConversionSequences()
4320 // A conversion that is not a conversion of a pointer, or in CompareStandardConversionSequences()
4321 // pointer to member, to bool is better than another conversion in CompareStandardConversionSequences()
4322 // that is such a conversion. in CompareStandardConversionSequences()
4331 // A conversion that promotes an enumeration whose underlying type is fixed in CompareStandardConversionSequences()
4345 // conversion of B* to A* is better than conversion of B* to in CompareStandardConversionSequences()
4346 // void*, and conversion of A* to void* is better than conversion in CompareStandardConversionSequences()
4347 // of B* to void*. in CompareStandardConversionSequences()
4353 // Exactly one of the conversion sequences is a conversion to in CompareStandardConversionSequences()
4354 // a void pointer; it's the worse conversion. in CompareStandardConversionSequences()
4358 // Neither conversion sequence converts to a void pointer; compare in CompareStandardConversionSequences()
4359 // their derived-to-base conversions. in CompareStandardConversionSequences()
4365 // Both conversion sequences are conversions to void in CompareStandardConversionSequences()
4371 // Adjust the types we're converting from via the array-to-pointer in CompareStandardConversionSequences()
4372 // conversion, if we need to. in CompareStandardConversionSequences()
4378 QualType FromPointee1 = FromType1->getPointeeType().getUnqualifiedType(); in CompareStandardConversionSequences()
4379 QualType FromPointee2 = FromType2->getPointeeType().getUnqualifiedType(); in CompareStandardConversionSequences()
4386 // Objective-C++: If one interface is more specific than the in CompareStandardConversionSequences()
4389 = FromType1->getAs<ObjCObjectPointerType>(); in CompareStandardConversionSequences()
4391 = FromType2->getAs<ObjCObjectPointerType>(); in CompareStandardConversionSequences()
4405 // Check for a better reference binding based on the kind of bindings. in CompareStandardConversionSequences()
4420 // -- S1 and S2 are reference bindings (8.5.3), and the types to in CompareStandardConversionSequences()
4422 // top-level cv-qualifiers, and the type to which the reference in CompareStandardConversionSequences()
4423 // initialized by S2 refers is more cv-qualified than the type in CompareStandardConversionSequences()
4433 // Objective-C++ ARC: If the references refer to objects with different in CompareStandardConversionSequences()
4455 // In Microsoft mode (below 19.28), prefer an integral conversion to a in CompareStandardConversionSequences()
4456 // floating-to-integral conversion if the integral conversion in CompareStandardConversionSequences()
4457 // is between types of the same size. in CompareStandardConversionSequences()
4465 // Here, MSVC will call f(int) instead of generating a compile error in CompareStandardConversionSequences()
4475 // Prefer a compatible vector conversion over a lax vector conversion in CompareStandardConversionSequences()
4530 /// CompareQualificationConversions - Compares two standard conversion
4538 // -- S1 and S2 differ only in their qualification conversion and in CompareQualificationConversions()
4541 // [...] and the cv-qualification signature of type T1 is a proper subset in CompareQualificationConversions()
4542 // of the cv-qualification signature of type T2, and S1 is not the in CompareQualificationConversions()
4543 // deprecated string literal array-to-pointer conversion (4.2). in CompareQualificationConversions()
4545 // [...] where T1 can be converted to T2 by a qualification conversion. in CompareQualificationConversions()
4551 // conversion (!) in CompareQualificationConversions()
4556 assert(!T1->isReferenceType() && !T2->isReferenceType()); in CompareQualificationConversions()
4566 // Don't ever prefer a standard conversion sequence that uses the deprecated in CompareQualificationConversions()
4567 // string literal array to pointer conversion. in CompareQualificationConversions()
4571 // Objective-C++ ARC: in CompareQualificationConversions()
4585 // FIXME: In Objective-C ARC, we can have qualification conversions in both in CompareQualificationConversions()
4586 // directions, so we can't short-cut this second check in general. in CompareQualificationConversions()
4597 /// CompareDerivedToBaseConversions - Compares two standard conversion
4599 /// various kinds of derived-to-base conversions (C++
4600 /// [over.ics.rank]p4b3). As part of these checks, we also look at
4601 /// conversions between Objective-C interface types.
4611 // Adjust the types we're converting from via the array-to-pointer in CompareDerivedToBaseConversions()
4612 // conversion, if we need to. in CompareDerivedToBaseConversions()
4618 // Canonicalize all of the types. in CompareDerivedToBaseConversions()
4632 /*FIXME: Remove if Objective-C id conversions get their own rank*/ in CompareDerivedToBaseConversions()
4633 FromType1->isPointerType() && FromType2->isPointerType() && in CompareDerivedToBaseConversions()
4634 ToType1->isPointerType() && ToType2->isPointerType()) { in CompareDerivedToBaseConversions()
4636 FromType1->castAs<PointerType>()->getPointeeType().getUnqualifiedType(); in CompareDerivedToBaseConversions()
4638 ToType1->castAs<PointerType>()->getPointeeType().getUnqualifiedType(); in CompareDerivedToBaseConversions()
4640 FromType2->castAs<PointerType>()->getPointeeType().getUnqualifiedType(); in CompareDerivedToBaseConversions()
4642 ToType2->castAs<PointerType>()->getPointeeType().getUnqualifiedType(); in CompareDerivedToBaseConversions()
4644 // -- conversion of C* to B* is better than conversion of C* to A*, in CompareDerivedToBaseConversions()
4652 // -- conversion of B* to A* is better than conversion of C* to A*, in CompareDerivedToBaseConversions()
4662 = FromType1->getAs<ObjCObjectPointerType>(); in CompareDerivedToBaseConversions()
4664 = FromType2->getAs<ObjCObjectPointerType>(); in CompareDerivedToBaseConversions()
4666 = ToType1->getAs<ObjCObjectPointerType>(); in CompareDerivedToBaseConversions()
4668 = ToType2->getAs<ObjCObjectPointerType>(); in CompareDerivedToBaseConversions()
4671 // Apply the same conversion ranking rules for Objective-C pointer types in CompareDerivedToBaseConversions()
4673 // Objective-C pseudo-subtyping relationship used for assignment of in CompareDerivedToBaseConversions()
4674 // Objective-C pointer types. in CompareDerivedToBaseConversions()
4684 // A conversion to an a non-id object pointer type or qualified 'id' in CompareDerivedToBaseConversions()
4685 // type is better than a conversion to 'id'. in CompareDerivedToBaseConversions()
4686 if (ToPtr1->isObjCIdType() && in CompareDerivedToBaseConversions()
4687 (ToPtr2->isObjCQualifiedIdType() || ToPtr2->getInterfaceDecl())) in CompareDerivedToBaseConversions()
4689 if (ToPtr2->isObjCIdType() && in CompareDerivedToBaseConversions()
4690 (ToPtr1->isObjCQualifiedIdType() || ToPtr1->getInterfaceDecl())) in CompareDerivedToBaseConversions()
4693 // A conversion to a non-id object pointer type is better than a in CompareDerivedToBaseConversions()
4694 // conversion to a qualified 'id' type in CompareDerivedToBaseConversions()
4695 if (ToPtr1->isObjCQualifiedIdType() && ToPtr2->getInterfaceDecl()) in CompareDerivedToBaseConversions()
4697 if (ToPtr2->isObjCQualifiedIdType() && ToPtr1->getInterfaceDecl()) in CompareDerivedToBaseConversions()
4700 // A conversion to an a non-Class object pointer type or qualified 'Class' in CompareDerivedToBaseConversions()
4701 // type is better than a conversion to 'Class'. in CompareDerivedToBaseConversions()
4702 if (ToPtr1->isObjCClassType() && in CompareDerivedToBaseConversions()
4703 (ToPtr2->isObjCQualifiedClassType() || ToPtr2->getInterfaceDecl())) in CompareDerivedToBaseConversions()
4705 if (ToPtr2->isObjCClassType() && in CompareDerivedToBaseConversions()
4706 (ToPtr1->isObjCQualifiedClassType() || ToPtr1->getInterfaceDecl())) in CompareDerivedToBaseConversions()
4709 // A conversion to a non-Class object pointer type is better than a in CompareDerivedToBaseConversions()
4710 // conversion to a qualified 'Class' type. in CompareDerivedToBaseConversions()
4711 if (ToPtr1->isObjCQualifiedClassType() && ToPtr2->getInterfaceDecl()) in CompareDerivedToBaseConversions()
4713 if (ToPtr2->isObjCQualifiedClassType() && ToPtr1->getInterfaceDecl()) in CompareDerivedToBaseConversions()
4716 // -- "conversion of C* to B* is better than conversion of C* to A*," in CompareDerivedToBaseConversions()
4718 !FromPtr1->isObjCIdType() && !FromPtr1->isObjCClassType() && in CompareDerivedToBaseConversions()
4720 if (FromPtr1->isSpecialized()) { in CompareDerivedToBaseConversions()
4721 // "conversion of B<A> * to B * is better than conversion of B * to in CompareDerivedToBaseConversions()
4724 FromPtr1->getInterfaceDecl() == ToPtr1->getInterfaceDecl(); in CompareDerivedToBaseConversions()
4726 FromPtr1->getInterfaceDecl() == ToPtr2->getInterfaceDecl(); in CompareDerivedToBaseConversions()
4737 // -- "conversion of B* to A* is better than conversion of C* to A*," in CompareDerivedToBaseConversions()
4745 // Ranking of member-pointer types. in CompareDerivedToBaseConversions()
4747 FromType1->isMemberPointerType() && FromType2->isMemberPointerType() && in CompareDerivedToBaseConversions()
4748 ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) { in CompareDerivedToBaseConversions()
4749 const auto *FromMemPointer1 = FromType1->castAs<MemberPointerType>(); in CompareDerivedToBaseConversions()
4750 const auto *ToMemPointer1 = ToType1->castAs<MemberPointerType>(); in CompareDerivedToBaseConversions()
4751 const auto *FromMemPointer2 = FromType2->castAs<MemberPointerType>(); in CompareDerivedToBaseConversions()
4752 const auto *ToMemPointer2 = ToType2->castAs<MemberPointerType>(); in CompareDerivedToBaseConversions()
4753 const Type *FromPointeeType1 = FromMemPointer1->getClass(); in CompareDerivedToBaseConversions()
4754 const Type *ToPointeeType1 = ToMemPointer1->getClass(); in CompareDerivedToBaseConversions()
4755 const Type *FromPointeeType2 = FromMemPointer2->getClass(); in CompareDerivedToBaseConversions()
4756 const Type *ToPointeeType2 = ToMemPointer2->getClass(); in CompareDerivedToBaseConversions()
4761 // conversion of A::* to B::* is better than conversion of A::* to C::*, in CompareDerivedToBaseConversions()
4768 // conversion of B::* to C::* is better than conversion of A::* to C::* in CompareDerivedToBaseConversions()
4778 // -- conversion of C to B is better than conversion of C to A, in CompareDerivedToBaseConversions()
4779 // -- binding of an expression of type C to a reference of type in CompareDerivedToBaseConversions()
4780 // B& is better than binding an expression of type C to a in CompareDerivedToBaseConversions()
4781 // reference of type A&, in CompareDerivedToBaseConversions()
4790 // -- conversion of B to A is better than conversion of C to A. in CompareDerivedToBaseConversions()
4791 // -- binding of an expression of type B to a reference of type in CompareDerivedToBaseConversions()
4792 // A& is better than binding an expression of type C to a in CompareDerivedToBaseConversions()
4793 // reference of type A&, in CompareDerivedToBaseConversions()
4820 assert(!OrigT1->isReferenceType() && in CompareReferenceRelationship()
4821 "T1 must be the pointee type of the reference type"); in CompareReferenceRelationship()
4822 assert(!OrigT2->isReferenceType() && "T2 cannot be a reference type"); in CompareReferenceRelationship()
4836 // reference-related to "cv2 T2" if T1 is similar to T2, or in CompareReferenceRelationship()
4837 // T1 is a base class of T2. in CompareReferenceRelationship()
4838 // "cv1 T1" is reference-compatible with "cv2 T2" if in CompareReferenceRelationship()
4839 // a prvalue of type "pointer to cv2 T2" can be converted to the type in CompareReferenceRelationship()
4840 // "pointer to cv1 T1" via a standard conversion sequence. in CompareReferenceRelationship()
4842 // Check for standard conversions we can apply to pointers: derived-to-base in CompareReferenceRelationship()
4851 else if (UnqualT1->isObjCObjectOrInterfaceType() && in CompareReferenceRelationship()
4852 UnqualT2->isObjCObjectOrInterfaceType() && in CompareReferenceRelationship()
4855 else if (UnqualT2->isFunctionType() && in CompareReferenceRelationship()
4863 // We can have a qualification conversion. Compute whether the types are in CompareReferenceRelationship()
4871 // We will need a qualification conversion. in CompareReferenceRelationship()
4874 // Track whether we performed a qualification conversion anywhere other in CompareReferenceRelationship()
4884 // If we find a qualifier mismatch, the types are not reference-compatible, in CompareReferenceRelationship()
4885 // but are still be reference-related if they're similar. in CompareReferenceRelationship()
4901 // At this point, if the types are reference-related, we must either have the in CompareReferenceRelationship()
4909 /// Look for a user-defined conversion to a value reference-compatible
4916 assert(T2->isRecordType() && "Can only find conversions of record types."); in FindConversionForRefInit()
4917 auto *T2RecordDecl = cast<CXXRecordDecl>(T2->castAs<RecordType>()->getDecl()); in FindConversionForRefInit()
4921 const auto &Conversions = T2RecordDecl->getVisibleConversionFunctions(); in FindConversionForRefInit()
4922 for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { in FindConversionForRefInit()
4924 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(D->getDeclContext()); in FindConversionForRefInit()
4926 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in FindConversionForRefInit()
4932 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in FindConversionForRefInit()
4937 // If we are initializing an rvalue reference, don't permit conversion in FindConversionForRefInit()
4939 if (!ConvTemplate && DeclType->isRValueReferenceType()) { in FindConversionForRefInit()
4941 = Conv->getConversionType()->getAs<LValueReferenceType>(); in FindConversionForRefInit()
4942 if (RefType && !RefType->getPointeeType()->isFunctionType()) in FindConversionForRefInit()
4949 Conv->getConversionType() in FindConversionForRefInit()
4956 // If the conversion function doesn't return a reference type, in FindConversionForRefInit()
4957 // it can't be considered for this conversion. An rvalue reference in FindConversionForRefInit()
4961 Conv->getConversionType()->getAs<ReferenceType>(); in FindConversionForRefInit()
4963 (!RefType->isLValueReferenceType() && in FindConversionForRefInit()
4964 !RefType->getPointeeType()->isFunctionType())) in FindConversionForRefInit()
4985 // [...] If the parameter binds directly to the result of in FindConversionForRefInit()
4986 // applying a conversion function to the argument in FindConversionForRefInit()
4987 // expression, the implicit conversion sequence is a in FindConversionForRefInit()
4988 // user-defined conversion sequence (13.3.3.1.2), with the in FindConversionForRefInit()
4989 // second standard conversion sequence either an identity in FindConversionForRefInit()
4990 // conversion or, if the conversion function returns an in FindConversionForRefInit()
4991 // entity of a type that is a derived class of the parameter in FindConversionForRefInit()
4992 // type, a derived-to-base Conversion. in FindConversionForRefInit()
4993 if (!Best->FinalConversion.DirectBinding) in FindConversionForRefInit()
4997 ICS.UserDefined.Before = Best->Conversions[0].Standard; in FindConversionForRefInit()
4998 ICS.UserDefined.After = Best->FinalConversion; in FindConversionForRefInit()
5000 ICS.UserDefined.ConversionFunction = Best->Function; in FindConversionForRefInit()
5001 ICS.UserDefined.FoundConversionFunction = Best->FoundDecl; in FindConversionForRefInit()
5011 Cand != CandidateSet.end(); ++Cand) in FindConversionForRefInit()
5012 if (Cand->Best) in FindConversionForRefInit()
5013 ICS.Ambiguous.addConversion(Cand->FoundDecl, Cand->Function); in FindConversionForRefInit()
5018 // There was no suitable conversion, or we found a deleted in FindConversionForRefInit()
5019 // conversion; continue with other checks. in FindConversionForRefInit()
5026 /// Compute an implicit conversion sequence for reference
5033 assert(DeclType->isReferenceType() && "Reference init needs a reference"); in TryReferenceInit()
5035 // Most paths end in a failed conversion. in TryReferenceInit()
5039 QualType T1 = DeclType->castAs<ReferenceType>()->getPointeeType(); in TryReferenceInit()
5040 QualType T2 = Init->getType(); in TryReferenceInit()
5042 // If the initializer is the address of an overloaded function, try in TryReferenceInit()
5044 // type of the resulting function. in TryReferenceInit()
5049 T2 = Fn->getType(); in TryReferenceInit()
5052 // Compute some basic properties of the types and the initializer. in TryReferenceInit()
5053 bool isRValRef = DeclType->isRValueReferenceType(); in TryReferenceInit()
5054 Expr::Classification InitCategory = Init->Classify(S.Context); in TryReferenceInit()
5063 // FIXME: A reference binding can be a function conversion too. We should in TryReferenceInit()
5064 // consider that when ordering reference-to-function bindings. in TryReferenceInit()
5072 // a reference binding that performs a non-top-level qualification in TryReferenceInit()
5073 // conversion as a qualification conversion, not as an identity conversion. in TryReferenceInit()
5085 ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType(); in TryReferenceInit()
5096 // of type "cv2 T2" as follows: in TryReferenceInit()
5098 // -- If reference is an lvalue reference and the initializer expression in TryReferenceInit()
5100 // -- is an lvalue (but is not a bit-field), and "cv1 T1" is in TryReferenceInit()
5101 // reference-compatible with "cv2 T2," or in TryReferenceInit()
5103 // Per C++ [over.ics.ref]p4, we don't check the bit-field property here. in TryReferenceInit()
5106 // When a parameter of reference type binds directly (8.5.3) in TryReferenceInit()
5107 // to an argument expression, the implicit conversion sequence in TryReferenceInit()
5108 // is the identity conversion, unless the argument expression in TryReferenceInit()
5109 // has a type that is a derived class of the parameter type, in TryReferenceInit()
5110 // in which case the implicit conversion sequence is a in TryReferenceInit()
5111 // derived-to-base Conversion (13.3.3.1). in TryReferenceInit()
5115 // derived-to-base conversions is suppressed when we're in TryReferenceInit()
5116 // computing the implicit conversion sequence (C++ in TryReferenceInit()
5121 // -- has a class type (i.e., T2 is a class type), where T1 is in TryReferenceInit()
5122 // not reference-related to T2, and can be implicitly in TryReferenceInit()
5123 // converted to an lvalue of type "cv3 T3," where "cv1 T1" in TryReferenceInit()
5124 // is reference-compatible with "cv3 T3" 92) (this in TryReferenceInit()
5125 // conversion is selected by enumerating the applicable in TryReferenceInit()
5126 // conversion functions (13.3.1.6) and choosing the best in TryReferenceInit()
5128 if (!SuppressUserConversions && T2->isRecordType() && in TryReferenceInit()
5138 // -- Otherwise, the reference shall be an lvalue reference to a in TryReferenceInit()
5139 // non-volatile const type (i.e., cv1 shall be const), or the reference in TryReferenceInit()
5147 // -- If the initializer expression in TryReferenceInit()
5149 // -- is an xvalue, class prvalue, array prvalue or function in TryReferenceInit()
5150 // lvalue and "cv1 T1" is reference-compatible with "cv2 T2", or in TryReferenceInit()
5154 (T2->isRecordType() || T2->isArrayType())) || in TryReferenceInit()
5155 (InitCategory.isLValue() && T2->isFunctionType()))) { in TryReferenceInit()
5159 // allow the use of rvalue references in C++98/03 for the benefit of in TryReferenceInit()
5162 !(InitCategory.isPRValue() || T2->isRecordType())); in TryReferenceInit()
5166 // -- has a class type (i.e., T2 is a class type), where T1 is not in TryReferenceInit()
5167 // reference-related to T2, and can be implicitly converted to in TryReferenceInit()
5168 // an xvalue, class prvalue, or function lvalue of type in TryReferenceInit()
5169 // "cv3 T3", where "cv1 T1" is reference-compatible with in TryReferenceInit()
5172 // then the reference is bound to the value of the initializer in TryReferenceInit()
5173 // expression in the first case and to the result of the conversion in TryReferenceInit()
5177 T2->isRecordType() && S.isCompleteType(DeclLoc, T2) && in TryReferenceInit()
5182 // and the second standard conversion sequence of the in TryReferenceInit()
5183 // user-defined conversion sequence includes an lvalue-to-rvalue in TryReferenceInit()
5184 // conversion, the program is ill-formed. in TryReferenceInit()
5192 // A temporary of function type cannot be created; don't even try. in TryReferenceInit()
5193 if (T1->isFunctionType()) in TryReferenceInit()
5196 // -- Otherwise, a temporary of type "cv1 T1" is created and in TryReferenceInit()
5198 // rules for a non-reference copy initialization (8.5). The in TryReferenceInit()
5200 // reference-related to T2, cv1 must be the same in TryReferenceInit()
5201 // cv-qualification as, or greater cv-qualification than, in TryReferenceInit()
5202 // cv2; otherwise, the program is ill-formed. in TryReferenceInit()
5204 // If cv1 == cv2 or cv1 is a greater cv-qualified than cv2, then in TryReferenceInit()
5205 // we would be reference-compatible or reference-compatible with in TryReferenceInit()
5209 // Note that we only want to check address spaces and cvr-qualifiers here. in TryReferenceInit()
5224 // If at least one of the types is a class type, the types are not in TryReferenceInit()
5228 // create a temporary through the use of a copy constructor. in TryReferenceInit()
5230 (T1->isRecordType() || T2->isRecordType())) in TryReferenceInit()
5233 // If T1 is reference-related to T2 and the reference is an rvalue in TryReferenceInit()
5236 Init->Classify(S.Context).isLValue()) { in TryReferenceInit()
5242 // When a parameter of reference type is not bound directly to in TryReferenceInit()
5243 // an argument expression, the conversion sequence is the one in TryReferenceInit()
5245 // underlying type of the reference according to in TryReferenceInit()
5246 // 13.3.3.1. Conceptually, this conversion sequence corresponds in TryReferenceInit()
5247 // to copy-initializing a temporary of the underlying type with in TryReferenceInit()
5248 // the argument expression. Any difference in top-level in TryReferenceInit()
5249 // cv-qualification is subsumed by the initialization itself in TryReferenceInit()
5250 // and does not constitute a conversion. in TryReferenceInit()
5258 // Of course, that's still a reference binding. in TryReferenceInit()
5268 ICS.UserDefined.ConversionFunction->getReturnType() in TryReferenceInit()
5269 ->getAs<LValueReferenceType>(); in TryReferenceInit()
5273 // standard conversion sequence cannot be formed if it requires [...] in TryReferenceInit()
5300 /// TryListConversion - Try to copy-initialize a value of type ToType from the
5320 // C++20 allows list initialization of an incomplete array type. in TryListConversion()
5321 InitTy = IAT->getElementType(); in TryListConversion()
5322 if (!S.isCompleteType(From->getBeginLoc(), InitTy)) in TryListConversion()
5326 // If the initializer list is a designated-initializer-list, a conversion in TryListConversion()
5329 // FIXME: The exception for reference initialization here is not part of the in TryListConversion()
5332 bool IsDesignatedInit = From->hasDesignatedInit(); in TryListConversion()
5333 if (!ToType->isAggregateType() && !ToType->isReferenceType() && in TryListConversion()
5339 // element of type cv U, where U is X or a class derived from X, the in TryListConversion()
5340 // implicit conversion sequence is the one required to convert the element in TryListConversion()
5345 // appropriately-typed string literal (8.5.2 [dcl.init.string]), the in TryListConversion()
5346 // implicit conversion sequence is the identity conversion. in TryListConversion()
5347 if (From->getNumInits() == 1 && !IsDesignatedInit) { in TryListConversion()
5348 if (ToType->isRecordType()) { in TryListConversion()
5349 QualType InitType = From->getInit(0)->getType(); in TryListConversion()
5351 S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType)) in TryListConversion()
5352 return TryCopyInitialization(S, From->getInit(0), ToType, in TryListConversion()
5358 if (AT && S.IsStringInit(From->getInit(0), AT)) { in TryListConversion()
5374 // If the parameter type is std::initializer_list<X> or "array of X" and in TryListConversion()
5376 // conversion sequence is the worst conversion necessary to convert an in TryListConversion()
5377 // element of the list to X. in TryListConversion()
5380 // Otherwise, if the parameter type is "array of N X", if the initializer in TryListConversion()
5382 // default-constructible, and if all the elements of the initializer list in TryListConversion()
5383 // can be implicitly converted to X, the implicit conversion sequence is in TryListConversion()
5384 // the worst conversion necessary to convert an element of the list to X. in TryListConversion()
5386 unsigned e = From->getNumInits(); in TryListConversion()
5393 InitTy = AT->getElementType(); in TryListConversion()
5395 if (CT->getSize().ult(e)) { in TryListConversion()
5402 if (CT->getSize().ugt(e)) { in TryListConversion()
5404 InitListExpr EmptyList(S.Context, From->getEndLoc(), std::nullopt, in TryListConversion()
5405 From->getEndLoc()); in TryListConversion()
5422 // Cannot convert to zero-sized. in TryListConversion()
5439 Expr *Init = From->getInit(i); in TryListConversion()
5444 // Keep the worse conversion seen so far. in TryListConversion()
5447 if (CompareImplicitConversionSequences(S, From->getBeginLoc(), ICS, in TryListConversion()
5460 // over.ics.list/6 indicates we should compare that conversion. Again CWG in TryListConversion()
5463 S, From->getEndLoc(), DfltElt, Result) == in TryListConversion()
5473 // Otherwise, if the parameter is a non-aggregate class X and overload in TryListConversion()
5475 // conversion sequence is a user-defined conversion sequence. If multiple in TryListConversion()
5477 // implicit conversion sequence is a user-defined conversion sequence. in TryListConversion()
5478 if (ToType->isRecordType() && !ToType->isAggregateType()) { in TryListConversion()
5490 // initialized from the initializer list [...] the implicit conversion in TryListConversion()
5491 // sequence is a user-defined conversion sequence. in TryListConversion()
5492 if (ToType->isAggregateType()) { in TryListConversion()
5518 if (ToType->isReferenceType()) { in TryListConversion()
5520 // mention initializer lists in any way. So we go by what list- in TryListConversion()
5523 QualType T1 = ToType->castAs<ReferenceType>()->getPointeeType(); in TryListConversion()
5525 // If the initializer list has a single element that is reference-related in TryListConversion()
5527 if (From->getNumInits() == 1 && !IsDesignatedInit) { in TryListConversion()
5528 Expr *Init = From->getInit(0); in TryListConversion()
5530 QualType T2 = Init->getType(); in TryListConversion()
5532 // If the initializer is the address of an overloaded function, try in TryListConversion()
5534 // type of the resulting function. in TryListConversion()
5539 T2 = Fn->getType(); in TryListConversion()
5542 // Compute some basic properties of the types and the initializer. in TryListConversion()
5544 S.CompareReferenceRelationship(From->getBeginLoc(), T1, T2); in TryListConversion()
5547 return TryReferenceInit(S, Init, ToType, /*FIXME*/ From->getBeginLoc(), in TryListConversion()
5561 "Sub-initialization cannot result in ellipsis conversion."); in TryListConversion()
5564 if (ToType->isRValueReferenceType() || in TryListConversion()
5569 SCS.IsLvalueReference = ToType->isLValueReferenceType(); in TryListConversion()
5583 if (!ToType->isRecordType()) { in TryListConversion()
5584 // - if the initializer list has one element that is not itself an in TryListConversion()
5585 // initializer list, the implicit conversion sequence is the one in TryListConversion()
5587 unsigned NumInits = From->getNumInits(); in TryListConversion()
5588 if (NumInits == 1 && !isa<InitListExpr>(From->getInit(0))) in TryListConversion()
5589 Result = TryCopyInitialization(S, From->getInit(0), ToType, in TryListConversion()
5593 // - if the initializer list has no elements, the implicit conversion in TryListConversion()
5594 // sequence is the identity conversion. in TryListConversion()
5606 // In all cases other than those enumerated above, no conversion is possible in TryListConversion()
5610 /// TryCopyInitialization - Try to copy-initialize a value of type
5611 /// ToType from the expression From. Return the implicit conversion
5613 /// conversion sequence (meaning that the argument cannot be passed to
5614 /// a parameter of this type). If @p SuppressUserConversions, then we
5615 /// do not permit any user-defined conversion sequences.
5626 if (ToType->isReferenceType()) in TryCopyInitialization()
5628 /*FIXME:*/ From->getBeginLoc(), in TryCopyInitialization()
5652 /// TryObjectArgumentInitialization - Try to initialize the object
5653 /// parameter of the given member function (@c Method) from the
5662 // We need to have an object of class type. in TryObjectArgumentInitialization()
5663 if (const auto *PT = FromType->getAs<PointerType>()) { in TryObjectArgumentInitialization()
5664 FromType = PT->getPointeeType(); in TryObjectArgumentInitialization()
5679 if (Method->isExplicitObjectMemberFunction()) { in TryObjectArgumentInitialization()
5681 ExplicitParameterType = Method->getFunctionObjectParameterReferenceType(); in TryObjectArgumentInitialization()
5692 assert(FromType->isRecordType()); in TryObjectArgumentInitialization()
5702 Qualifiers Quals = Method->getMethodQualifiers(); in TryObjectArgumentInitialization()
5703 if (isa<CXXDestructorDecl>(Method) || Method->isStatic()) { in TryObjectArgumentInitialization()
5710 // Set up the conversion sequence as a "bad" conversion, to allow us in TryObjectArgumentInitialization()
5715 // For non-static member functions, the type of the implicit object in TryObjectArgumentInitialization()
5718 // - "lvalue reference to cv X" for functions declared without a in TryObjectArgumentInitialization()
5719 // ref-qualifier or with the & ref-qualifier in TryObjectArgumentInitialization()
5720 // - "rvalue reference to cv X" for functions declared with the && in TryObjectArgumentInitialization()
5721 // ref-qualifier in TryObjectArgumentInitialization()
5723 // where X is the class of which the function is a member and cv is the in TryObjectArgumentInitialization()
5724 // cv-qualification on the member function declaration. in TryObjectArgumentInitialization()
5726 // However, when finding an implicit conversion sequence for the argument, we in TryObjectArgumentInitialization()
5727 // are not allowed to perform user-defined conversions in TryObjectArgumentInitialization()
5728 // (C++ [over.match.funcs]p5). We perform a simplified version of in TryObjectArgumentInitialization()
5730 // non-constant references. in TryObjectArgumentInitialization()
5755 // affects the conversion rank. in TryObjectArgumentInitialization()
5762 } else if (!Method->isExplicitObjectMemberFunction()) { in TryObjectArgumentInitialization()
5768 // Check the ref-qualifier. in TryObjectArgumentInitialization()
5769 switch (Method->getRefQualifier()) { in TryObjectArgumentInitialization()
5776 // non-const lvalue reference cannot bind to an rvalue in TryObjectArgumentInitialization()
5801 ICS.Standard.IsLvalueReference = Method->getRefQualifier() != RQ_RValue; in TryObjectArgumentInitialization()
5805 = (Method->getRefQualifier() == RQ_None); in TryObjectArgumentInitialization()
5809 /// PerformObjectArgumentInitialization - Perform initialization of
5816 QualType ImplicitParamRecordType = Method->getFunctionObjectParameterType(); in PerformImplicitObjectArgumentInitialization()
5819 if (const PointerType *PT = From->getType()->getAs<PointerType>()) { in PerformImplicitObjectArgumentInitialization()
5820 FromRecordType = PT->getPointeeType(); in PerformImplicitObjectArgumentInitialization()
5821 DestType = Method->getThisType(); in PerformImplicitObjectArgumentInitialization()
5824 FromRecordType = From->getType(); in PerformImplicitObjectArgumentInitialization()
5826 FromClassification = From->Classify(Context); in PerformImplicitObjectArgumentInitialization()
5829 if (From->isPRValue()) { in PerformImplicitObjectArgumentInitialization()
5831 Method->getRefQualifier() != in PerformImplicitObjectArgumentInitialization()
5839 *this, From->getBeginLoc(), From->getType(), FromClassification, Method, in PerformImplicitObjectArgumentInitialization()
5840 Method->getParent()); in PerformImplicitObjectArgumentInitialization()
5848 Diag(From->getBeginLoc(), diag::err_member_function_call_bad_cvr) in PerformImplicitObjectArgumentInitialization()
5849 << Method->getDeclName() << FromRecordType << (CVR - 1) in PerformImplicitObjectArgumentInitialization()
5850 << From->getSourceRange(); in PerformImplicitObjectArgumentInitialization()
5851 Diag(Method->getLocation(), diag::note_previous_decl) in PerformImplicitObjectArgumentInitialization()
5852 << Method->getDeclName(); in PerformImplicitObjectArgumentInitialization()
5861 Method->getRefQualifier() == RefQualifierKind::RQ_RValue; in PerformImplicitObjectArgumentInitialization()
5862 Diag(From->getBeginLoc(), diag::err_member_function_call_bad_ref) in PerformImplicitObjectArgumentInitialization()
5863 << Method->getDeclName() << FromClassification.isRValue() in PerformImplicitObjectArgumentInitialization()
5865 Diag(Method->getLocation(), diag::note_previous_decl) in PerformImplicitObjectArgumentInitialization()
5866 << Method->getDeclName(); in PerformImplicitObjectArgumentInitialization()
5879 return Diag(From->getBeginLoc(), diag::err_member_function_call_bad_type) in PerformImplicitObjectArgumentInitialization()
5881 << From->getSourceRange(); in PerformImplicitObjectArgumentInitialization()
5892 if (!Context.hasSameType(From->getType(), DestType)) { in PerformImplicitObjectArgumentInitialization()
5894 QualType PteeTy = DestType->getPointeeType(); in PerformImplicitObjectArgumentInitialization()
5901 From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get(); in PerformImplicitObjectArgumentInitialization()
5906 /// TryContextuallyConvertToBool - Attempt to contextually convert the
5911 // - Otherwise, if the initialization is direct-initialization, the source in TryContextuallyConvertToBool()
5913 // value of the object being initialized is false. in TryContextuallyConvertToBool()
5914 if (From->getType()->isNullPtrType()) in TryContextuallyConvertToBool()
5915 return ImplicitConversionSequence::getNullptrToBool(From->getType(), in TryContextuallyConvertToBool()
5917 From->isGLValue()); in TryContextuallyConvertToBool()
5919 // All other direct-initialization of bool is equivalent to an implicit in TryContextuallyConvertToBool()
5920 // conversion to bool in which explicit conversions are permitted. in TryContextuallyConvertToBool()
5939 return Diag(From->getBeginLoc(), diag::err_typecheck_bool_condition) in PerformContextuallyConvertToBool()
5940 << From->getType() << From->getSourceRange(); in PerformContextuallyConvertToBool()
5944 /// Check that the specified conversion is permitted in a converted constant
5945 /// expression, according to C++11 [expr.const]p3. Return true if the conversion
5950 // type, most conversion kinds are impossible. All possible First and Third in CheckConvertedConstantConversions()
5960 // Conversion from an integral or unscoped enumeration type to bool is in CheckConvertedConstantConversions()
5962 // conversion, so we allow it in a converted constant expression. in CheckConvertedConstantConversions()
5965 // a lot of popular code. We should at least add a warning for this in CheckConvertedConstantConversions()
5966 // (non-conforming) extension. in CheckConvertedConstantConversions()
5967 return SCS.getFromType()->isIntegralOrUnscopedEnumerationType() && in CheckConvertedConstantConversions()
5968 SCS.getToType(2)->isBooleanType(); in CheckConvertedConstantConversions()
5974 return SCS.getFromType()->isNullPtrType(); in CheckConvertedConstantConversions()
6003 llvm_unreachable("found a first conversion kind in Second"); in CheckConvertedConstantConversions()
6007 llvm_unreachable("found a third conversion kind in Second"); in CheckConvertedConstantConversions()
6013 llvm_unreachable("unknown conversion kind"); in CheckConvertedConstantConversions()
6016 /// BuildConvertedConstantExpression - Check that the expression From is a
6017 /// converted constant expression of type T, perform the conversion but
6031 // A converted constant expression of type T is an expression, in BuildConvertedConstantExpression()
6033 // expression is a constant expression and the implicit conversion in BuildConvertedConstantExpression()
6034 // sequence contains only [... list of conversions ...]. in BuildConvertedConstantExpression()
6049 if (T->isRecordType()) in BuildConvertedConstantExpression()
6057 return S.Diag(From->getBeginLoc(), in BuildConvertedConstantExpression()
6059 << From->getType() << From->getSourceRange() << T; in BuildConvertedConstantExpression()
6064 llvm_unreachable("bad conversion in converted constant expression"); in BuildConvertedConstantExpression()
6069 return S.Diag(From->getBeginLoc(), in BuildConvertedConstantExpression()
6071 << From->getType() << From->getSourceRange() << T; in BuildConvertedConstantExpression()
6074 if (SCS->ReferenceBinding && !SCS->DirectBinding) { in BuildConvertedConstantExpression()
6075 return S.Diag(From->getBeginLoc(), in BuildConvertedConstantExpression()
6077 << From->getType() << From->getSourceRange() << T; in BuildConvertedConstantExpression()
6080 // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely, in BuildConvertedConstantExpression()
6081 // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not in BuildConvertedConstantExpression()
6084 if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) { in BuildConvertedConstantExpression()
6085 return S.Diag(From->getBeginLoc(), in BuildConvertedConstantExpression()
6087 << From->getSourceRange(); in BuildConvertedConstantExpression()
6091 // earlier, but that's not guaranteed to work when initializing an object of in BuildConvertedConstantExpression()
6094 if (T->isRecordType()) { in BuildConvertedConstantExpression()
6108 // A full-expression is [...] a constant-expression [...] in BuildConvertedConstantExpression()
6109 Result = S.ActOnFinishFullExpr(Result.get(), From->getExprLoc(), in BuildConvertedConstantExpression()
6115 // Check for a narrowing implicit conversion. in BuildConvertedConstantExpression()
6118 switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue, in BuildConvertedConstantExpression()
6121 // Implicit conversion to a narrower type, but the expression is in BuildConvertedConstantExpression()
6122 // value-dependent so we can't tell whether it's actually narrowing. in BuildConvertedConstantExpression()
6124 // Implicit conversion to a narrower type, and the value is not a constant in BuildConvertedConstantExpression()
6131 PreNarrowingType->isIntegralOrEnumerationType() && in BuildConvertedConstantExpression()
6134 // errors by allowing the un-narrowed value through. in BuildConvertedConstantExpression()
6138 S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing) in BuildConvertedConstantExpression()
6146 S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing) in BuildConvertedConstantExpression()
6147 << CCE << /*Constant*/ 0 << From->getType() << T; in BuildConvertedConstantExpression()
6156 /// CheckConvertedConstantExpression - Check that the expression From is a
6157 /// converted constant expression of type T, perform the conversion and produce
6168 if (Result.isInvalid() || Result.get()->isValueDependent()) { in CheckConvertedConstantExpression()
6194 assert(T->isIntegralOrEnumerationType() && "unexpected converted const type"); in CheckConvertedConstantExpression()
6199 if (!R.isInvalid() && !R.get()->isValueDependent()) in CheckConvertedConstantExpression()
6216 if (CCE == Sema::CCEK_TemplateArg && T->isRecordType()) in EvaluateConvertedConstantExpression()
6223 if (!E->EvaluateAsConstantExpr(Eval, Context, Kind) || in EvaluateConvertedConstantExpression()
6237 assert(CE->getResultStorageKind() != ConstantResultStorageKind::None && in EvaluateConvertedConstantExpression()
6259 Diag(E->getBeginLoc(), diag::err_expr_not_cce) in EvaluateConvertedConstantExpression()
6260 << CCE << E->getSourceRange(); in EvaluateConvertedConstantExpression()
6267 /// dropPointerConversions - If the given standard conversion sequence
6269 /// the result type of the conversion sequence.
6279 /// TryContextuallyConvertToObjCPointer - Attempt to contextually
6280 /// convert the expression From to an Objective-C pointer type.
6283 // Do an implicit conversion to 'id'. in TryContextuallyConvertToObjCPointer()
6333 M && !M->isImplicitAccess()) in GetExplicitObjectType()
6334 Base = M->getBase(); in GetExplicitObjectType()
6336 M && !M->isImplicitAccess()) in GetExplicitObjectType()
6337 Base = M->getBase(); in GetExplicitObjectType()
6339 QualType T = Base ? Base->getType() : S.getCurrentThisType(); in GetExplicitObjectType()
6341 if (T->isPointerType()) in GetExplicitObjectType()
6342 T = T->getPointeeType(); in GetExplicitObjectType()
6349 QualType ObjType = Obj->getType(); in GetExplicitObjectExpr()
6350 if (ObjType->isPointerType()) { in GetExplicitObjectExpr()
6351 ObjType = ObjType->getPointeeType(); in GetExplicitObjectExpr()
6356 if (Obj->Classify(S.getASTContext()).isPRValue()) { in GetExplicitObjectExpr()
6359 !Fun->getParamDecl(0)->getType()->isRValueReferenceType()); in GetExplicitObjectExpr()
6368 InitializedEntity::InitializeParameter(S.Context, Fun->getParamDecl(0)), in InitializeExplicitObjectArgument()
6369 Obj->getExprLoc(), Obj); in InitializeExplicitObjectArgument()
6375 assert(Method->isExplicitObjectMemberFunction() && in PrepareExplicitObjectArgument()
6382 NewArgs.append(Args.begin(), Args.end()); in PrepareExplicitObjectArgument()
6385 Method, Object->getBeginLoc()); in PrepareExplicitObjectArgument()
6389 /// type of a permitted flavor.
6391 return AllowScopedEnumerations ? T->isIntegralOrEnumerationType() in match()
6392 : T->isIntegralOrUnscopedEnumerationType(); in match()
6403 Converter.diagnoseAmbiguous(SemaRef, Loc, T) << From->getSourceRange(); in diagnoseAmbiguousConversion()
6406 cast<CXXConversionDecl>(ViableConversions[I]->getUnderlyingDecl()); in diagnoseAmbiguousConversion()
6407 QualType ConvTy = Conv->getConversionType().getNonReferenceType(); in diagnoseAmbiguousConversion()
6420 CXXConversionDecl *Conversion = in diagnoseNoViableConversion() local
6421 cast<CXXConversionDecl>(Found->getUnderlyingDecl()); in diagnoseNoViableConversion()
6424 // conversion; use it. in diagnoseNoViableConversion()
6425 QualType ConvTy = Conversion->getConversionType().getNonReferenceType(); in diagnoseNoViableConversion()
6430 << FixItHint::CreateInsertion(From->getBeginLoc(), in diagnoseNoViableConversion()
6433 SemaRef.getLocForEndOfToken(From->getEndLoc()), ")"); in diagnoseNoViableConversion()
6434 Converter.noteExplicitConv(SemaRef, Conversion, ConvTy); in diagnoseNoViableConversion()
6437 // explicit conversion function. in diagnoseNoViableConversion()
6441 SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found); in diagnoseNoViableConversion()
6442 ExprResult Result = SemaRef.BuildCXXMemberCallExpr(From, Found, Conversion, in diagnoseNoViableConversion()
6447 // Replace the conversion with a RecoveryExpr, so we don't try to in diagnoseNoViableConversion()
6449 Result = SemaRef.CreateRecoveryExpr(From->getBeginLoc(), From->getEndLoc(), in diagnoseNoViableConversion()
6450 From, Result.get()->getType()); in diagnoseNoViableConversion()
6462 CXXConversionDecl *Conversion = in recordConversion() local
6463 cast<CXXConversionDecl>(Found->getUnderlyingDecl()); in recordConversion()
6464 SemaRef.CheckMemberOperatorAccess(From->getExprLoc(), From, nullptr, Found); in recordConversion()
6466 QualType ToType = Conversion->getConversionType().getNonReferenceType(); in recordConversion()
6472 << From->getSourceRange(); in recordConversion()
6475 ExprResult Result = SemaRef.BuildCXXMemberCallExpr(From, Found, Conversion, in recordConversion()
6479 // Record usage of conversion in an implicit cast. in recordConversion()
6480 From = ImplicitCastExpr::Create(SemaRef.Context, Result.get()->getType(), in recordConversion()
6482 nullptr, Result.get()->getValueKind(), in recordConversion()
6490 if (!Converter.match(From->getType()) && !Converter.Suppress) in finishContextualImplicitConversion()
6491 Converter.diagnoseNoMatch(SemaRef, Loc, From->getType()) in finishContextualImplicitConversion()
6492 << From->getSourceRange(); in finishContextualImplicitConversion()
6504 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); in collectViableConversionCandidates()
6506 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in collectViableConversionCandidates()
6511 Conv = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in collectViableConversionCandidates()
6530 /// This routine will attempt to convert an expression of class type to a
6532 /// must have a single non-explicit conversion function converting to a matching
6533 /// type. In C++1y, there can be multiple such conversion functions, but only
6536 /// \param Loc The source location of the construct that requires the
6537 /// conversion.
6541 /// \param Converter Used to control and diagnose the conversion process.
6547 // We can't perform any more checking for type-dependent expressions. in PerformContextualImplicitConversion()
6548 if (From->isTypeDependent()) in PerformContextualImplicitConversion()
6552 if (From->hasPlaceholderType()) { in PerformContextualImplicitConversion()
6559 // Try converting the expression to an Lvalue first, to get rid of qualifiers. in PerformContextualImplicitConversion()
6561 QualType T = Converted.isUsable() ? Converted.get()->getType() : QualType(); in PerformContextualImplicitConversion()
6568 // We can only perform contextual implicit conversions on objects of class in PerformContextualImplicitConversion()
6570 const RecordType *RecordTy = T->getAs<RecordType>(); in PerformContextualImplicitConversion()
6573 Converter.diagnoseNoMatch(*this, Loc, T) << From->getSourceRange(); in PerformContextualImplicitConversion()
6586 Converter.diagnoseIncomplete(S, Loc, T) << From->getSourceRange(); in PerformContextualImplicitConversion()
6594 // Look for a conversion to an integral or enumeration type. in PerformContextualImplicitConversion()
6599 cast<CXXRecordDecl>(RecordTy->getDecl())->getVisibleConversionFunctions(); in PerformContextualImplicitConversion()
6602 (std::distance(Conversions.begin(), Conversions.end()) > 1); in PerformContextualImplicitConversion()
6609 for (auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) { in PerformContextualImplicitConversion()
6610 NamedDecl *D = (*I)->getUnderlyingDecl(); in PerformContextualImplicitConversion()
6611 CXXConversionDecl *Conversion; in PerformContextualImplicitConversion() local
6615 Conversion = cast<CXXConversionDecl>(ConvTemplate->getTemplatedDecl()); in PerformContextualImplicitConversion()
6617 continue; // C++11 does not consider conversion operator templates(?). in PerformContextualImplicitConversion()
6619 Conversion = cast<CXXConversionDecl>(D); in PerformContextualImplicitConversion()
6622 "Conversion operator templates are considered potentially " in PerformContextualImplicitConversion()
6625 QualType CurToType = Conversion->getConversionType().getNonReferenceType(); in PerformContextualImplicitConversion()
6628 if (Conversion->isExplicit()) { in PerformContextualImplicitConversion()
6648 // ... An expression e of class type E appearing in such a context in PerformContextualImplicitConversion()
6650 // type T and is well-formed if and only if e can be implicitly in PerformContextualImplicitConversion()
6652 // for conversion functions whose return type is cv T or reference to in PerformContextualImplicitConversion()
6681 // Apply this conversion. in PerformContextualImplicitConversion()
6683 DeclAccessPair::make(Best->Function, Best->FoundDecl.getAccess()); in PerformContextualImplicitConversion()
6699 // We'll complain below about a non-integral condition type. in PerformContextualImplicitConversion()
6710 // We'll complain below about a non-integral condition type. in PerformContextualImplicitConversion()
6714 // Apply this conversion. in PerformContextualImplicitConversion()
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(); in IsAcceptableNonMemberOperatorCandidate()
6739 QualType T2 = Args.size() > 1 ? Args[1]->getType() : QualType(); in IsAcceptableNonMemberOperatorCandidate()
6741 if (T1->isDependentType() || (!T2.isNull() && T2->isDependentType())) in IsAcceptableNonMemberOperatorCandidate()
6744 if (T1->isRecordType() || (!T2.isNull() && T2->isRecordType())) in IsAcceptableNonMemberOperatorCandidate()
6747 const auto *Proto = Fn->getType()->castAs<FunctionProtoType>(); in IsAcceptableNonMemberOperatorCandidate()
6748 if (Proto->getNumParams() < 1) in IsAcceptableNonMemberOperatorCandidate()
6751 if (T1->isEnumeralType()) { in IsAcceptableNonMemberOperatorCandidate()
6752 QualType ArgType = Proto->getParamType(0).getNonReferenceType(); in IsAcceptableNonMemberOperatorCandidate()
6757 if (Proto->getNumParams() < 2) in IsAcceptableNonMemberOperatorCandidate()
6760 if (!T2.isNull() && T2->isEnumeralType()) { in IsAcceptableNonMemberOperatorCandidate()
6761 QualType ArgType = Proto->getParamType(1).getNonReferenceType(); in IsAcceptableNonMemberOperatorCandidate()
6770 if (FD->isTargetMultiVersionDefault()) in isNonViableMultiVersionOverload()
6773 if (!FD->getASTContext().getTargetInfo().getTriple().isAArch64()) in isNonViableMultiVersionOverload()
6774 return FD->isTargetMultiVersion(); in isNonViableMultiVersionOverload()
6776 if (!FD->isMultiVersion()) in isNonViableMultiVersionOverload()
6780 // or the first non-default in the absence of default version. in isNonViableMultiVersionOverload()
6784 FD->getASTContext().forEachMultiversionedFunctionVersion( in isNonViableMultiVersionOverload()
6788 else if (CurFD->isTargetMultiVersionDefault()) in isNonViableMultiVersionOverload()
6802 = dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>()); in AddOverloadCandidate()
6804 assert(!Function->getDescribedFunctionTemplate() && in AddOverloadCandidate()
6811 // "this->f") that was either written explicitly or created in AddOverloadCandidate()
6816 AddMethodCandidate(Method, FoundDecl, Method->getParent(), QualType(), in AddOverloadCandidate()
6822 // We treat a constructor like a non-member function, since its object in AddOverloadCandidate()
6833 if (Constructor && Constructor->isDefaulted() && Constructor->isDeleted() && in AddOverloadCandidate()
6834 Constructor->isMoveConstructor()) in AddOverloadCandidate()
6842 // if no operand has a class type, only those non-member functions in the in AddOverloadCandidate()
6843 // lookup set that have a first parameter of type T1 or "reference to in AddOverloadCandidate()
6844 // (possibly cv-qualified) T1", when T1 is an enumeration type, or (if there in AddOverloadCandidate()
6845 // is a right operand) a second parameter of type T2 or "reference to in AddOverloadCandidate()
6846 // (possibly cv-qualified) T2", when T2 is an enumeration type, are in AddOverloadCandidate()
6873 if (getLangOpts().CPlusPlusModules && Function->isInAnotherModuleUnit()) { in AddOverloadCandidate()
6874 /// FIXME: Currently, the semantics of linkage in clang is slightly in AddOverloadCandidate()
6876 /// have linkage. So that all entities of the same should share one in AddOverloadCandidate()
6877 /// linkage. But in clang, different entities of the same could have in AddOverloadCandidate()
6880 if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) in AddOverloadCandidate()
6881 ND = SpecInfo->getTemplate(); in AddOverloadCandidate()
6883 if (ND->getFormalLinkage() == Linkage::Internal) { in AddOverloadCandidate()
6899 // of a class object to an object of its class type. in AddOverloadCandidate()
6900 QualType ClassType = Context.getTypeDeclType(Constructor->getParent()); in AddOverloadCandidate()
6901 if (Args.size() == 1 && Constructor->isSpecializationCopyingObject() && in AddOverloadCandidate()
6902 (Context.hasSameUnqualifiedType(ClassType, Args[0]->getType()) || in AddOverloadCandidate()
6903 IsDerivedFrom(Args[0]->getBeginLoc(), Args[0]->getType(), in AddOverloadCandidate()
6912 // of type "reference to P" (including such a constructor instantiated in AddOverloadCandidate()
6913 // from a template) is excluded from the set of candidate functions when in AddOverloadCandidate()
6914 // constructing an object of type cv D if the argument list has exactly in AddOverloadCandidate()
6915 // one argument and D is reference-related to P and P is reference-related in AddOverloadCandidate()
6918 if (Shadow && Args.size() == 1 && Constructor->getNumParams() >= 1 && in AddOverloadCandidate()
6919 Constructor->getParamDecl(0)->getType()->isReferenceType()) { in AddOverloadCandidate()
6920 QualType P = Constructor->getParamDecl(0)->getType()->getPointeeType(); in AddOverloadCandidate()
6921 QualType C = Context.getRecordType(Constructor->getParent()); in AddOverloadCandidate()
6922 QualType D = Context.getRecordType(Shadow->getParent()); in AddOverloadCandidate()
6923 SourceLocation Loc = Args.front()->getExprLoc(); in AddOverloadCandidate()
6932 // Check that the constructor is capable of constructing an object in the in AddOverloadCandidate()
6935 Constructor->getMethodQualifiers().getAddressSpace(), in AddOverloadCandidate()
6942 unsigned NumParams = Proto->getNumParams(); in AddOverloadCandidate()
6948 !Proto->isVariadic() && in AddOverloadCandidate()
6957 // (8.3.6). For the purposes of overload resolution, the in AddOverloadCandidate()
6960 unsigned MinRequiredArgs = Function->getMinRequiredArguments(); in AddOverloadCandidate()
6974 // inferred for the member automatically, based on the bases and fields of in AddOverloadCandidate()
6976 if (!(Caller && Caller->isImplicit()) && in AddOverloadCandidate()
6984 if (Function->getTrailingRequiresClause()) { in AddOverloadCandidate()
6995 // Determine the implicit conversion sequences for each of the in AddOverloadCandidate()
6999 PO == OverloadCandidateParamOrder::Reversed ? 1 - ArgIdx : ArgIdx; in AddOverloadCandidate()
7001 // We already formed a conversion sequence for this parameter during in AddOverloadCandidate()
7005 // exist for each argument an implicit conversion sequence in AddOverloadCandidate()
7007 // parameter of F. in AddOverloadCandidate()
7008 QualType ParamType = Proto->getParamType(ArgIdx); in AddOverloadCandidate()
7020 // (C++ 13.3.2p2): For the purposes of overload resolution, any in AddOverloadCandidate()
7047 // to addition of c-style arguments in method. in SelectBestMethod()
7048 if (Method->param_size() > NumNamedArgs) in SelectBestMethod()
7049 NumNamedArgs = Method->param_size(); in SelectBestMethod()
7054 // We can't do any type-checking on a type-dependent argument. in SelectBestMethod()
7055 if (Args[i]->isTypeDependent()) { in SelectBestMethod()
7060 ParmVarDecl *param = Method->parameters()[i]; in SelectBestMethod()
7064 // Strip the unbridged-cast placeholder expression off unless it's in SelectBestMethod()
7066 if (argExpr->hasPlaceholderType(BuiltinType::ARCUnbridgedCast) && in SelectBestMethod()
7067 !param->hasAttr<CFConsumedAttr>()) in SelectBestMethod()
7071 if (param->getType() == Context.UnknownAnyTy) { in SelectBestMethod()
7077 = TryCopyInitialization(*this, argExpr, param->getType(), in SelectBestMethod()
7083 // This function looks for a reasonably-exact match, so we consider in SelectBestMethod()
7094 if (Match && Method->isVariadic()) { in SelectBestMethod()
7096 if (Args[i]->isTypeDependent()) { in SelectBestMethod()
7108 // Check for extra arguments to non-variadic methods. in SelectBestMethod()
7113 // one with the most general result type of 'id'. in SelectBestMethod()
7115 QualType ReturnT = Methods[b]->getReturnType(); in SelectBestMethod()
7116 if (ReturnT->isObjCIdType()) in SelectBestMethod()
7136 assert(!Method->isStatic() && "Shouldn't have `this` for static methods!"); in convertArgsForAvailabilityChecks()
7145 assert((MissingImplicitThis || MD->isStatic() || in convertArgsForAvailabilityChecks()
7147 "Expected `this` for non-ctor instance methods"); in convertArgsForAvailabilityChecks()
7154 unsigned ArgSizeNoVarargs = std::min(Function->param_size(), Args.size()); in convertArgsForAvailabilityChecks()
7160 S.Context, Function->getParamDecl(I)), in convertArgsForAvailabilityChecks()
7173 if (!Function->isVariadic() && Args.size() < Function->getNumParams()) { in convertArgsForAvailabilityChecks()
7174 for (unsigned i = Args.size(), e = Function->getNumParams(); i != e; ++i) { in convertArgsForAvailabilityChecks()
7175 ParmVarDecl *P = Function->getParamDecl(i); in convertArgsForAvailabilityChecks()
7176 if (!P->hasDefaultArg()) in convertArgsForAvailabilityChecks()
7194 auto EnableIfAttrs = Function->specific_attrs<EnableIfAttr>(); in CheckEnableIf()
7195 if (EnableIfAttrs.begin() == EnableIfAttrs.end()) in CheckEnableIf()
7200 // FIXME: We should look into making enable_if late-parsed. in CheckEnableIf()
7209 // FIXME: This doesn't consider value-dependent cases, because doing so is in CheckEnableIf()
7211 if (EIA->getCond()->isValueDependent() || in CheckEnableIf()
7212 !EIA->getCond()->EvaluateWithSubstitution( in CheckEnableIf()
7227 for (const auto *DIA : ND->specific_attrs<DiagnoseIfAttr>()) { in diagnoseDiagnoseIfAttrsWith()
7228 if (ArgDependent == DIA->getArgDependent()) in diagnoseDiagnoseIfAttrsWith()
7237 Attrs.begin(), Attrs.end(), in diagnoseDiagnoseIfAttrsWith()
7238 [](const DiagnoseIfAttr *DIA) { return DIA->isError(); }); in diagnoseDiagnoseIfAttrsWith()
7240 // Note that diagnose_if attributes are late-parsed, so they appear in the in diagnoseDiagnoseIfAttrsWith()
7246 S.Diag(Loc, diag::err_diagnose_if_succeeded) << DIA->getMessage(); in diagnoseDiagnoseIfAttrsWith()
7247 S.Diag(DIA->getLocation(), diag::note_from_diagnose_if) in diagnoseDiagnoseIfAttrsWith()
7248 << DIA->getParent() << DIA->getCond()->getSourceRange(); in diagnoseDiagnoseIfAttrsWith()
7252 for (const auto *DIA : llvm::make_range(WarningBegin, Attrs.end())) in diagnoseDiagnoseIfAttrsWith()
7254 S.Diag(Loc, diag::warn_diagnose_if_succeeded) << DIA->getMessage(); in diagnoseDiagnoseIfAttrsWith()
7255 S.Diag(DIA->getLocation(), diag::note_from_diagnose_if) in diagnoseDiagnoseIfAttrsWith()
7256 << DIA->getParent() << DIA->getCond()->getSourceRange(); in diagnoseDiagnoseIfAttrsWith()
7270 // It's sane to use the same Args for any redecl of this function, since in diagnoseArgDependentDiagnoseIfAttrs()
7271 // EvaluateWithSubstitution only cares about the position of each in diagnoseArgDependentDiagnoseIfAttrs()
7273 if (!DIA->getCond()->EvaluateWithSubstitution( in diagnoseArgDependentDiagnoseIfAttrs()
7274 Result, Context, cast<FunctionDecl>(DIA->getParent()), Args, ThisArg)) in diagnoseArgDependentDiagnoseIfAttrs()
7286 return DIA->getCond()->EvaluateAsBooleanCondition(Result, Context) && in diagnoseArgIndependentDiagnoseIfAttrs()
7298 for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) { in AddFunctionCandidates()
7299 NamedDecl *D = F.getDecl()->getUnderlyingDecl(); in AddFunctionCandidates()
7304 FunTmpl ? FunTmpl->getTemplatedDecl() : cast<FunctionDecl>(D); in AddFunctionCandidates()
7306 if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic()) { in AddFunctionCandidates()
7312 ObjectType = E->getType(); in AddFunctionCandidates()
7314 // always classify them as l-values. in AddFunctionCandidates()
7315 if (!ObjectType.isNull() && ObjectType->isPointerType()) in AddFunctionCandidates()
7318 ObjectClassification = E->Classify(Context); in AddFunctionCandidates()
7325 cast<CXXRecordDecl>(FunTmpl->getDeclContext()), in AddFunctionCandidates()
7331 cast<CXXMethodDecl>(FD)->getParent(), ObjectType, in AddFunctionCandidates()
7339 // static method as non-static. in AddFunctionCandidates()
7343 assert(cast<CXXMethodDecl>(FD)->isStatic()); in AddFunctionCandidates()
7366 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(Decl->getDeclContext()); in AddMethodCandidate()
7369 Decl = cast<UsingShadowDecl>(Decl)->getTargetDecl(); in AddMethodCandidate()
7372 assert(isa<CXXMethodDecl>(TD->getTemplatedDecl()) && in AddMethodCandidate()
7396 = dyn_cast<FunctionProtoType>(Method->getType()->getAs<FunctionType>()); in AddMethodCandidate()
7407 if (Method->isDefaulted() && Method->isDeleted() && in AddMethodCandidate()
7408 Method->isMoveAssignmentOperator()) in AddMethodCandidate()
7427 (Method->isExplicitObjectMemberFunction() && in AddMethodCandidate()
7433 Method->isImplicitObjectMemberFunction(); in AddMethodCandidate()
7436 !IgnoreExplicitObject && Method->isExplicitObjectMemberFunction() ? 1 : 0; in AddMethodCandidate()
7438 unsigned NumParams = Method->getNumParams() - ExplicitOffset + in AddMethodCandidate()
7445 !Proto->isVariadic() && in AddMethodCandidate()
7454 // (8.3.6). For the purposes of overload resolution, the in AddMethodCandidate()
7457 unsigned MinRequiredArgs = Method->getMinRequiredArguments() - in AddMethodCandidate()
7473 else if (Method->isStatic()) { in AddMethodCandidate()
7475 // When the parameter is the implicit object parameter of a static member in AddMethodCandidate()
7476 // function, the implicit conversion sequence is a standard conversion in AddMethodCandidate()
7478 // conversion sequence. in AddMethodCandidate()
7485 // Determine the implicit conversion sequence for the object in AddMethodCandidate()
7506 if (Method->getTrailingRequiresClause()) { in AddMethodCandidate()
7517 // Determine the implicit conversion sequences for each of the in AddMethodCandidate()
7523 // We already formed a conversion sequence for this parameter during in AddMethodCandidate()
7527 // exist for each argument an implicit conversion sequence in AddMethodCandidate()
7529 // parameter of F. in AddMethodCandidate()
7533 ? Method->getFunctionObjectParameterReferenceType() in AddMethodCandidate()
7534 : Proto->getParamType(ArgIdx - 1); in AddMethodCandidate()
7536 ParamType = Proto->getParamType(ArgIdx + ExplicitOffset); in AddMethodCandidate()
7550 // (C++ 13.3.2p2): For the purposes of overload resolution, any in AddMethodCandidate()
7586 // or more function templates and also to a set of overloaded non-template in AddMethodTemplateCandidate()
7588 // function template are combined with the set of non-template candidate in AddMethodTemplateCandidate()
7607 Candidate.Function = MethodTmpl->getTemplatedDecl(); in AddMethodTemplateCandidate()
7613 cast<CXXMethodDecl>(Candidate.Function)->isStatic() || in AddMethodTemplateCandidate()
7638 /// or a non-value-dependent explicit-specification that evaluates to true.
7640 return ExplicitSpecifier::getFromDecl(FTD->getTemplatedDecl()).isExplicit(); in isNonDependentlyExplicit()
7652 // If the function template has a non-dependent explicit specification, in AddTemplateOverloadCandidate()
7658 Candidate.Function = FunctionTemplate->getTemplatedDecl(); in AddTemplateOverloadCandidate()
7669 // or more function templates and also to a set of overloaded non-template in AddTemplateOverloadCandidate()
7671 // function template are combined with the set of non-template candidate in AddTemplateOverloadCandidate()
7674 FunctionTemplate->getTemplateDepth()); in AddTemplateOverloadCandidate()
7691 Candidate.Function = FunctionTemplate->getTemplatedDecl(); in AddTemplateOverloadCandidate()
7734 auto *FD = FunctionTemplate->getTemplatedDecl(); in CheckNonDependentConversions()
7746 // For a method call, check the 'this' conversion here too. DR1391 doesn't in CheckNonDependentConversions()
7749 if (HasThisConversion && !cast<CXXMethodDecl>(FD)->isStatic() && in CheckNonDependentConversions()
7752 if (!FD->hasCXXExplicitFunctionObjectParameter() || in CheckNonDependentConversions()
7753 !ParamTypes[0]->isDependentType()) { in CheckNonDependentConversions()
7757 FD->hasCXXExplicitFunctionObjectParameter() ? ParamTypes[0] in CheckNonDependentConversions()
7765 Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0; in CheckNonDependentConversions()
7767 for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size()); in CheckNonDependentConversions()
7770 if (!ParamType->isDependentType()) { in CheckNonDependentConversions()
7773 ConvIdx = Args.size() - 1 - I; in CheckNonDependentConversions()
7775 "number of args (including 'this') must be exactly 2 for " in CheckNonDependentConversions()
7799 /// Determine whether this is an allowable conversion from the result
7800 /// of an explicit conversion operator to the expected type, per C++
7803 /// \param ConvType The return type of the conversion function.
7807 /// \param AllowObjCPointerConversion Allow a conversion from one
7808 /// Objective-C pointer to another.
7810 /// \returns true if the conversion is allowable, false otherwise.
7826 // If we're not allowed to consider Objective-C pointer conversions, in isAllowableExplicitConversion()
7831 // Is this an Objective-C pointer conversion? in isAllowableExplicitConversion()
7839 CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, in AddConversionCandidate() argument
7843 assert(!Conversion->getDescribedFunctionTemplate() && in AddConversionCandidate()
7844 "Conversion function templates use AddTemplateConversionCandidate"); in AddConversionCandidate()
7845 QualType ConvType = Conversion->getConversionType().getNonReferenceType(); in AddConversionCandidate()
7846 if (!CandidateSet.isNewCandidate(Conversion)) in AddConversionCandidate()
7849 // If the conversion function has an undeduced return type, trigger its in AddConversionCandidate()
7851 if (getLangOpts().CPlusPlus14 && ConvType->isUndeducedType()) { in AddConversionCandidate()
7852 if (DeduceReturnType(Conversion, From->getExprLoc())) in AddConversionCandidate()
7854 ConvType = Conversion->getConversionType().getNonReferenceType(); in AddConversionCandidate()
7857 // If we don't allow any conversion of the result type, ignore conversion in AddConversionCandidate()
7858 // functions that don't convert to exactly (possibly cv-qualified) T. in AddConversionCandidate()
7860 !Context.hasSameUnqualifiedType(Conversion->getConversionType(), ToType)) in AddConversionCandidate()
7863 // Per C++ [over.match.conv]p1, [over.match.ref]p1, an explicit conversion in AddConversionCandidate()
7865 // can be converted to the target type with a qualification conversion. in AddConversionCandidate()
7869 if (Conversion->isExplicit() && in AddConversionCandidate()
7881 Candidate.Function = Conversion; in AddConversionCandidate()
7891 if (!AllowExplicit && Conversion->isExplicit()) { in AddConversionCandidate()
7898 // For conversion functions, the function is considered to be a member of in AddConversionCandidate()
7899 // the class of the implicit implied object argument for the purpose of in AddConversionCandidate()
7900 // defining the type of the implicit object parameter. in AddConversionCandidate()
7902 // Determine the implicit conversion sequence for the implicit in AddConversionCandidate()
7904 QualType ObjectType = From->getType(); in AddConversionCandidate()
7905 if (const auto *FromPtrType = ObjectType->getAs<PointerType>()) in AddConversionCandidate()
7906 ObjectType = FromPtrType->getPointeeType(); in AddConversionCandidate()
7908 cast<CXXRecordDecl>(ObjectType->castAs<RecordType>()->getDecl()); in AddConversionCandidate()
7912 // - the object parameter of a user-defined conversion function in AddConversionCandidate()
7913 // [...] user-defined conversion sequences are not considered. in AddConversionCandidate()
7915 *this, CandidateSet.getLocation(), From->getType(), in AddConversionCandidate()
7916 From->Classify(Context), Conversion, ConversionContext, in AddConversionCandidate()
7926 if (Conversion->getTrailingRequiresClause()) { in AddConversionCandidate()
7928 if (CheckFunctionConstraints(Conversion, Satisfaction) || in AddConversionCandidate()
7936 // We won't go through a user-defined type conversion function to convert a in AddConversionCandidate()
7937 // derived to base as such conversions are given Conversion Rank. They only in AddConversionCandidate()
7938 // go through a copy constructor. 13.3.3.1.2-p4 [over.ics.user] in AddConversionCandidate()
7940 = Context.getCanonicalType(From->getType().getUnqualifiedType()); in AddConversionCandidate()
7949 // To determine what the conversion from the result of calling the in AddConversionCandidate()
7950 // conversion function to the type we're eventually trying to in AddConversionCandidate()
7952 // conversion function and attempt copy initialization from it. This in AddConversionCandidate()
7956 // well-formed. in AddConversionCandidate()
7957 DeclRefExpr ConversionRef(Context, Conversion, false, Conversion->getType(), in AddConversionCandidate()
7958 VK_LValue, From->getBeginLoc()); in AddConversionCandidate()
7960 Context.getPointerType(Conversion->getType()), in AddConversionCandidate()
7964 QualType ConversionType = Conversion->getConversionType(); in AddConversionCandidate()
7965 if (!isCompleteType(From->getBeginLoc(), ConversionType)) { in AddConversionCandidate()
7980 Buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc()); in AddConversionCandidate()
7993 // If the user-defined conversion is specified by a specialization of a in AddConversionCandidate()
7994 // conversion function template, the second standard conversion sequence in AddConversionCandidate()
7996 if (Conversion->getPrimaryTemplate() && in AddConversionCandidate()
8005 // the second standard conversion sequence of the user-defined in AddConversionCandidate()
8006 // conversion sequence includes an lvalue-to-rvalue conversion, the in AddConversionCandidate()
8007 // program is ill-formed. in AddConversionCandidate()
8008 if (ToType->isRValueReferenceType() && in AddConversionCandidate()
8023 "Can only end up with a standard conversion sequence or failure"); in AddConversionCandidate()
8027 CheckEnableIf(Conversion, CandidateSet.getLocation(), std::nullopt)) { in AddConversionCandidate()
8034 if (isNonViableMultiVersionOverload(Conversion)) { in AddConversionCandidate()
8045 assert(isa<CXXConversionDecl>(FunctionTemplate->getTemplatedDecl()) && in AddTemplateConversionCandidate()
8046 "Only conversion function templates permitted here"); in AddTemplateConversionCandidate()
8051 // If the function template has a non-dependent explicit specification, in AddTemplateConversionCandidate()
8057 Candidate.Function = FunctionTemplate->getTemplatedDecl(); in AddTemplateConversionCandidate()
8063 QualType ObjectType = From->getType(); in AddTemplateConversionCandidate()
8064 Expr::Classification ObjectClassification = From->Classify(getASTContext()); in AddTemplateConversionCandidate()
8074 Candidate.Function = FunctionTemplate->getTemplatedDecl(); in AddTemplateConversionCandidate()
8083 // Add the conversion function template specialization produced by in AddTemplateConversionCandidate()
8091 void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion, in AddSurrogateCandidate() argument
8098 if (!CandidateSet.isNewCandidate(Conversion)) in AddSurrogateCandidate()
8108 Candidate.Surrogate = Conversion; in AddSurrogateCandidate()
8113 // Determine the implicit conversion sequence for the implicit in AddSurrogateCandidate()
8116 if (Conversion->hasCXXExplicitFunctionObjectParameter()) { in AddSurrogateCandidate()
8118 Conversion->getParamDecl(0)->getType(), in AddSurrogateCandidate()
8123 *this, CandidateSet.getLocation(), Object->getType(), in AddSurrogateCandidate()
8124 Object->Classify(Context), Conversion, ActingContext); in AddSurrogateCandidate()
8134 // The first conversion is actually a user-defined conversion whose in AddSurrogateCandidate()
8135 // first conversion is ObjectInit's standard conversion (which is in AddSurrogateCandidate()
8141 Candidate.Conversions[0].UserDefined.ConversionFunction = Conversion; in AddSurrogateCandidate()
8148 unsigned NumParams = Proto->getNumParams(); in AddSurrogateCandidate()
8153 if (Args.size() > NumParams && !Proto->isVariadic()) { in AddSurrogateCandidate()
8168 // Determine the implicit conversion sequences for each of the in AddSurrogateCandidate()
8173 // exist for each argument an implicit conversion sequence in AddSurrogateCandidate()
8175 // parameter of F. in AddSurrogateCandidate()
8176 QualType ParamType = Proto->getParamType(ArgIdx); in AddSurrogateCandidate()
8189 // (C++ 13.3.2p2): For the purposes of overload resolution, any in AddSurrogateCandidate()
8196 if (Conversion->getTrailingRequiresClause()) { in AddSurrogateCandidate()
8198 if (CheckFunctionConstraints(Conversion, Satisfaction, /*Loc*/ {}, in AddSurrogateCandidate()
8208 CheckEnableIf(Conversion, CandidateSet.getLocation(), std::nullopt)) { in AddSurrogateCandidate()
8220 for (UnresolvedSetIterator F = Fns.begin(), E = Fns.end(); F != E; ++F) { in AddNonMemberOperatorCandidates()
8221 NamedDecl *D = F.getDecl()->getUnderlyingDecl(); in AddNonMemberOperatorCandidates()
8226 FunTmpl ? FunTmpl->getTemplatedDecl() : cast<FunctionDecl>(D); in AddNonMemberOperatorCandidates()
8264 // For a unary operator @ with an operand of a type whose in AddMemberOperatorCandidates()
8265 // cv-unqualified version is T1, and for a binary operator @ with in AddMemberOperatorCandidates()
8266 // a left operand of a type whose cv-unqualified version is T1 and in AddMemberOperatorCandidates()
8267 // a right operand of a type whose cv-unqualified version is T2, in AddMemberOperatorCandidates()
8268 // three sets of candidate functions, designated member in AddMemberOperatorCandidates()
8269 // candidates, non-member candidates and built-in candidates, are in AddMemberOperatorCandidates()
8271 QualType T1 = Args[0]->getType(); in AddMemberOperatorCandidates()
8273 // -- If T1 is a complete class type or a class currently being in AddMemberOperatorCandidates()
8274 // defined, the set of member candidates is the result of the in AddMemberOperatorCandidates()
8275 // qualified lookup of T1::operator@ (13.3.1.1.1); otherwise, in AddMemberOperatorCandidates()
8276 // the set of member candidates is empty. in AddMemberOperatorCandidates()
8277 if (const RecordType *T1Rec = T1->getAs<RecordType>()) { in AddMemberOperatorCandidates()
8279 if (!isCompleteType(OpLoc, T1) && !T1Rec->isBeingDefined()) in AddMemberOperatorCandidates()
8282 if (!T1Rec->getDecl()->getDefinition()) in AddMemberOperatorCandidates()
8286 LookupQualifiedName(Operators, T1Rec->getDecl()); in AddMemberOperatorCandidates()
8290 OperEnd = Operators.end(); in AddMemberOperatorCandidates()
8292 if (Oper->getAsFunction() && in AddMemberOperatorCandidates()
8295 *this, {Args[1], Args[0]}, Oper->getAsFunction())) in AddMemberOperatorCandidates()
8297 AddMethodCandidate(Oper.getPair(), Args[0]->getType(), in AddMemberOperatorCandidates()
8298 Args[0]->Classify(Context), Args.slice(1), in AddMemberOperatorCandidates()
8318 // Determine the implicit conversion sequences for each of the in AddBuiltinCandidate()
8324 // For the built-in assignment operators, conversions of the in AddBuiltinCandidate()
8326 // -- no temporaries are introduced to hold the left operand, and in AddBuiltinCandidate()
8327 // -- no user-defined conversions are applied to the left in AddBuiltinCandidate()
8328 // operand to achieve a type match with the left-most in AddBuiltinCandidate()
8329 // parameter of a built-in candidate. in AddBuiltinCandidate()
8331 // We block these conversions by turning off user-defined in AddBuiltinCandidate()
8332 // conversions, since that is the only way that initialization of in AddBuiltinCandidate()
8333 // a reference to a non-class type can occur from something that in AddBuiltinCandidate()
8334 // is not of the same type. in AddBuiltinCandidate()
8337 "Contextual conversion to bool requires bool type"); in AddBuiltinCandidate()
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.
8445 } // end anonymous namespace
8447 /// AddPointerWithMoreQualifiedTypeVariants - Add the pointer type @p Ty to
8448 /// the set of pointer types along with any more-qualified variants of
8451 /// restrict *", and "int const volatile restrict *" to the set of
8452 /// pointer types. Returns true if the add of @p Ty itself succeeded,
8465 const PointerType *PointerTy = Ty->getAs<PointerType>(); in AddPointerWithMoreQualifiedTypeVariants()
8468 const ObjCObjectPointerType *PTy = Ty->castAs<ObjCObjectPointerType>(); in AddPointerWithMoreQualifiedTypeVariants()
8469 PointeeTy = PTy->getPointeeType(); in AddPointerWithMoreQualifiedTypeVariants()
8472 PointeeTy = PointerTy->getPointeeType(); in AddPointerWithMoreQualifiedTypeVariants()
8475 // Don't add qualified variants of arrays. For one, they're not allowed in AddPointerWithMoreQualifiedTypeVariants()
8477 // only overload situation where it matters is subscript or pointer +- int, in AddPointerWithMoreQualifiedTypeVariants()
8479 if (PointeeTy->isArrayType()) in AddPointerWithMoreQualifiedTypeVariants()
8486 // Iterate through all strict supersets of BaseCVR. in AddPointerWithMoreQualifiedTypeVariants()
8493 // the type cannot be restrict-qualified. in AddPointerWithMoreQualifiedTypeVariants()
8496 (!(PointeeTy->isAnyPointerType() || PointeeTy->isReferenceType())))) in AddPointerWithMoreQualifiedTypeVariants()
8516 /// AddMemberPointerWithMoreQualifiedTypeVariants - Add the pointer type @p Ty
8517 /// to the set of pointer types along with any more-qualified variants of
8520 /// restrict *", and "int const volatile restrict *" to the set of
8521 /// pointer types. Returns true if the add of @p Ty itself succeeded,
8532 const MemberPointerType *PointerTy = Ty->getAs<MemberPointerType>(); in AddMemberPointerWithMoreQualifiedTypeVariants()
8535 QualType PointeeTy = PointerTy->getPointeeType(); in AddMemberPointerWithMoreQualifiedTypeVariants()
8536 // Don't add qualified variants of arrays. For one, they're not allowed in AddMemberPointerWithMoreQualifiedTypeVariants()
8538 // only overload situation where it matters is subscript or pointer +- int, in AddMemberPointerWithMoreQualifiedTypeVariants()
8540 if (PointeeTy->isArrayType()) in AddMemberPointerWithMoreQualifiedTypeVariants()
8542 const Type *ClassTy = PointerTy->getClass(); in AddMemberPointerWithMoreQualifiedTypeVariants()
8544 // Iterate through all strict supersets of the pointee type's CVR in AddMemberPointerWithMoreQualifiedTypeVariants()
8558 /// AddTypesConvertedFrom - Add each of the types to which the type @p
8559 /// Ty can be implicit converted to the given set of @p Types. We're
8562 /// AllowUserConversions is true if we should look at the conversion
8563 /// functions of a class type, and AllowExplicitConversions if we
8564 /// should also include the explicit conversion functions of a class
8575 // Look through reference types; they aren't part of the type of an in AddTypesConvertedFrom()
8576 // expression for the purposes of conversions. in AddTypesConvertedFrom()
8577 if (const ReferenceType *RefTy = Ty->getAs<ReferenceType>()) in AddTypesConvertedFrom()
8578 Ty = RefTy->getPointeeType(); in AddTypesConvertedFrom()
8581 if (Ty->isArrayType()) in AddTypesConvertedFrom()
8587 // Flag if we ever add a non-record type. in AddTypesConvertedFrom()
8588 const RecordType *TyRec = Ty->getAs<RecordType>(); in AddTypesConvertedFrom()
8593 HasArithmeticOrEnumeralTypes || Ty->isArithmeticType(); in AddTypesConvertedFrom()
8595 if (Ty->isObjCIdType() || Ty->isObjCClassType()) in AddTypesConvertedFrom()
8597 else if (Ty->getAs<PointerType>() || Ty->getAs<ObjCObjectPointerType>()) { in AddTypesConvertedFrom()
8598 // Insert our type, and its more-qualified variants, into the set in AddTypesConvertedFrom()
8599 // of types. in AddTypesConvertedFrom()
8602 } else if (Ty->isMemberPointerType()) { in AddTypesConvertedFrom()
8606 } else if (Ty->isEnumeralType()) { in AddTypesConvertedFrom()
8609 } else if (Ty->isBitIntType()) { in AddTypesConvertedFrom()
8612 } else if (Ty->isVectorType()) { in AddTypesConvertedFrom()
8617 } else if (Ty->isMatrixType()) { in AddTypesConvertedFrom()
8622 } else if (Ty->isNullPtrType()) { in AddTypesConvertedFrom()
8625 // No conversion functions in incomplete types. in AddTypesConvertedFrom()
8629 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); in AddTypesConvertedFrom()
8630 for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) { in AddTypesConvertedFrom()
8632 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in AddTypesConvertedFrom()
8634 // Skip conversion function templates; they don't tell us anything in AddTypesConvertedFrom()
8640 if (AllowExplicitConversions || !Conv->isExplicit()) { in AddTypesConvertedFrom()
8641 AddTypesConvertedFrom(Conv->getConversionType(), Loc, false, false, in AddTypesConvertedFrom()
8648 /// operands of builtin operators depending on the argument.
8651 return S.Context.getAddrSpaceQualType(T, Arg->getType().getAddressSpace()); in AdjustAddressSpaceForBuiltinOperandType()
8655 /// the volatile- and non-volatile-qualified assignment operators for the
8681 /// CollectVRQualifiers - This routine returns Volatile/Restrict qualifiers,
8682 /// if any, found in visible type conversion functions found in ArgExpr's type.
8687 ArgExpr->getType()->getAs<MemberPointerType>()) in CollectVRQualifiers()
8688 TyRec = RHSMPType->getClass()->getAs<RecordType>(); in CollectVRQualifiers()
8690 TyRec = ArgExpr->getType()->getAs<RecordType>(); in CollectVRQualifiers()
8698 CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(TyRec->getDecl()); in CollectVRQualifiers()
8699 if (!ClassDecl->hasDefinition()) in CollectVRQualifiers()
8702 for (NamedDecl *D : ClassDecl->getVisibleConversionFunctions()) { in CollectVRQualifiers()
8704 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in CollectVRQualifiers()
8706 QualType CanTy = Context.getCanonicalType(Conv->getConversionType()); in CollectVRQualifiers()
8707 if (const ReferenceType *ResTypeRef = CanTy->getAs<ReferenceType>()) in CollectVRQualifiers()
8708 CanTy = ResTypeRef->getPointeeType(); in CollectVRQualifiers()
8715 if (const PointerType *ResTypePtr = CanTy->getAs<PointerType>()) in CollectVRQualifiers()
8716 CanTy = ResTypePtr->getPointeeType(); in CollectVRQualifiers()
8718 CanTy->getAs<MemberPointerType>()) in CollectVRQualifiers()
8719 CanTy = ResTypeMPtr->getPointeeType(); in CollectVRQualifiers()
8733 // LHS of compound assignment overloading.
8777 /// Helper class to manage the addition of builtin operator overload
8779 /// the process, as well as a helper method to add each group of builtin
8805 // Start of promoted types. in InitArithmeticTypes()
8815 // Start of integral types. in InitArithmeticTypes()
8823 S.Context.getAuxTargetInfo()->hasInt128Type())) in InitArithmeticTypes()
8830 S.Context.getAuxTargetInfo()->hasInt128Type())) in InitArithmeticTypes()
8838 /// of arithmetic types. in InitArithmeticTypes()
8848 // End of promoted types. in InitArithmeticTypes()
8863 // End of integral types. in InitArithmeticTypes()
8866 // We don't know for sure how many bit-precise candidates were involved, so in InitArithmeticTypes()
8869 assert(ArithmeticTypes.size() - BitIntCandidates.size() <= in InitArithmeticTypes()
8874 /// Helper method to factor out the common pattern of adding overloads
8875 /// for '++' and '--' builtin operators.
8884 // Non-volatile version. in addPlusPlusMinusMinusStyleOverloads()
8887 // Use a heuristic to reduce number of builtin candidates in the set: in addPlusPlusMinusMinusStyleOverloads()
8897 // and our candidate type is a non-restrict-qualified pointer. in addPlusPlusMinusMinusStyleOverloads()
8898 if (HasRestrict && CandidateTy->isAnyPointerType() && in addPlusPlusMinusMinusStyleOverloads()
8947 // candidate operator functions of the form
8956 // candidate operator functions of the form
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
8983 // empty, there exist candidate operator functions of the form
8986 // T*VQ& operator--(T*VQ&);
8988 // T* operator--(T*VQ&, int);
8992 if (!PtrTy->getPointeeType()->isObjectType()) in addPlusPlusMinusMinusPointerOverloads()
9005 // For every cv-qualified or cv-unqualified object type T, there
9006 // exist candidate operator functions of the form
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(); in addUnaryStarPointerOverloads()
9017 if (!PointeeTy->isObjectType() && !PointeeTy->isFunctionType()) in addUnaryStarPointerOverloads()
9020 if (const FunctionProtoType *Proto =PointeeTy->getAs<FunctionProtoType>()) in addUnaryStarPointerOverloads()
9021 if (Proto->getMethodQuals() || Proto->getRefQualifier()) in addUnaryStarPointerOverloads()
9030 // operator functions of the form
9033 // T operator-(T);
9050 // For every type T, there exist candidate operator functions of
9061 // operator functions of the form
9081 // exist candidate operator functions of the form
9086 /// Set of (canonical) types that we've already handled. in addEqualEqualOrNotEqualMemberPointerOrNullptrOverloads()
9112 // there exist candidate operator functions of the form
9123 // [...]the built-in candidates include all of the candidate operator in addGenericBinaryPointerOrEnumeralOverloads()
9125 // do not have the same parameter-type-list as any non-template non-member in addGenericBinaryPointerOrEnumeralOverloads()
9129 // aren't any built-in candidates of record type, and a user-defined operator in addGenericBinaryPointerOrEnumeralOverloads()
9130 // must have an operand of record or enumeration type. Also, the only other in addGenericBinaryPointerOrEnumeralOverloads()
9140 CEnd = CandidateSet.end(); in addGenericBinaryPointerOrEnumeralOverloads()
9142 if (!C->Viable || !C->Function || C->Function->getNumParams() != 2) in addGenericBinaryPointerOrEnumeralOverloads()
9145 if (C->Function->isFunctionTemplateSpecialization()) in addGenericBinaryPointerOrEnumeralOverloads()
9148 // We interpret "same parameter-type-list" as applying to the in addGenericBinaryPointerOrEnumeralOverloads()
9149 // "synthesized candidate, with the order of the two parameters in addGenericBinaryPointerOrEnumeralOverloads()
9151 bool Reversed = C->isReversed(); in addGenericBinaryPointerOrEnumeralOverloads()
9152 QualType FirstParamType = C->Function->getParamDecl(Reversed ? 1 : 0) in addGenericBinaryPointerOrEnumeralOverloads()
9153 ->getType() in addGenericBinaryPointerOrEnumeralOverloads()
9155 QualType SecondParamType = C->Function->getParamDecl(Reversed ? 0 : 1) in addGenericBinaryPointerOrEnumeralOverloads()
9156 ->getType() in addGenericBinaryPointerOrEnumeralOverloads()
9159 // Skip if either parameter isn't of enumeral type. in addGenericBinaryPointerOrEnumeralOverloads()
9160 if (!FirstParamType->isEnumeralType() || in addGenericBinaryPointerOrEnumeralOverloads()
9161 !SecondParamType->isEnumeralType()) in addGenericBinaryPointerOrEnumeralOverloads()
9164 // Add this operator to the set of known user-defined operators. in addGenericBinaryPointerOrEnumeralOverloads()
9172 /// Set of (canonical) types that we've already handled. in addGenericBinaryPointerOrEnumeralOverloads()
9180 if (IsSpaceship && PtrTy->isFunctionPointerType()) in addGenericBinaryPointerOrEnumeralOverloads()
9203 // For every cv-qualified or cv-unqualified object type T
9204 // there exist candidate operator functions of the form
9208 // T* operator-(T*, ptrdiff_t);
9215 // exist candidate operator functions of the form
9217 // ptrdiff_t operator-(T, T);
9219 /// Set of (canonical) types that we've already handled. in addBinaryPlusOrMinusPointerOverloads()
9228 QualType PointeeTy = PtrTy->getPointeeType(); in addBinaryPlusOrMinusPointerOverloads()
9229 if (!PointeeTy->isObjectType()) in addBinaryPlusOrMinusPointerOverloads()
9234 // operator+(T*, ptrdiff_t) or operator-(T*, ptrdiff_t) in addBinaryPlusOrMinusPointerOverloads()
9239 // ptrdiff_t operator-(T, T); in addBinaryPlusOrMinusPointerOverloads()
9252 // For every pair of promoted arithmetic types L and R, there
9253 // exist candidate operator functions of the form
9258 // LR operator-(L, R);
9266 // where LR is the result of the usual arithmetic conversions
9271 // For every pair of promoted arithmetic types L and R, there exist
9272 // candidate operator functions of the form
9276 // where LR is the result of the usual arithmetic conversions
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()); in addMatrixBinaryArithmeticOverloads()
9317 AddCandidate(cast<MatrixType>(M2)->getElementType(), M2); in addMatrixBinaryArithmeticOverloads()
9326 // of the form
9332 // For every pair of floating-point types L and R, there exists a candidate
9333 // operator function of the form
9338 // the direction of p0946r0, which allows mixed integral and unscoped-enum
9360 // For every pair of promoted integral types L and R, there
9361 // exist candidate operator functions of the form
9370 // where LR is the result of the usual arithmetic conversions
9391 // empty, there exist candidate operator functions of the form
9395 /// Set of (canonical) types that we've already handled. in addAssignmentMemberPointerOrEnumeralOverloads()
9419 // of the form
9425 // For every pair (T, VQ), where T is a cv-qualified or
9426 // cv-unqualified object type and VQ is either volatile or
9427 // empty, there exist candidate operator functions of the form
9430 // T*VQ& operator-=(T*VQ&, ptrdiff_t);
9432 /// Set of (canonical) types that we've already handled. in addAssignmentPointerOverloads()
9436 // If this is operator=, keep track of the builtin candidates we added. in addAssignmentPointerOverloads()
9439 else if (!PtrTy->getPointeeType()->isObjectType()) in addAssignmentPointerOverloads()
9442 // non-volatile version in addAssignmentPointerOverloads()
9490 // non-volatile version in addAssignmentPointerOverloads()
9529 // arithmetic type, there exist candidate operator functions of
9536 // VQ L& operator-=(VQ L&, R);
9559 // Extension: Add the binary operators =, +=, -=, *=, /= for vector types. in addAssignmentArithmeticOverloads()
9564 // Add this built-in operator as a candidate (VQ is empty). in addAssignmentArithmeticOverloads()
9569 // Add this built-in operator as a candidate (VQ is 'volatile'). in addAssignmentArithmeticOverloads()
9583 // type, there exist candidate operator functions of the form
9615 // There also exist candidate operator functions of the form
9635 // For every cv-qualified or cv-unqualified object type T there
9636 // exist candidate operator functions of the form
9640 // T* operator-(T*, ptrdiff_t); [ABOVE]
9646 QualType PointeeType = PtrTy->getPointeeType(); in addSubscriptOverloads()
9647 if (!PointeeType->isObjectType()) in addSubscriptOverloads()
9656 QualType PointeeType = PtrTy->getPointeeType(); in addSubscriptOverloads()
9657 if (!PointeeType->isObjectType()) in addSubscriptOverloads()
9667 // C1 is the same type as C2 or is a derived class of C2, T is an object
9668 // type or a function type, and CV1 and CV2 are cv-qualifier-seqs,
9669 // there exist candidate operator functions of the form
9671 // CV12 T& operator->*(CV1 C1*, CV2 T C2::*);
9673 // where CV12 is the union of CV1 and CV2.
9679 C1 = QualType(Q1.strip(C1Ty->getPointeeType()), 0); in addArrowStarOverloads()
9682 // heuristic to reduce number of builtin candidates in the set. in addArrowStarOverloads()
9691 QualType C2 = QualType(mptr->getClass(), 0); in addArrowStarOverloads()
9697 QualType T = mptr->getPointeeType(); in addArrowStarOverloads()
9715 // For every type T, where T is a pointer, pointer-to-member, or scoped
9716 // enumeration type, there exist candidate operator functions of the form
9721 /// Set of (canonical) types that we've already handled. in addConditionalOperatorOverloads()
9743 if (!EnumTy->castAs<EnumType>()->getDecl()->isScoped()) in addConditionalOperatorOverloads()
9757 } // end anonymous namespace
9763 // Find all of the types that the arguments can convert to, but only in AddBuiltinOperatorCandidates()
9764 // if the operator we're looking at has built-in operator candidates in AddBuiltinOperatorCandidates()
9765 // that make use of these types. Also record whether we encounter non-record in AddBuiltinOperatorCandidates()
9771 if (Args[ArgIdx]->getType()->isAtomicType()) in AddBuiltinOperatorCandidates()
9780 CandidateTypes[ArgIdx].AddTypesConvertedFrom(Args[ArgIdx]->getType(), in AddBuiltinOperatorCandidates()
9794 // Exit early when no non-record types have been added to the candidate set in AddBuiltinOperatorCandidates()
9795 // for any of the arguments to the operator. in AddBuiltinOperatorCandidates()
9827 // -- For the operator ',', the unary operator '&', the in AddBuiltinOperatorCandidates()
9828 // operator '->', or the operator 'co_await', the in AddBuiltinOperatorCandidates()
9829 // built-in candidates set is empty. in AddBuiltinOperatorCandidates()
9837 case OO_Minus: // '-' is either unary or binary in AddBuiltinOperatorCandidates()
9897 // -- For the operator ',', the unary operator '&', or the in AddBuiltinOperatorCandidates()
9898 // operator '->', the built-in candidates set is empty. in AddBuiltinOperatorCandidates()
9966 // redundant candidates from the set) relies on pointer-equality, in AddArgumentDependentLookupCandidates()
9969 // right set of default arguments. What default arguments are in AddArgumentDependentLookupCandidates()
9975 // Erase all of the candidates we already knew about. in AddArgumentDependentLookupCandidates()
9977 CandEnd = CandidateSet.end(); in AddArgumentDependentLookupCandidates()
9979 if (Cand->Function) { in AddArgumentDependentLookupCandidates()
9980 Fns.erase(Cand->Function); in AddArgumentDependentLookupCandidates()
9981 if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate()) in AddArgumentDependentLookupCandidates()
9985 // For each of the ADL candidates we found, add it to the overload in AddArgumentDependentLookupCandidates()
9987 for (ADLResult::iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) { in AddArgumentDependentLookupCandidates()
10013 *this, Args, FTD->getTemplatedDecl())) { in AddArgumentDependentLookupCandidates()
10028 /// Compares the enable_if attributes of two FunctionDecls, for the purposes of
10031 /// Cand1's set of enable_if attributes are said to be "better" than Cand2's iff
10033 /// Cand2's first N enable_if attributes (where N = the number of enable_if
10036 /// Note that you can have a pair of candidates such that Cand1's enable_if
10042 bool Cand1Attr = Cand1->hasAttr<EnableIfAttr>(); in compareEnableIfAttrs()
10043 bool Cand2Attr = Cand2->hasAttr<EnableIfAttr>(); in compareEnableIfAttrs()
10050 auto Cand1Attrs = Cand1->specific_attrs<EnableIfAttr>(); in compareEnableIfAttrs()
10051 auto Cand2Attrs = Cand2->specific_attrs<EnableIfAttr>(); in compareEnableIfAttrs()
10068 (*Cand1A)->getCond()->Profile(Cand1ID, S.getASTContext(), true); in compareEnableIfAttrs()
10069 (*Cand2A)->getCond()->Profile(Cand2ID, S.getASTContext(), true); in compareEnableIfAttrs()
10080 if (!Cand1.Function || !Cand1.Function->isMultiVersion() || !Cand2.Function || in isBetterMultiversionCandidate()
10081 !Cand2.Function->isMultiVersion()) in isBetterMultiversionCandidate()
10084 // If both are invalid, they are equal. If one of them is invalid, the other in isBetterMultiversionCandidate()
10086 if (Cand1.Function->isInvalidDecl()) { in isBetterMultiversionCandidate()
10087 if (Cand2.Function->isInvalidDecl()) in isBetterMultiversionCandidate()
10091 if (Cand2.Function->isInvalidDecl()) in isBetterMultiversionCandidate()
10096 bool Cand1CPUDisp = Cand1.Function->hasAttr<CPUDispatchAttr>(); in isBetterMultiversionCandidate()
10097 bool Cand2CPUDisp = Cand2.Function->hasAttr<CPUDispatchAttr>(); in isBetterMultiversionCandidate()
10098 const auto *Cand1CPUSpec = Cand1.Function->getAttr<CPUSpecificAttr>(); in isBetterMultiversionCandidate()
10099 const auto *Cand2CPUSpec = Cand2.Function->getAttr<CPUSpecificAttr>(); in isBetterMultiversionCandidate()
10110 if (Cand1CPUSpec->cpus_size() != Cand2CPUSpec->cpus_size()) in isBetterMultiversionCandidate()
10111 return Cand1CPUSpec->cpus_size() < Cand2CPUSpec->cpus_size() in isBetterMultiversionCandidate()
10117 Cand1CPUSpec->cpus_begin(), Cand1CPUSpec->cpus_end(), in isBetterMultiversionCandidate()
10118 Cand2CPUSpec->cpus_begin(), in isBetterMultiversionCandidate()
10120 return LHS->getName() == RHS->getName(); in isBetterMultiversionCandidate()
10123 assert(FirstDiff.first != Cand1CPUSpec->cpus_end() && in isBetterMultiversionCandidate()
10124 "Two different cpu-specific versions should not have the same " in isBetterMultiversionCandidate()
10126 return (*FirstDiff.first)->getName() < (*FirstDiff.second)->getName() in isBetterMultiversionCandidate()
10133 /// Compute the type of the implicit object parameter for the given function,
10143 if (M->isStatic()) in getImplicitObjectParamType()
10145 return M->getFunctionObjectParameterReferenceType(); in getImplicitObjectParamType()
10154 auto PT1 = F1->getPrimaryTemplate(); in allowAmbiguity()
10155 auto PT2 = F2->getPrimaryTemplate(); in allowAmbiguity()
10158 declaresSameEntity(PT1->getInstantiatedFromMemberTemplate(), in allowAmbiguity()
10159 PT2->getInstantiatedFromMemberTemplate())) in allowAmbiguity()
10170 assert(I < F->getNumParams()); in allowAmbiguity()
10171 return F->getParamDecl(I++)->getType(); in allowAmbiguity()
10174 unsigned F1NumParams = F1->getNumParams() + isa<CXXMethodDecl>(F1); in allowAmbiguity()
10175 unsigned F2NumParams = F2->getNumParams() + isa<CXXMethodDecl>(F2); in allowAmbiguity()
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()) in sameFunctionParameterTypeLists()
10215 // if they are member functions, both are direct members of the same class, in sameFunctionParameterTypeLists()
10217 if (Mem1->getParent() != Mem2->getParent()) in sameFunctionParameterTypeLists()
10219 // if both are non-static member functions, they have the same types for in sameFunctionParameterTypeLists()
10221 if (Mem1->isInstance() && Mem2->isInstance() && in sameFunctionParameterTypeLists()
10223 Mem1->getFunctionObjectParameterReferenceType(), in sameFunctionParameterTypeLists()
10224 Mem1->getFunctionObjectParameterReferenceType())) in sameFunctionParameterTypeLists()
10230 /// isBetterOverloadCandidate - Determines whether the first overload
10235 // Define viable functions to be better candidates than non-viable in isBetterOverloadCandidate()
10247 // be triggered if it is emitted. However a wrong-sided function is still in isBetterOverloadCandidate()
10258 // viability of a function. If two functions are both viable, other factors in isBetterOverloadCandidate()
10259 // should take precedence in preference, e.g. the standard-defined preferences in isBetterOverloadCandidate()
10260 // like argument conversion ranks or enable_if partial-ordering. The in isBetterOverloadCandidate()
10261 // preference for pass-object-size parameters is probably most similar to a in isBetterOverloadCandidate()
10262 // type-based-overloading decision and so should take priority. in isBetterOverloadCandidate()
10274 // -fgpu-exclude-wrong-side-overloads is on since this requires deferring in isBetterOverloadCandidate()
10289 // over wrong-sided candidates, overloading resolution may change, which in isBetterOverloadCandidate()
10290 // may result in non-deferrable diagnostics. As a workaround, we let in isBetterOverloadCandidate()
10291 // implicit HD candidates take equal preference as wrong-sided candidates. in isBetterOverloadCandidate()
10293 // TODO: We still need special handling of implicit HD functions since in isBetterOverloadCandidate()
10296 // of implicit HD functions. in isBetterOverloadCandidate()
10313 // -- if F is a static member function, ICS1(F) is defined such in isBetterOverloadCandidate()
10327 // The only ill-formed conversion we allow in C++ is the string literal to in isBetterOverloadCandidate()
10328 // char* conversion, which is only considered ill-formed after C++11. in isBetterOverloadCandidate()
10333 // Define functions that don't require ill-formed conversions for a given in isBetterOverloadCandidate()
10354 // conversion sequence than ICSi(F2), and then... in isBetterOverloadCandidate()
10361 // Cand1 has a better conversion sequence. in isBetterOverloadCandidate()
10369 // Work around large-scale breakage caused by considering reversed in isBetterOverloadCandidate()
10370 // forms of operator== in C++20: in isBetterOverloadCandidate()
10373 // better conversion for one argument and a worse conversion for the in isBetterOverloadCandidate()
10374 // other, the implicit conversion sequences are treated as being equally in isBetterOverloadCandidate()
10394 // -- for some argument j, ICSj(F1) is a better conversion sequence than in isBetterOverloadCandidate()
10399 // -- the context is an initialization by user-defined conversion in isBetterOverloadCandidate()
10400 // (see 8.5, 13.3.1.5) and the standard conversion sequence in isBetterOverloadCandidate()
10401 // from the return type of F1 to the destination type (i.e., in isBetterOverloadCandidate()
10402 // the type of the entity being initialized) is a better in isBetterOverloadCandidate()
10403 // conversion sequence than the standard conversion sequence in isBetterOverloadCandidate()
10404 // from the return type of F2 to the destination type. in isBetterOverloadCandidate()
10409 // First check whether we prefer one of the conversion functions over the in isBetterOverloadCandidate()
10410 // other. This only distinguishes the results in non-standard, extension in isBetterOverloadCandidate()
10411 // cases such as the conversion from a lambda closure type to a function in isBetterOverloadCandidate()
10423 // FIXME: Compare kind of reference binding if conversion functions in isBetterOverloadCandidate()
10432 // either phase of [over.match.list]), a constructor is preferred over in isBetterOverloadCandidate()
10433 // a conversion function. in isBetterOverloadCandidate()
10440 // -- F1 is a non-template function and F2 is a function template in isBetterOverloadCandidate()
10443 Cand1.Function->getPrimaryTemplate(); in isBetterOverloadCandidate()
10445 Cand2.Function->getPrimaryTemplate(); in isBetterOverloadCandidate()
10449 // -- F1 and F2 are function template specializations, and the function in isBetterOverloadCandidate()
10455 dyn_cast<CXXRecordDecl>(Cand1.FoundDecl->getDeclContext()); in isBetterOverloadCandidate()
10457 dyn_cast<CXXRecordDecl>(Cand2.FoundDecl->getDeclContext()); in isBetterOverloadCandidate()
10459 Cand1.Function->getPrimaryTemplate(), in isBetterOverloadCandidate()
10460 Cand2.Function->getPrimaryTemplate(), Loc, in isBetterOverloadCandidate()
10464 Obj1Context ? QualType(Obj1Context->getTypeForDecl(), 0) in isBetterOverloadCandidate()
10466 Obj2Context ? QualType(Obj2Context->getTypeForDecl(), 0) in isBetterOverloadCandidate()
10469 return BetterTemplate == Cand1.Function->getPrimaryTemplate(); in isBetterOverloadCandidate()
10473 // -— F1 and F2 are non-template functions with the same in isBetterOverloadCandidate()
10474 // parameter-type-lists, and F1 is more constrained than F2 [...], in isBetterOverloadCandidate()
10481 // -- F1 is a constructor for a class D, F2 is a constructor for a base in isBetterOverloadCandidate()
10482 // class B of D, and for all arguments the corresponding parameters of in isBetterOverloadCandidate()
10493 auto *Cand1Class = cast<CXXRecordDecl>(Cand1.Function->getDeclContext()); in isBetterOverloadCandidate()
10494 auto *Cand2Class = cast<CXXRecordDecl>(Cand2.Function->getDeclContext()); in isBetterOverloadCandidate()
10495 if (Cand1Class->isDerivedFrom(Cand2Class)) in isBetterOverloadCandidate()
10497 if (Cand2Class->isDerivedFrom(Cand1Class)) in isBetterOverloadCandidate()
10502 // -- F2 is a rewritten candidate (12.4.1.2) and F1 is not in isBetterOverloadCandidate()
10503 // -- F1 and F2 are rewritten candidates, and F2 is a synthesized candidate in isBetterOverloadCandidate()
10504 // with reversed order of parameters and F1 is not in isBetterOverloadCandidate()
10508 // the maximally-rewritten operator (== or <=>). in isBetterOverloadCandidate()
10512 // Check C++17 tie-breakers for deduction guides. in isBetterOverloadCandidate()
10517 // -- F1 is generated from a deduction-guide and F2 is not in isBetterOverloadCandidate()
10518 if (Guide1->isImplicit() != Guide2->isImplicit()) in isBetterOverloadCandidate()
10519 return Guide2->isImplicit(); in isBetterOverloadCandidate()
10521 // -- F1 is the copy deduction candidate(16.3.1.8) and F2 is not in isBetterOverloadCandidate()
10522 if (Guide1->getDeductionCandidateKind() == DeductionCandidate::Copy) in isBetterOverloadCandidate()
10524 if (Guide2->getDeductionCandidateKind() == DeductionCandidate::Copy) in isBetterOverloadCandidate()
10527 // --F1 is generated from a non-template constructor and F2 is generated in isBetterOverloadCandidate()
10529 const auto *Constructor1 = Guide1->getCorrespondingConstructor(); in isBetterOverloadCandidate()
10530 const auto *Constructor2 = Guide2->getCorrespondingConstructor(); in isBetterOverloadCandidate()
10532 bool isC1Templated = Constructor1->getTemplatedKind() != in isBetterOverloadCandidate()
10534 bool isC2Templated = Constructor2->getTemplatedKind() != in isBetterOverloadCandidate()
10542 // Check for enable_if value-based overload resolution. in isBetterOverloadCandidate()
10577 LangAS AS1 = CD1->getMethodQualifiers().getAddressSpace(); in isBetterOverloadCandidate()
10578 LangAS AS2 = CD2->getMethodQualifiers().getAddressSpace(); in isBetterOverloadCandidate()
10590 /// Determine whether two declarations are "equivalent" for the purposes of
10606 if (!VA->getDeclContext()->getRedeclContext()->Equals( in isEquivalentInternalLinkageDeclaration()
10607 VB->getDeclContext()->getRedeclContext()) || in isEquivalentInternalLinkageDeclaration()
10609 VA->isExternallyVisible() || VB->isExternallyVisible()) in isEquivalentInternalLinkageDeclaration()
10616 // the same. For non-constant variables, we shouldn't allow it at all. in isEquivalentInternalLinkageDeclaration()
10617 if (Context.hasSameType(VA->getType(), VB->getType())) in isEquivalentInternalLinkageDeclaration()
10626 auto *EnumA = cast<EnumDecl>(EA->getDeclContext()); in isEquivalentInternalLinkageDeclaration()
10627 auto *EnumB = cast<EnumDecl>(EB->getDeclContext()); in isEquivalentInternalLinkageDeclaration()
10628 if (EnumA->hasNameForLinkage() || EnumB->hasNameForLinkage() || in isEquivalentInternalLinkageDeclaration()
10629 !Context.hasSameType(EnumA->getIntegerType(), in isEquivalentInternalLinkageDeclaration()
10630 EnumB->getIntegerType())) in isEquivalentInternalLinkageDeclaration()
10633 return llvm::APSInt::isSameValue(EA->getInitVal(), EB->getInitVal()); in isEquivalentInternalLinkageDeclaration()
10647 Diag(D->getLocation(), diag::note_equivalent_internal_linkage_decl) in diagnoseEquivalentInternalLinkageDeclarations()
10648 << !M << (M ? M->getFullModuleName() : ""); in diagnoseEquivalentInternalLinkageDeclarations()
10652 Diag(E->getLocation(), diag::note_equivalent_internal_linkage_decl) in diagnoseEquivalentInternalLinkageDeclarations()
10653 << !M << (M ? M->getFullModuleName() : ""); in diagnoseEquivalentInternalLinkageDeclarations()
10662 ->Satisfaction.ContainsErrors; in NotValidBecauseConstraintExprHasError()
10668 /// \param Loc The location of the function name (or operator symbol) for
10674 /// \returns The result of overload resolution.
10679 std::transform(begin(), end(), std::back_inserter(Candidates), in BestViableFunction()
10682 // [CUDA] HD->H or HD->D calls are technically not allowed by CUDA but in BestViableFunction()
10685 // exclude non-viable overload candidates from consideration based in BestViableFunction()
10689 // We only need to remove wrong-sided candidates here if in BestViableFunction()
10690 // -fgpu-exclude-wrong-side-overloads is off. When in BestViableFunction()
10691 // -fgpu-exclude-wrong-side-overloads is on, all candidates are compared in BestViableFunction()
10698 return Cand->Viable && Cand->Function && in BestViableFunction()
10699 S.CUDA().IdentifyPreference(Caller, Cand->Function) == in BestViableFunction()
10705 return Cand->Viable && Cand->Function && in BestViableFunction()
10706 S.CUDA().IdentifyPreference(Caller, Cand->Function) == in BestViableFunction()
10714 Best = end(); in BestViableFunction()
10716 Cand->Best = false; in BestViableFunction()
10717 if (Cand->Viable) { in BestViableFunction()
10718 if (Best == end() || in BestViableFunction()
10721 } else if (Cand->NotValidBecauseConstraintExprHasError()) { in BestViableFunction()
10726 Best = end(); in BestViableFunction()
10732 if (Best == end()) in BestViableFunction()
10739 Best->Best = true; in BestViableFunction()
10746 if (Cand->Viable && !Cand->Best && in BestViableFunction()
10749 Cand->Best = true; in BestViableFunction()
10751 if (S.isEquivalentInternalLinkageDeclaration(Cand->Function, in BestViableFunction()
10752 Curr->Function)) in BestViableFunction()
10753 EquivalentCands.push_back(Cand->Function); in BestViableFunction()
10755 Best = end(); in BestViableFunction()
10761 if (Best == end()) in BestViableFunction()
10765 if (Best->Function && Best->Function->isDeleted()) in BestViableFunction()
10768 if (auto *M = dyn_cast_or_null<CXXMethodDecl>(Best->Function); in BestViableFunction()
10770 M->isImplicitObjectMemberFunction()) { in BestViableFunction()
10775 S.diagnoseEquivalentInternalLinkageDeclarations(Loc, Best->Function, in BestViableFunction()
10809 bool isTemplate = Fn->isTemplateDecl() || Found->isTemplateDecl(); in ClassifyOverloadCandidate()
10810 if (FunctionTemplateDecl *FunTmpl = Fn->getPrimaryTemplate()) { in ClassifyOverloadCandidate()
10813 FunTmpl->getTemplateParameters(), *Fn->getTemplateSpecializationArgs()); in ClassifyOverloadCandidate()
10823 if (Fn->isImplicit() && Fn->getOverloadedOperator() == OO_EqualEqual) in ClassifyOverloadCandidate()
10830 if (!Ctor->isImplicit()) { in ClassifyOverloadCandidate()
10837 if (Ctor->isDefaultConstructor()) in ClassifyOverloadCandidate()
10840 if (Ctor->isMoveConstructor()) in ClassifyOverloadCandidate()
10843 assert(Ctor->isCopyConstructor() && in ClassifyOverloadCandidate()
10844 "unexpected sort of implicit constructor"); in ClassifyOverloadCandidate()
10851 if (!Meth->isImplicit()) in ClassifyOverloadCandidate()
10854 if (Meth->isMoveAssignmentOperator()) in ClassifyOverloadCandidate()
10857 if (Meth->isCopyAssignmentOperator()) in ClassifyOverloadCandidate()
10860 assert(isa<CXXConversionDecl>(Meth) && "expected conversion"); in ClassifyOverloadCandidate()
10871 // FIXME: It'd be nice to only emit a note once per using-decl per overload in MaybeEmitInheritedConstructorNote()
10874 S.Diag(FoundDecl->getLocation(), in MaybeEmitInheritedConstructorNote()
10876 << Shadow->getNominatedBaseClass(); in MaybeEmitInheritedConstructorNote()
10879 } // end anonymous namespace
10883 for (auto *EnableIf : FD->specific_attrs<EnableIfAttr>()) { in isFunctionAlwaysEnabled()
10885 if (EnableIf->getCond()->isValueDependent() || in isFunctionAlwaysEnabled()
10886 !EnableIf->getCond()->EvaluateAsBooleanCondition(AlwaysTrue, Ctx)) in isFunctionAlwaysEnabled()
10894 /// Returns true if we can take the address of the function.
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(), in checkAddressOfFunctionIsAvailable()
10916 if (FD->getTrailingRequiresClause()) { in checkAddressOfFunctionIsAvailable()
10924 if (FunctionTemplateDecl *FunTmpl = FD->getPrimaryTemplate()) { in checkAddressOfFunctionIsAvailable()
10927 FunTmpl->getTemplateParameters(), in checkAddressOfFunctionIsAvailable()
10928 *FD->getTemplateSpecializationArgs()); in checkAddressOfFunctionIsAvailable()
10931 S.Diag(FD->getBeginLoc(), in checkAddressOfFunctionIsAvailable()
10943 auto I = llvm::find_if(FD->parameters(), [](const ParmVarDecl *P) { in checkAddressOfFunctionIsAvailable()
10944 return P->hasAttr<PassObjectSizeAttr>(); in checkAddressOfFunctionIsAvailable()
10946 if (I == FD->param_end()) in checkAddressOfFunctionIsAvailable()
10950 // Add one to ParamNo because it's user-facing in checkAddressOfFunctionIsAvailable()
10951 unsigned ParamNo = std::distance(FD->param_begin(), I) + 1; in checkAddressOfFunctionIsAvailable()
10953 S.Diag(FD->getLocation(), in checkAddressOfFunctionIsAvailable()
10979 // convention of the call operator, since that is guaranteed to exist.
10985 const auto *RD = cast<CXXRecordDecl>(Fn->getParent()); in shouldSkipNotingLambdaConversionDecl()
10986 if (!RD->isLambda()) in shouldSkipNotingLambdaConversionDecl()
10989 CXXMethodDecl *CallOp = RD->getLambdaCallOperator(); in shouldSkipNotingLambdaConversionDecl()
10991 CallOp->getType()->castAs<FunctionType>()->getCallConv(); in shouldSkipNotingLambdaConversionDecl()
10992 QualType ConvRTy = ConvD->getType()->castAs<FunctionType>()->getReturnType(); in shouldSkipNotingLambdaConversionDecl()
10994 ConvRTy->getPointeeType()->castAs<FunctionType>()->getCallConv(); in shouldSkipNotingLambdaConversionDecl()
10999 // Notes the location of an overload candidate.
11005 if (Fn->isMultiVersion() && Fn->hasAttr<TargetAttr>() && in NoteOverloadCandidate()
11006 !Fn->getAttr<TargetAttr>()->isDefaultVersion()) in NoteOverloadCandidate()
11008 if (Fn->isMultiVersion() && Fn->hasAttr<TargetVersionAttr>() && in NoteOverloadCandidate()
11009 !Fn->getAttr<TargetVersionAttr>()->isDefaultVersion()) in NoteOverloadCandidate()
11021 HandleFunctionTypeMismatch(PD, Fn->getType(), DestType); in NoteOverloadCandidate()
11022 Diag(Fn->getLocation(), PD); in NoteOverloadCandidate()
11037 // source-level construct. This behavior is quite confusing and we should try in MaybeDiagnoseAmbiguousConstraints()
11042 for (auto I = Cands.begin(), E = Cands.end(); I != E; ++I) { in MaybeDiagnoseAmbiguousConstraints()
11043 if (!I->Function) in MaybeDiagnoseAmbiguousConstraints()
11046 if (auto *Template = I->Function->getPrimaryTemplate()) in MaybeDiagnoseAmbiguousConstraints()
11047 Template->getAssociatedConstraints(AC); in MaybeDiagnoseAmbiguousConstraints()
11049 I->Function->getAssociatedConstraints(AC); in MaybeDiagnoseAmbiguousConstraints()
11053 FirstCand = I->Function; in MaybeDiagnoseAmbiguousConstraints()
11056 SecondCand = I->Function; in MaybeDiagnoseAmbiguousConstraints()
11059 // We have more than one pair of constrained functions - this check is in MaybeDiagnoseAmbiguousConstraints()
11075 // Notes the location of all overload candidates designated through
11079 assert(OverloadedExpr->getType() == Context.OverloadTy); in NoteAllOverloadCandidates()
11084 for (UnresolvedSetIterator I = OvlExpr->decls_begin(), in NoteAllOverloadCandidates()
11085 IEnd = OvlExpr->decls_end(); in NoteAllOverloadCandidates()
11088 dyn_cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl()) ) { in NoteAllOverloadCandidates()
11089 NoteOverloadCandidate(*I, FunTmpl->getTemplatedDecl(), CRK_None, DestType, in NoteAllOverloadCandidates()
11092 = dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl()) ) { in NoteAllOverloadCandidates()
11098 /// Diagnoses an ambiguous conversion. The partial diagnostic is the
11100 /// target types of the conversion.
11109 for (I = Ambiguous.begin(), E = Ambiguous.end(); I != E; ++I) { in DiagnoseAmbiguousConversion()
11113 S.NoteOverloadCandidate(I->first, I->second); in DiagnoseAmbiguousConversion()
11117 S.Diag(SourceLocation(), diag::note_ovl_too_many_candidates) << int(E - I); in DiagnoseAmbiguousConversion()
11122 const ImplicitConversionSequence &Conv = Cand->Conversions[I]; in DiagnoseBadConversion()
11124 assert(Cand->Function && "for now, candidate must be a function"); in DiagnoseBadConversion()
11125 FunctionDecl *Fn = Cand->Function; in DiagnoseBadConversion()
11127 // There's a conversion slot for the object argument if this is a in DiagnoseBadConversion()
11128 // non-constructor method. Note that 'I' corresponds the in DiagnoseBadConversion()
11129 // conversion-slot index. in DiagnoseBadConversion()
11135 I--; in DiagnoseBadConversion()
11140 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(), in DiagnoseBadConversion()
11148 // FIXME: In presence of parameter packs we can't determine parameter range in DiagnoseBadConversion()
11151 llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) { in DiagnoseBadConversion()
11152 return Parm->isParameterPack(); in DiagnoseBadConversion()
11155 ToParamRange = Fn->getParamDecl(I)->getSourceRange(); in DiagnoseBadConversion()
11159 Expr *E = FromExpr->IgnoreParens(); in DiagnoseBadConversion()
11161 E = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens(); in DiagnoseBadConversion()
11162 DeclarationName Name = cast<OverloadExpr>(E)->getName(); in DiagnoseBadConversion()
11164 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_overload) in DiagnoseBadConversion()
11167 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11171 // Do some hand-waving analysis to see if the non-viability is due in DiagnoseBadConversion()
11175 if (CanQual<ReferenceType> RT = CToTy->getAs<ReferenceType>()) in DiagnoseBadConversion()
11176 CToTy = RT->getPointeeType(); in DiagnoseBadConversion()
11178 // TODO: detect and diagnose the full richness of const mismatches. in DiagnoseBadConversion()
11179 if (CanQual<PointerType> FromPT = CFromTy->getAs<PointerType>()) in DiagnoseBadConversion()
11180 if (CanQual<PointerType> ToPT = CToTy->getAs<PointerType>()) { in DiagnoseBadConversion()
11181 CFromTy = FromPT->getPointeeType(); in DiagnoseBadConversion()
11182 CToTy = ToPT->getPointeeType(); in DiagnoseBadConversion()
11193 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace_this) in DiagnoseBadConversion()
11197 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace) in DiagnoseBadConversion()
11200 << ToQs.getAddressSpace() << ToTy->isReferenceType() << I + 1; in DiagnoseBadConversion()
11201 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11206 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_ownership) in DiagnoseBadConversion()
11210 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11215 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_gc) in DiagnoseBadConversion()
11219 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11227 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr_this) in DiagnoseBadConversion()
11229 << FromTy << (CVR - 1); in DiagnoseBadConversion()
11231 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_cvr) in DiagnoseBadConversion()
11233 << ToParamRange << FromTy << (CVR - 1) << I + 1; in DiagnoseBadConversion()
11235 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11241 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_value_category) in DiagnoseBadConversion()
11246 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11253 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_list_argument) in DiagnoseBadConversion()
11260 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11268 if (const PointerType *PTy = TempFromTy->getAs<PointerType>()) in DiagnoseBadConversion()
11269 TempFromTy = PTy->getPointeeType(); in DiagnoseBadConversion()
11270 if (TempFromTy->isIncompleteType()) { in DiagnoseBadConversion()
11272 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_conv_incomplete) in DiagnoseBadConversion()
11275 << (unsigned)(Cand->Fix.Kind); in DiagnoseBadConversion()
11277 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11281 // Diagnose base -> derived pointer conversions. in DiagnoseBadConversion()
11283 if (const PointerType *FromPtrTy = FromTy->getAs<PointerType>()) { in DiagnoseBadConversion()
11284 if (const PointerType *ToPtrTy = ToTy->getAs<PointerType>()) { in DiagnoseBadConversion()
11285 if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs( in DiagnoseBadConversion()
11286 FromPtrTy->getPointeeType()) && in DiagnoseBadConversion()
11287 !FromPtrTy->getPointeeType()->isIncompleteType() && in DiagnoseBadConversion()
11288 !ToPtrTy->getPointeeType()->isIncompleteType() && in DiagnoseBadConversion()
11289 S.IsDerivedFrom(SourceLocation(), ToPtrTy->getPointeeType(), in DiagnoseBadConversion()
11290 FromPtrTy->getPointeeType())) in DiagnoseBadConversion()
11294 = FromTy->getAs<ObjCObjectPointerType>()) { in DiagnoseBadConversion()
11296 = ToTy->getAs<ObjCObjectPointerType>()) in DiagnoseBadConversion()
11297 if (const ObjCInterfaceDecl *FromIface = FromPtrTy->getInterfaceDecl()) in DiagnoseBadConversion()
11298 if (const ObjCInterfaceDecl *ToIface = ToPtrTy->getInterfaceDecl()) in DiagnoseBadConversion()
11299 if (ToPtrTy->getPointeeType().isAtLeastAsQualifiedAs( in DiagnoseBadConversion()
11300 FromPtrTy->getPointeeType()) && in DiagnoseBadConversion()
11301 FromIface->isSuperClassOf(ToIface)) in DiagnoseBadConversion()
11303 } else if (const ReferenceType *ToRefTy = ToTy->getAs<ReferenceType>()) { in DiagnoseBadConversion()
11304 if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) && in DiagnoseBadConversion()
11305 !FromTy->isIncompleteType() && in DiagnoseBadConversion()
11306 !ToRefTy->getPointeeType()->isIncompleteType() && in DiagnoseBadConversion()
11307 S.IsDerivedFrom(SourceLocation(), ToRefTy->getPointeeType(), FromTy)) { in DiagnoseBadConversion()
11313 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_base_to_derived_conv) in DiagnoseBadConversion()
11315 << ToParamRange << (BaseToDerivedConversion - 1) << FromTy << ToTy in DiagnoseBadConversion()
11317 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11326 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_arc_conv) in DiagnoseBadConversion()
11330 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11336 !checkAddressOfCandidateIsAvailable(S, Cand->Function)) in DiagnoseBadConversion()
11343 << (unsigned)(Cand->Fix.Kind); in DiagnoseBadConversion()
11345 // Check that location of Fn is not in system header. in DiagnoseBadConversion()
11346 if (!S.SourceMgr.isInSystemHeader(Fn->getLocation())) { in DiagnoseBadConversion()
11347 // If we can fix the conversion, suggest the FixIts. in DiagnoseBadConversion()
11348 for (const FixItHint &HI : Cand->Fix.Hints) in DiagnoseBadConversion()
11352 S.Diag(Fn->getLocation(), FDiag); in DiagnoseBadConversion()
11354 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in DiagnoseBadConversion()
11362 FunctionDecl *Fn = Cand->Function; in CheckArityMismatch()
11363 unsigned MinParams = Fn->getMinRequiredExplicitArguments() + in CheckArityMismatch()
11364 ((IsAddressOf && !Fn->isStatic()) ? 1 : 0); in CheckArityMismatch()
11368 // right number of arguments, because only overloaded operators have in CheckArityMismatch()
11369 // the weird behavior of overloading member and non-member functions. in CheckArityMismatch()
11371 if (Fn->isInvalidDecl() && in CheckArityMismatch()
11372 Fn->getDeclName().getNameKind() == DeclarationName::CXXOperatorName) in CheckArityMismatch()
11376 assert((Cand->FailureKind == ovl_fail_too_few_arguments) || in CheckArityMismatch()
11377 (Cand->FailureKind == ovl_fail_bad_deduction && in CheckArityMismatch()
11378 Cand->DeductionFailure.getResult() == in CheckArityMismatch()
11381 assert((Cand->FailureKind == ovl_fail_too_many_arguments) || in CheckArityMismatch()
11382 (Cand->FailureKind == ovl_fail_bad_deduction && in CheckArityMismatch()
11383 Cand->DeductionFailure.getResult() == in CheckArityMismatch()
11402 const auto *FnTy = Fn->getType()->castAs<FunctionProtoType>(); in DiagnoseArityMismatch()
11403 unsigned MinParams = Fn->getMinRequiredExplicitArguments() + in DiagnoseArityMismatch()
11404 ((IsAddressOf && !Fn->isStatic()) ? 1 : 0); in DiagnoseArityMismatch()
11408 !IsAddressOf && Fn->hasCXXExplicitFunctionObjectParameter(); in DiagnoseArityMismatch()
11411 Fn->getNumNonObjectParams() + ((IsAddressOf && !Fn->isStatic()) ? 1 : 0); in DiagnoseArityMismatch()
11415 if (MinParams != ParamCount || FnTy->isVariadic() || in DiagnoseArityMismatch()
11416 FnTy->isTemplateVariadic()) in DiagnoseArityMismatch()
11434 Fn->getParamDecl(HasExplicitObjectParam ? 1 : 0)->getDeclName()) in DiagnoseArityMismatch()
11435 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity_one) in DiagnoseArityMismatch()
11438 << Fn->getParamDecl(HasExplicitObjectParam ? 1 : 0) << NumFormalArgs in DiagnoseArityMismatch()
11439 << HasExplicitObjectParam << Fn->getParametersSourceRange(); in DiagnoseArityMismatch()
11441 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity) in DiagnoseArityMismatch()
11444 << HasExplicitObjectParam << Fn->getParametersSourceRange(); in DiagnoseArityMismatch()
11452 if (!CheckArityMismatch(S, Cand, NumFormalArgs, Cand->TookAddressOfOverload)) in DiagnoseArityMismatch()
11453 DiagnoseArityMismatch(S, Cand->FoundDecl, Cand->Function, NumFormalArgs, in DiagnoseArityMismatch()
11454 Cand->TookAddressOfOverload); in DiagnoseArityMismatch()
11458 if (TemplateDecl *TD = Templated->getDescribedTemplate()) in getDescribedTemplate()
11464 /// Diagnose a failed template-argument deduction.
11487 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11489 << ParamD->getDeclName(); in DiagnoseBadDeduction()
11496 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11498 << ParamD->getDeclName() in DiagnoseBadDeduction()
11499 << (DeductionFailure.getFirstArg()->pack_size() + 1) in DiagnoseBadDeduction()
11509 QualType Param = DeductionFailure.getFirstArg()->getAsType(); in DiagnoseBadDeduction()
11512 // qualified version of ParamD, so move the qualifiers to that. in DiagnoseBadDeduction()
11515 QualType NonCanonParam = Qs.apply(S.Context, TParam->getTypeForDecl()); in DiagnoseBadDeduction()
11522 QualType Arg = DeductionFailure.getSecondArg()->getAsType(); in DiagnoseBadDeduction()
11524 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_underqualified) in DiagnoseBadDeduction()
11525 << ParamD->getDeclName() << Arg << NonCanonParam; in DiagnoseBadDeduction()
11536 // Deduction might have failed because we deduced arguments of two in DiagnoseBadDeduction()
11537 // different types for a non-type template parameter. in DiagnoseBadDeduction()
11540 DeductionFailure.getFirstArg()->getNonTypeTemplateArgumentType(); in DiagnoseBadDeduction()
11542 DeductionFailure.getSecondArg()->getNonTypeTemplateArgumentType(); in DiagnoseBadDeduction()
11544 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11546 << ParamD->getDeclName() << *DeductionFailure.getFirstArg() << T1 in DiagnoseBadDeduction()
11557 // Tweak the diagnostic if the problem is that we deduced packs of in DiagnoseBadDeduction()
11560 if (DeductionFailure.getFirstArg()->getKind() == TemplateArgument::Pack && in DiagnoseBadDeduction()
11561 DeductionFailure.getSecondArg()->getKind() == TemplateArgument::Pack && in DiagnoseBadDeduction()
11562 DeductionFailure.getFirstArg()->pack_size() != in DiagnoseBadDeduction()
11563 DeductionFailure.getSecondArg()->pack_size()) { in DiagnoseBadDeduction()
11567 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11569 << which << ParamD->getDeclName() << *DeductionFailure.getFirstArg() in DiagnoseBadDeduction()
11577 if (ParamD->getDeclName()) in DiagnoseBadDeduction()
11578 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11580 << ParamD->getDeclName(); in DiagnoseBadDeduction()
11584 index = TTP->getIndex(); in DiagnoseBadDeduction()
11587 index = NTTP->getIndex(); in DiagnoseBadDeduction()
11589 index = cast<TemplateTemplateParmDecl>(ParamD)->getIndex(); in DiagnoseBadDeduction()
11590 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11603 getDescribedTemplate(Templated)->getTemplateParameters(), *Args); in DiagnoseBadDeduction()
11606 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11611 static_cast<CNSInfo*>(DeductionFailure.Data)->Satisfaction); in DiagnoseBadDeduction()
11620 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11632 getDescribedTemplate(Templated)->getTemplateParameters(), *Args); in DiagnoseBadDeduction()
11639 if (PDiag && PDiag->second.getDiagID() == in DiagnoseBadDeduction()
11641 // FIXME: Use the source range of the condition, and the fully-qualified in DiagnoseBadDeduction()
11642 // name of the enable_if template. These are both present in PDiag. in DiagnoseBadDeduction()
11643 S.Diag(PDiag->first, diag::note_ovl_candidate_disabled_by_enable_if) in DiagnoseBadDeduction()
11649 if (PDiag && PDiag->second.getDiagID() == in DiagnoseBadDeduction()
11651 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11653 << PDiag->second.getStringArg(0) << TemplateArgString; in DiagnoseBadDeduction()
11664 R = SourceRange(PDiag->first, PDiag->first); in DiagnoseBadDeduction()
11665 PDiag->second.EmitToString(S.getDiagnostics(), SFINAEArgString); in DiagnoseBadDeduction()
11668 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11683 getDescribedTemplate(Templated)->getTemplateParameters(), *Args); in DiagnoseBadDeduction()
11688 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_deduced_mismatch) in DiagnoseBadDeduction()
11707 if (FirstTN.getAsTemplateDecl()->getName() == in DiagnoseBadDeduction()
11708 SecondTN.getAsTemplateDecl()->getName()) { in DiagnoseBadDeduction()
11715 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11730 // (or instead of?) the canonical template type parameters. in DiagnoseBadDeduction()
11731 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11739 S.Diag(Templated->getLocation(), diag::note_ovl_candidate_bad_deduction); in DiagnoseBadDeduction()
11743 S.Diag(Templated->getLocation(), in DiagnoseBadDeduction()
11749 /// Diagnose a failed template-argument deduction, for function calls.
11753 TemplateDeductionResult TDK = Cand->DeductionFailure.getResult(); in DiagnoseBadDeduction()
11759 DiagnoseBadDeduction(S, Cand->FoundDecl, Cand->Function, // pattern in DiagnoseBadDeduction()
11760 Cand->DeductionFailure, NumArgs, TakingCandidateAddress); in DiagnoseBadDeduction()
11766 FunctionDecl *Callee = Cand->Function; in DiagnoseBadTarget()
11773 ClassifyOverloadCandidate(S, Cand->FoundDecl, Callee, in DiagnoseBadTarget()
11774 Cand->getRewriteKind(), FnDesc); in DiagnoseBadTarget()
11776 S.Diag(Callee->getLocation(), diag::note_ovl_candidate_bad_target) in DiagnoseBadTarget()
11784 if (Meth != nullptr && Meth->isImplicit()) { in DiagnoseBadTarget()
11785 CXXRecordDecl *ParentClass = Meth->getParent(); in DiagnoseBadTarget()
11809 if (Meth->getNumParams()) { in DiagnoseBadTarget()
11811 Meth->getParamDecl(0)->getType()->getAs<ReferenceType>()) { in DiagnoseBadTarget()
11812 ConstRHS = RT->getPointeeType().isConstQualified(); in DiagnoseBadTarget()
11823 FunctionDecl *Callee = Cand->Function; in DiagnoseFailedEnableIfAttr()
11824 EnableIfAttr *Attr = static_cast<EnableIfAttr*>(Cand->DeductionFailure.Data); in DiagnoseFailedEnableIfAttr()
11826 S.Diag(Callee->getLocation(), in DiagnoseFailedEnableIfAttr()
11828 << Attr->getCond()->getSourceRange() << Attr->getMessage(); in DiagnoseFailedEnableIfAttr()
11832 ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(Cand->Function); in DiagnoseFailedExplicitSpec()
11836 switch (Cand->Function->getDeclKind()) { in DiagnoseFailedExplicitSpec()
11844 Kind = Cand->Function->isImplicit() ? 0 : 2; in DiagnoseFailedExplicitSpec()
11850 // Note the location of the first (in-class) declaration; a redeclaration in DiagnoseFailedExplicitSpec()
11851 // (particularly an out-of-class definition) will typically lack the in DiagnoseFailedExplicitSpec()
11854 FunctionDecl *First = Cand->Function->getFirstDecl(); in DiagnoseFailedExplicitSpec()
11855 if (FunctionDecl *Pattern = First->getTemplateInstantiationPattern()) in DiagnoseFailedExplicitSpec()
11856 First = Pattern->getFirstDecl(); in DiagnoseFailedExplicitSpec()
11858 S.Diag(First->getLocation(), in DiagnoseFailedExplicitSpec()
11861 << (ES.getExpr() ? ES.getExpr()->getSourceRange() : SourceRange()); in DiagnoseFailedExplicitSpec()
11869 DG->getDeclName().getCXXDeductionGuideTemplate(); in NoteImplicitDeductionGuide()
11871 // They would retain the explicit bit of the corresponding constructor. in NoteImplicitDeductionGuide()
11872 if (!(DG->isImplicit() || (OriginTemplate && OriginTemplate->isTypeAlias()))) in NoteImplicitDeductionGuide()
11876 FunctionTemplateDecl *Template = DG->getDescribedFunctionTemplate(); in NoteImplicitDeductionGuide()
11880 DG->getTemplateInstantiationPattern(/*ForDefinition=*/false); in NoteImplicitDeductionGuide()
11882 // The implicit deduction guide is built on an explicit non-template in NoteImplicitDeductionGuide()
11885 // FIXME: Add a test once https://github.com/llvm/llvm-project/pull/96686 in NoteImplicitDeductionGuide()
11887 assert(OriginTemplate->isTypeAlias() && in NoteImplicitDeductionGuide()
11888 "Non-template implicit deduction guides are only possible for " in NoteImplicitDeductionGuide()
11890 DG->print(OS); in NoteImplicitDeductionGuide()
11891 S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide) in NoteImplicitDeductionGuide()
11895 Template = Pattern->getDescribedFunctionTemplate(); in NoteImplicitDeductionGuide()
11896 assert(Template && "Cannot find the associated function template of " in NoteImplicitDeductionGuide()
11899 Template->print(OS); in NoteImplicitDeductionGuide()
11900 S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide) in NoteImplicitDeductionGuide()
11909 /// major challenges of technical writing. Yes, this makes pointing
11911 /// better than generating twenty screens of text for every failed
11914 /// It would be great to be able to express per-candidate problems
11917 /// \param CtorDestAS Addr space of object being constructed (for ctor
11923 FunctionDecl *Fn = Cand->Function; in NoteFunctionCandidate()
11930 if (S.getLangOpts().OpenCL && Fn->isImplicit() && in NoteFunctionCandidate()
11931 Cand->FailureKind != ovl_fail_bad_conversion) in NoteFunctionCandidate()
11935 // the address of a an overload set for a function pointer. in NoteFunctionCandidate()
11936 if (Cand->TookAddressOfOverload && in NoteFunctionCandidate()
11937 !Cand->Function->hasCXXExplicitFunctionObjectParameter() && in NoteFunctionCandidate()
11938 !Cand->Function->isStatic()) in NoteFunctionCandidate()
11942 if (Cand->Viable) { in NoteFunctionCandidate()
11943 if (Fn->isDeleted()) { in NoteFunctionCandidate()
11946 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, in NoteFunctionCandidate()
11947 Cand->getRewriteKind(), FnDesc); in NoteFunctionCandidate()
11949 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_deleted) in NoteFunctionCandidate()
11951 << (Fn->isDeleted() ? (Fn->isDeletedAsWritten() ? 1 : 2) : 0); in NoteFunctionCandidate()
11952 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in NoteFunctionCandidate()
11957 S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind()); in NoteFunctionCandidate()
11964 // template parameters or pointing to the header of the surrounding RecordDecl in NoteFunctionCandidate()
11967 // We prefer adding such notes at the end of the deduction failure because in NoteFunctionCandidate()
11972 switch (Cand->FailureKind) { in NoteFunctionCandidate()
11982 S.Diag(Fn->getLocation(), diag::note_ovl_candidate_illegal_constructor) in NoteFunctionCandidate()
11983 << (Fn->getPrimaryTemplate() ? 1 : 0); in NoteFunctionCandidate()
11984 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in NoteFunctionCandidate()
11991 S.Diag(Fn->getLocation(), in NoteFunctionCandidate()
11994 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in NoteFunctionCandidate()
12001 return S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind()); in NoteFunctionCandidate()
12004 unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0); in NoteFunctionCandidate()
12005 for (unsigned N = Cand->Conversions.size(); I != N; ++I) in NoteFunctionCandidate()
12006 if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad()) in NoteFunctionCandidate()
12010 // when user-conversion overload fails. Figure out how to handle in NoteFunctionCandidate()
12012 return S.NoteOverloadCandidate(Cand->FoundDecl, Fn, Cand->getRewriteKind()); in NoteFunctionCandidate()
12026 if (cast<CXXConstructorDecl>(Fn)->isCopyOrMoveConstructor()) in NoteFunctionCandidate()
12028 S.Diag(Fn->getLocation(), in NoteFunctionCandidate()
12030 << (Fn->getPrimaryTemplate() ? 1 : 0) in NoteFunctionCandidate()
12031 << Fn->getParamDecl(0)->getType()->isRValueReferenceType(); in NoteFunctionCandidate()
12032 MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl); in NoteFunctionCandidate()
12036 bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function); in NoteFunctionCandidate()
12048 ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, in NoteFunctionCandidate()
12049 Cand->getRewriteKind(), FnDesc); in NoteFunctionCandidate()
12051 S.Diag(Fn->getLocation(), in NoteFunctionCandidate()
12064 if (shouldSkipNotingLambdaConversionDecl(Cand->Surrogate)) in NoteSurrogateCandidate()
12067 // Desugar the type of the surrogate down to a function type, in NoteSurrogateCandidate()
12070 QualType FnType = Cand->Surrogate->getConversionType(); in NoteSurrogateCandidate()
12075 FnType->getAs<LValueReferenceType>()) { in NoteSurrogateCandidate()
12076 FnType = FnTypeRef->getPointeeType(); in NoteSurrogateCandidate()
12079 FnType->getAs<RValueReferenceType>()) { in NoteSurrogateCandidate()
12080 FnType = FnTypeRef->getPointeeType(); in NoteSurrogateCandidate()
12083 if (const PointerType *FnTypePtr = FnType->getAs<PointerType>()) { in NoteSurrogateCandidate()
12084 FnType = FnTypePtr->getPointeeType(); in NoteSurrogateCandidate()
12088 FnType = QualType(FnType->getAs<FunctionType>(), 0); in NoteSurrogateCandidate()
12094 if (!Cand->Viable && in NoteSurrogateCandidate()
12095 Cand->FailureKind == ovl_fail_constraints_not_satisfied) { in NoteSurrogateCandidate()
12096 S.Diag(Cand->Surrogate->getLocation(), in NoteSurrogateCandidate()
12098 << Cand->Surrogate; in NoteSurrogateCandidate()
12100 if (S.CheckFunctionConstraints(Cand->Surrogate, Satisfaction)) in NoteSurrogateCandidate()
12103 S.Diag(Cand->Surrogate->getLocation(), diag::note_ovl_surrogate_cand) in NoteSurrogateCandidate()
12111 assert(Cand->Conversions.size() <= 2 && "builtin operator is not binary"); in NoteBuiltinOperatorCandidate()
12115 TypeStr += Cand->BuiltinParamTypes[0].getAsString(); in NoteBuiltinOperatorCandidate()
12116 if (Cand->Conversions.size() == 1) { in NoteBuiltinOperatorCandidate()
12121 TypeStr += Cand->BuiltinParamTypes[1].getAsString(); in NoteBuiltinOperatorCandidate()
12129 for (const ImplicitConversionSequence &ICS : Cand->Conversions) { in NoteAmbiguousUserConversions()
12139 if (Cand->Function) in GetLocationForCandidate()
12140 return Cand->Function->getLocation(); in GetLocationForCandidate()
12141 if (Cand->IsSurrogate) in GetLocationForCandidate()
12142 return Cand->Surrogate->getLocation(); in GetLocationForCandidate()
12151 llvm_unreachable("non-deduction failure while diagnosing bad deduction"); in RankDeductionFailure()
12198 // If there are too many or too few arguments, that's the high-order bit we in EffectiveFailureKind()
12200 if (C->FailureKind == ovl_fail_too_many_arguments || in EffectiveFailureKind()
12201 C->FailureKind == ovl_fail_too_few_arguments) in EffectiveFailureKind()
12202 return static_cast<OverloadFailureKind>(C->FailureKind); in EffectiveFailureKind()
12204 if (C->Function) { in EffectiveFailureKind()
12205 if (NumArgs > C->Function->getNumParams() && !C->Function->isVariadic()) in EffectiveFailureKind()
12207 if (NumArgs < C->Function->getMinRequiredArguments()) in EffectiveFailureKind()
12211 return static_cast<OverloadFailureKind>(C->FailureKind); in EffectiveFailureKind()
12216 // Fast-path this check. in operator ()()
12220 if (L->Viable) { in operator ()()
12221 if (!R->Viable) return true; in operator ()()
12226 } else if (R->Viable) in operator ()()
12229 assert(L->Viable == R->Viable); in operator ()()
12231 // Criteria by which we can sort non-viable candidates: in operator ()()
12232 if (!L->Viable) { in operator ()()
12241 int LDist = std::abs((int)L->getNumParams() - (int)NumArgs); in operator ()()
12242 int RDist = std::abs((int)R->getNumParams() - (int)NumArgs); in operator ()()
12245 // Sort non-surrogates before surrogates. in operator ()()
12246 return !L->IsSurrogate && R->IsSurrogate; in operator ()()
12261 // of bad conversions and quality of good conversions. in operator ()()
12266 // The conversion that can be fixed with a smaller number of changes, in operator ()()
12268 unsigned numLFixes = L->Fix.NumConversionsFixed; in operator ()()
12269 unsigned numRFixes = R->Fix.NumConversionsFixed; in operator ()()
12286 if (L->DeductionFailure.Result != R->DeductionFailure.Result) { in operator ()()
12287 unsigned LRank = RankDeductionFailure(L->DeductionFailure); in operator ()()
12288 unsigned RRank = RankDeductionFailure(R->DeductionFailure); in operator ()()
12302 // Put candidates without locations (e.g. builtins) at the end. in operator ()()
12339 // Returns -1 if conversions in L are considered better.
12357 ? -1 in CompareConversions()
12367 /// CompleteNonViableCandidate - Normally, overload resolution only
12368 /// computes up to the first bad conversion. Produces the FixIt set if
12374 assert(!Cand->Viable); in CompleteNonViableCandidate()
12376 // Don't do anything on failures other than bad conversion. in CompleteNonViableCandidate()
12377 if (Cand->FailureKind != ovl_fail_bad_conversion) in CompleteNonViableCandidate()
12382 // Use a implicit copy initialization to check conversion fixes. in CompleteNonViableCandidate()
12383 Cand->Fix.setConversionChecker(TryCopyInitialization); in CompleteNonViableCandidate()
12385 // Attempt to fix the bad conversion. in CompleteNonViableCandidate()
12386 unsigned ConvCount = Cand->Conversions.size(); in CompleteNonViableCandidate()
12387 for (unsigned ConvIdx = (Cand->IgnoreObjectArgument ? 1 : 0); /**/; in CompleteNonViableCandidate()
12389 assert(ConvIdx != ConvCount && "no bad conversion in candidate"); in CompleteNonViableCandidate()
12390 if (Cand->Conversions[ConvIdx].isInitialized() && in CompleteNonViableCandidate()
12391 Cand->Conversions[ConvIdx].isBad()) { in CompleteNonViableCandidate()
12392 Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S); in CompleteNonViableCandidate()
12404 bool Reversed = Cand->isReversed(); in CompleteNonViableCandidate()
12406 if (Cand->IsSurrogate) { in CompleteNonViableCandidate()
12408 = Cand->Surrogate->getConversionType().getNonReferenceType(); in CompleteNonViableCandidate()
12409 if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>()) in CompleteNonViableCandidate()
12410 ConvType = ConvPtrType->getPointeeType(); in CompleteNonViableCandidate()
12411 ParamTypes = ConvType->castAs<FunctionProtoType>()->getParamTypes(); in CompleteNonViableCandidate()
12412 // Conversion 0 is 'this', which doesn't have a corresponding parameter. in CompleteNonViableCandidate()
12414 } else if (Cand->Function) { in CompleteNonViableCandidate()
12416 Cand->Function->getType()->castAs<FunctionProtoType>()->getParamTypes(); in CompleteNonViableCandidate()
12417 if (isa<CXXMethodDecl>(Cand->Function) && in CompleteNonViableCandidate()
12418 !isa<CXXConstructorDecl>(Cand->Function) && !Reversed) { in CompleteNonViableCandidate()
12419 // Conversion 0 is 'this', which doesn't have a corresponding parameter. in CompleteNonViableCandidate()
12422 Cand->Function->getDeclName().getCXXOverloadedOperator() != OO_Call && in CompleteNonViableCandidate()
12423 Cand->Function->getDeclName().getCXXOverloadedOperator() != in CompleteNonViableCandidate()
12431 ParamTypes = Cand->BuiltinParamTypes; in CompleteNonViableCandidate()
12434 // Fill in the rest of the conversions. in CompleteNonViableCandidate()
12435 for (unsigned ParamIdx = Reversed ? ParamTypes.size() - 1 : 0; in CompleteNonViableCandidate()
12437 ++ConvIdx, ++ArgIdx, ParamIdx += (Reversed ? -1 : 1)) { in CompleteNonViableCandidate()
12438 assert(ArgIdx < Args.size() && "no argument for this arg conversion"); in CompleteNonViableCandidate()
12439 if (Cand->Conversions[ConvIdx].isInitialized()) { in CompleteNonViableCandidate()
12440 // We've already checked this conversion. in CompleteNonViableCandidate()
12442 if (ParamTypes[ParamIdx]->isDependentType()) in CompleteNonViableCandidate()
12443 Cand->Conversions[ConvIdx].setAsIdentityConversion( in CompleteNonViableCandidate()
12444 Args[ArgIdx]->getType()); in CompleteNonViableCandidate()
12446 Cand->Conversions[ConvIdx] = in CompleteNonViableCandidate()
12453 if (!Unfixable && Cand->Conversions[ConvIdx].isBad()) in CompleteNonViableCandidate()
12454 Unfixable = !Cand->TryToFixBadConversion(ConvIdx, S); in CompleteNonViableCandidate()
12457 Cand->Conversions[ConvIdx].setEllipsis(); in CompleteNonViableCandidate()
12466 // be prohibitive, so we make a set of pointers and sort those. in CompleteCandidates()
12469 for (iterator Cand = begin(), LastCand = end(); Cand != LastCand; ++Cand) { in CompleteCandidates()
12474 if (!Cand->Viable) { in CompleteCandidates()
12475 if (!Cand->Function && !Cand->IsSurrogate) { in CompleteCandidates()
12476 // This a non-viable builtin candidate. We do not, in general, in CompleteCandidates()
12485 if (!Cand->Viable) in CompleteCandidates()
12490 if (!Cand->Best) in CompleteCandidates()
12508 // Defer diagnostic for CUDA/HIP if there are wrong-sided candidates or in shouldDeferDiags()
12515 Cand.Function->template hasAttr<CUDAHostAttr>() && in shouldDeferDiags()
12516 Cand.Function->template hasAttr<CUDADeviceAttr>()); in shouldDeferDiags()
12538 if (Arg->getType()->isWebAssemblyTableType()) in NoteCandidates()
12546 MaybeDiagnoseAmbiguousConstraints(S, {begin(), end()}); in NoteCandidates()
12556 auto I = Cands.begin(), E = Cands.end(); in NoteCandidates()
12566 if (Cand->Function) in NoteCandidates()
12569 else if (Cand->IsSurrogate) in NoteCandidates()
12572 assert(Cand->Viable && in NoteCandidates()
12573 "Non-viable built-in candidates are not added to Cands."); in NoteCandidates()
12576 // ambiguous user-defined conversion. in NoteCandidates()
12591 // inform the future value of S.Diags.getNumOverloadCandidatesToShow(). in NoteCandidates()
12597 << int(E - I); in NoteCandidates()
12602 return Cand->Specialization ? Cand->Specialization->getLocation() in GetLocationForCandidate()
12613 // Fast-path this check. in operator ()()
12619 // Sort by the ranking of deduction failures. in operator ()()
12620 if (L->DeductionFailure.Result != R->DeductionFailure.Result) in operator ()()
12621 return RankDeductionFailure(L->DeductionFailure) < in operator ()()
12622 RankDeductionFailure(R->DeductionFailure); in operator ()()
12628 // Put candidates without locations (e.g. builtins) at the end. in operator ()()
12649 for (iterator i = begin(), e = end(); i != e; ++i) { in destroyCandidates()
12650 i->DeductionFailure.Destroy(); in destroyCandidates()
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.
12666 // Sorting directly would be prohibitive, so we make a set of pointers in NoteCandidates()
12670 for (iterator Cand = begin(), LastCand = end(); Cand != LastCand; ++Cand) { in NoteCandidates()
12671 if (Cand->Specialization) in NoteCandidates()
12673 // Otherwise, this is a non-matching builtin candidate. We do not, in NoteCandidates()
12685 for (I = Cands.begin(), E = Cands.end(); I != E; ++I) { in NoteCandidates()
12688 // Set an arbitrary limit on the number of candidates we'll spam in NoteCandidates()
12689 // the user with. FIXME: This limit should depend on details of the in NoteCandidates()
12695 assert(Cand->Specialization && in NoteCandidates()
12696 "Non-matching built-in candidates are not added to Cands."); in NoteCandidates()
12697 Cand->NoteDeductionFailure(S, ForTakingAddress); in NoteCandidates()
12701 S.Diag(Loc, diag::note_ovl_too_many_candidates) << int(E - I); in NoteCandidates()
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>()) in ExtractUnqualifiedFunctionType()
12714 Ret = ToTypePtr->getPointeeType(); in ExtractUnqualifiedFunctionType()
12716 PossiblyAFunctionType->getAs<ReferenceType>()) in ExtractUnqualifiedFunctionType()
12717 Ret = ToTypeRef->getPointeeType(); in ExtractUnqualifiedFunctionType()
12719 PossiblyAFunctionType->getAs<MemberPointerType>()) in ExtractUnqualifiedFunctionType()
12720 Ret = MemTypePtr->getPointeeType(); in ExtractUnqualifiedFunctionType()
12728 if (S.getLangOpts().CPlusPlus14 && FD->getReturnType()->isUndeducedType() && in completeFunctionType()
12732 auto *FPT = FD->getType()->castAs<FunctionProtoType>(); in completeFunctionType()
12734 isUnresolvedExceptionSpec(FPT->getExceptionSpecType()) && in completeFunctionType()
12742 // A helper class to help with address of function resolution
12743 // - allows us to avoid passing around all those ugly parameters
12771 !!TargetType->getAs<MemberPointerType>()), in AddressOfFunctionResolver()
12777 FailedCandidates(OvlExpr->getNameLoc(), /*ForTakingAddress=*/true) { in AddressOfFunctionResolver()
12780 if (TargetFunctionType->isFunctionType()) { in AddressOfFunctionResolver()
12782 if (!UME->isImplicitAccess() && in AddressOfFunctionResolver()
12785 } else if (OvlExpr->hasExplicitTemplateArgs()) { in AddressOfFunctionResolver()
12790 if (!Method->isStatic()) { in AddressOfFunctionResolver()
12791 // If the target type is a non-function type and the function found in AddressOfFunctionResolver()
12792 // is a non-static member function, pretend as if that was the in AddressOfFunctionResolver()
12793 // target, it's the only possible type to end up with. in AddressOfFunctionResolver()
12797 // We'll diagnose this due to an empty set of functions. in AddressOfFunctionResolver()
12807 if (OvlExpr->hasExplicitTemplateArgs()) in AddressOfFunctionResolver()
12808 OvlExpr->copyTemplateArgumentsInto(OvlExplicitTemplateArgs); in AddressOfFunctionResolver()
12830 return Context.hasSameUnqualifiedType(TargetFunctionType, FD->getType()) || in candidateHasExactlyCorrectType()
12831 S.IsFunctionConversion(FD->getType(), TargetFunctionType, Discard); in candidateHasExactlyCorrectType()
12848 // Same algorithm as overload resolution -- one pass to pick the "best", in eliminiateSuboptimalOverloadCandidates()
12851 for (auto I = Matches.begin()+1, E = Matches.end(); I != E; ++I) in eliminiateSuboptimalOverloadCandidates()
12852 if (isBetterCandidate(I->second, Best->second)) in eliminiateSuboptimalOverloadCandidates()
12855 const FunctionDecl *BestFn = Best->second; in eliminiateSuboptimalOverloadCandidates()
12871 return TargetFunctionType->isFunctionType(); in isTargetTypeAFunction()
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())) { in AddMatchingTemplateFunction()
12888 // Skip non-static function templates when converting to pointer, and in AddMatchingTemplateFunction()
12891 Method->isStatic() || Method->isExplicitObjectMemberFunction(); in AddMatchingTemplateFunction()
12902 // function template specialization, which is added to the set of in AddMatchingTemplateFunction()
12910 // Make a note of the failed deduction for diagnostics. in AddMatchingTemplateFunction()
12912 .set(CurAccessFunPair, FunctionTemplate->getTemplatedDecl(), in AddMatchingTemplateFunction()
12918 // compatible pointer-to-function arguments that would be adjusted by ICS. in AddMatchingTemplateFunction()
12921 Context.getCanonicalType(Specialization->getType()), in AddMatchingTemplateFunction()
12934 // Skip non-static functions when converting to pointer, and static in AddMatchingNonTemplateFunction()
12937 Method->isStatic() || Method->isExplicitObjectMemberFunction(); in AddMatchingNonTemplateFunction()
12947 if (!(Caller && Caller->isImplicit()) && in AddMatchingNonTemplateFunction()
12951 if (FunDecl->isMultiVersion()) { in AddMatchingNonTemplateFunction()
12952 const auto *TA = FunDecl->getAttr<TargetAttr>(); in AddMatchingNonTemplateFunction()
12953 if (TA && !TA->isDefaultVersion()) in AddMatchingNonTemplateFunction()
12955 const auto *TVA = FunDecl->getAttr<TargetVersionAttr>(); in AddMatchingNonTemplateFunction()
12956 if (TVA && !TVA->isDefaultVersion()) in AddMatchingNonTemplateFunction()
12962 if (completeFunctionType(S, FunDecl, SourceExpr->getBeginLoc(), in AddMatchingNonTemplateFunction()
12975 CurAccessFunPair, cast<FunctionDecl>(FunDecl->getCanonicalDecl()))); in AddMatchingNonTemplateFunction()
12987 // If the overload expression doesn't have the form of a pointer to in FindAllFunctionsThatMatchTargetTypeExactly()
12988 // member, don't try to convert it to a pointer-to-member type. in FindAllFunctionsThatMatchTargetTypeExactly()
12992 for (UnresolvedSetIterator I = OvlExpr->decls_begin(), in FindAllFunctionsThatMatchTargetTypeExactly()
12993 E = OvlExpr->decls_end(); in FindAllFunctionsThatMatchTargetTypeExactly()
12996 NamedDecl *Fn = (*I)->getUnderlyingDecl(); in FindAllFunctionsThatMatchTargetTypeExactly()
12999 // Non-member functions and static member functions match in FindAllFunctionsThatMatchTargetTypeExactly()
13000 // targets of type "pointer-to-function" or "reference-to-function." in FindAllFunctionsThatMatchTargetTypeExactly()
13001 // Nonstatic member functions match targets of in FindAllFunctionsThatMatchTargetTypeExactly()
13002 // type "pointer-to-member-function." in FindAllFunctionsThatMatchTargetTypeExactly()
13009 // If we have explicit template arguments supplied, skip non-templates. in FindAllFunctionsThatMatchTargetTypeExactly()
13010 else if (!OvlExpr->hasExplicitTemplateArgs() && in FindAllFunctionsThatMatchTargetTypeExactly()
13022 // than the function template of F1 according to the partial in EliminateAllExceptMostSpecializedTemplate()
13023 // ordering rules of 14.5.5.2. in EliminateAllExceptMostSpecializedTemplate()
13026 // two-pass algorithm (similar to the one used to identify the in EliminateAllExceptMostSpecializedTemplate()
13037 MatchesCopy.begin(), MatchesCopy.end(), FailedCandidates, in EliminateAllExceptMostSpecializedTemplate()
13038 SourceExpr->getBeginLoc(), S.PDiag(), in EliminateAllExceptMostSpecializedTemplate()
13040 << Matches[0].second->getDeclName(), in EliminateAllExceptMostSpecializedTemplate()
13045 if (Result != MatchesCopy.end()) { in EliminateAllExceptMostSpecializedTemplate()
13047 Matches[0].first = Matches[Result - MatchesCopy.begin()].first; in EliminateAllExceptMostSpecializedTemplate()
13056 // eliminated if the set also contains a non-template function, [...] in EliminateAllTemplateMatches()
13058 if (Matches[I].second->getPrimaryTemplate() == nullptr) in EliminateAllTemplateMatches()
13061 Matches[I] = Matches[--N]; in EliminateAllTemplateMatches()
13075 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_no_viable) in ComplainNoMatchesFound()
13076 << OvlExpr->getName() << TargetFunctionType in ComplainNoMatchesFound()
13077 << OvlExpr->getSourceRange(); in ComplainNoMatchesFound()
13083 // the function templates, and diagnose the non-template candidates in ComplainNoMatchesFound()
13085 for (UnresolvedSetIterator I = OvlExpr->decls_begin(), in ComplainNoMatchesFound()
13086 IEnd = OvlExpr->decls_end(); in ComplainNoMatchesFound()
13089 dyn_cast<FunctionDecl>((*I)->getUnderlyingDecl())) in ComplainNoMatchesFound()
13093 FailedCandidates.NoteCandidates(S, OvlExpr->getBeginLoc()); in ComplainNoMatchesFound()
13106 S.Diag(OvlExpr->getNameLoc(), diag::err_addr_ovl_no_qualifier) in ComplainIsInvalidFormOfPointerToMemberFunction()
13107 << TargetType << OvlExpr->getSourceRange(); in ComplainIsInvalidFormOfPointerToMemberFunction()
13115 S.Diag(OvlExpr->getBeginLoc(), in ComplainIsStaticMemberFunctionFromBoundPointer()
13117 << OvlExpr->getSourceRange(); in ComplainIsStaticMemberFunctionFromBoundPointer()
13121 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_not_func_ptrref) in ComplainOfInvalidConversion()
13122 << OvlExpr->getName() << TargetType; in ComplainOfInvalidConversion()
13127 S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_ambiguous) in ComplainMultipleMatchesFound()
13128 << OvlExpr->getName() << OvlExpr->getSourceRange(); in ComplainMultipleMatchesFound()
13133 bool hadMultipleCandidates() const { return (OvlExpr->getNumDecls() > 1); } in hadMultipleCandidates()
13155 assert(AddressOfExpr->getType() == Context.OverloadTy); in ResolveAddressOfOverloadedFunction()
13173 if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>()) in ResolveAddressOfOverloadedFunction()
13174 ResolveExceptionSpec(AddressOfExpr->getExprLoc(), FPT); in ResolveAddressOfOverloadedFunction()
13201 return static_cast<int>(CUDA().IdentifyPreference(Caller, FD1)) - in resolveAddressOfSingleOverloadCandidate()
13208 for (auto I = Ovl->decls_begin(), E = Ovl->decls_end(); I != E; ++I) { in resolveAddressOfSingleOverloadCandidate()
13209 auto *FD = dyn_cast<FunctionDecl>(I->getUnderlyingDecl()); in resolveAddressOfSingleOverloadCandidate()
13223 // We have more than one result - see if it is more constrained than the in resolveAddressOfSingleOverloadCandidate()
13249 // FD is more constrained - replace Result with it. in resolveAddressOfSingleOverloadCandidate()
13278 assert(E->getType() == Context.OverloadTy && "SrcExpr must be an overload"); in resolveAndFixAddressOfSingleOverloadCandidate()
13282 if (!Found || Found->isCPUDispatchMultiVersion() || in resolveAndFixAddressOfSingleOverloadCandidate()
13283 Found->isCPUSpecificMultiVersion()) in resolveAndFixAddressOfSingleOverloadCandidate()
13289 DiagnoseUseOfDecl(Found, E->getExprLoc()); in resolveAndFixAddressOfSingleOverloadCandidate()
13295 if (DoFunctionPointerConversion && Fixed->getType()->isFunctionType()) in resolveAndFixAddressOfSingleOverloadCandidate()
13306 // [...] [Note: any redundant set of parentheses surrounding the in ResolveSingleFunctionTemplateSpecialization()
13312 // If we didn't actually find any template-ids, we're done. in ResolveSingleFunctionTemplateSpecialization()
13313 if (!ovl->hasExplicitTemplateArgs()) in ResolveSingleFunctionTemplateSpecialization()
13317 ovl->copyTemplateArgumentsInto(ExplicitTemplateArgs); in ResolveSingleFunctionTemplateSpecialization()
13319 // Look through all of the overloaded functions, searching for one in ResolveSingleFunctionTemplateSpecialization()
13322 for (UnresolvedSetIterator I = ovl->decls_begin(), in ResolveSingleFunctionTemplateSpecialization()
13323 E = ovl->decls_end(); I != E; ++I) { in ResolveSingleFunctionTemplateSpecialization()
13329 // template-id is an lvalue for the function template specialization. in ResolveSingleFunctionTemplateSpecialization()
13331 = cast<FunctionTemplateDecl>((*I)->getUnderlyingDecl()); in ResolveSingleFunctionTemplateSpecialization()
13337 // function template specialization, which is added to the set of in ResolveSingleFunctionTemplateSpecialization()
13340 TemplateDeductionInfo Info(ovl->getNameLoc()); in ResolveSingleFunctionTemplateSpecialization()
13345 // Make a note of the failed deduction for diagnostics. in ResolveSingleFunctionTemplateSpecialization()
13347 FailedTSC->addCandidate().set( in ResolveSingleFunctionTemplateSpecialization()
13348 I.getPair(), FunctionTemplate->getTemplatedDecl(), in ResolveSingleFunctionTemplateSpecialization()
13358 Diag(ovl->getExprLoc(), diag::err_addr_ovl_ambiguous) in ResolveSingleFunctionTemplateSpecialization()
13359 << ovl->getName(); in ResolveSingleFunctionTemplateSpecialization()
13370 completeFunctionType(*this, Matched, ovl->getExprLoc(), Complain)) in ResolveSingleFunctionTemplateSpecialization()
13380 assert(SrcExpr.get()->getType() == Context.OverloadTy); in ResolveAndFixSingleFunctionTemplateSpecialization()
13388 if (DiagnoseUseOfDecl(fn, SrcExpr.get()->getBeginLoc())) { in ResolveAndFixSingleFunctionTemplateSpecialization()
13395 // Otherwise we'll end up making a bound member expression, which in ResolveAndFixSingleFunctionTemplateSpecialization()
13399 cast<CXXMethodDecl>(fn)->isInstance()) { in ResolveAndFixSingleFunctionTemplateSpecialization()
13402 Diag(ovl.Expression->getExprLoc(), in ResolveAndFixSingleFunctionTemplateSpecialization()
13404 << 0 << ovl.Expression->getSourceRange(); in ResolveAndFixSingleFunctionTemplateSpecialization()
13406 // TODO: I believe we only end up here if there's a mix of in ResolveAndFixSingleFunctionTemplateSpecialization()
13407 // static and non-static candidates (otherwise the expression in ResolveAndFixSingleFunctionTemplateSpecialization()
13419 // If desired, do function-to-pointer decay. in ResolveAndFixSingleFunctionTemplateSpecialization()
13433 << ovl.Expression->getName() in ResolveAndFixSingleFunctionTemplateSpecialization()
13436 << ovl.Expression->getQualifierLoc().getSourceRange(); in ResolveAndFixSingleFunctionTemplateSpecialization()
13460 Callee = cast<UsingShadowDecl>(Callee)->getTargetDecl(); in AddOverloadedCallCandidate()
13467 // Prevent ill-formed function decls to be added as overload candidates. in AddOverloadedCallCandidate()
13468 if (!isa<FunctionProtoType>(Func->getType()->getAs<FunctionType>())) in AddOverloadedCallCandidate()
13502 // -- a declaration of a class member, or in AddOverloadedCallCandidates()
13504 // -- a block-scope function declaration that is not a in AddOverloadedCallCandidates()
13505 // using-declaration, or in AddOverloadedCallCandidates()
13507 // -- a declaration that is neither a function or a function in AddOverloadedCallCandidates()
13512 if (ULE->requiresADL()) { in AddOverloadedCallCandidates()
13513 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), in AddOverloadedCallCandidates()
13514 E = ULE->decls_end(); I != E; ++I) { in AddOverloadedCallCandidates()
13515 assert(!(*I)->getDeclContext()->isRecord()); in AddOverloadedCallCandidates()
13517 !(*I)->getDeclContext()->isFunctionOrMethod()); in AddOverloadedCallCandidates()
13518 assert((*I)->getUnderlyingDecl()->isFunctionOrFunctionTemplate()); in AddOverloadedCallCandidates()
13526 if (ULE->hasExplicitTemplateArgs()) { in AddOverloadedCallCandidates()
13527 ULE->copyTemplateArgumentsInto(TABuffer); in AddOverloadedCallCandidates()
13531 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(), in AddOverloadedCallCandidates()
13532 E = ULE->decls_end(); I != E; ++I) in AddOverloadedCallCandidates()
13537 if (ULE->requiresADL()) in AddOverloadedCallCandidates()
13538 AddArgumentDependentLookupCandidates(ULE->getName(), ULE->getExprLoc(), in AddOverloadedCallCandidates()
13546 for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) in AddOverloadedCallCandidates()
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()) { in DiagnoseTwoPhaseLookup()
13579 if (DC->isTransparentContext()) in DiagnoseTwoPhaseLookup()
13596 // We either found non-function declarations or a best viable function in DiagnoseTwoPhaseLookup()
13597 // at class scope. A class-scope lookup result disables ADL. Don't in DiagnoseTwoPhaseLookup()
13604 R.addDecl(Best->FoundDecl.getDecl(), Best->FoundDecl.getAccess()); in DiagnoseTwoPhaseLookup()
13628 end = AssociatedNamespaces.end(); it != end; ++it) { in DiagnoseTwoPhaseLookup() local
13630 if (Std && Std->Encloses(*it)) in DiagnoseTwoPhaseLookup()
13637 NS->getQualifiedNameAsString().find("__") != std::string::npos) in DiagnoseTwoPhaseLookup()
13647 SemaRef.Diag(Best->Function->getLocation(), in DiagnoseTwoPhaseLookup()
13651 SemaRef.Diag(Best->Function->getLocation(), in DiagnoseTwoPhaseLookup()
13657 // a localized representation of a list of items. in DiagnoseTwoPhaseLookup()
13658 SemaRef.Diag(Best->Function->getLocation(), in DiagnoseTwoPhaseLookup()
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
13707 /// This function will do one of three things:
13722 // template <typename T> auto foo(T t) -> decltype(foo(t)) {} in BuildRecoveryCallExpr()
13723 // template <typename T> auto foo(T t) -> decltype(foo(&t)) {} in BuildRecoveryCallExpr()
13729 SS.Adopt(ULE->getQualifierLoc()); in BuildRecoveryCallExpr()
13730 SourceLocation TemplateKWLoc = ULE->getTemplateKeywordLoc(); in BuildRecoveryCallExpr()
13734 if (ULE->hasExplicitTemplateArgs()) { in BuildRecoveryCallExpr()
13735 ULE->copyTemplateArgumentsInto(TABuffer); in BuildRecoveryCallExpr()
13739 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(), in BuildRecoveryCallExpr()
13742 if (DiagnoseTwoPhaseLookup(SemaRef, Fn->getExprLoc(), SS, R, in BuildRecoveryCallExpr()
13745 // OK, diagnosed a two-phase lookup issue. in BuildRecoveryCallExpr()
13761 // We found a usable declaration of the name in a dependent base of some in BuildRecoveryCallExpr()
13786 if ((*R.begin())->isCXXClassMember()) in BuildRecoveryCallExpr()
13800 // end up here. in BuildRecoveryCallExpr()
13813 if (ULE->requiresADL()) { in buildOverloadedCallSet()
13815 assert(!ULE->getQualifier() && "qualified name with ADL"); in buildOverloadedCallSet()
13817 // We don't perform ADL for implicit declarations of builtins. in buildOverloadedCallSet()
13820 if (ULE->decls_begin() != ULE->decls_end() && in buildOverloadedCallSet()
13821 ULE->decls_begin() + 1 == ULE->decls_end() && in buildOverloadedCallSet()
13822 (F = dyn_cast<FunctionDecl>(*ULE->decls_begin())) && in buildOverloadedCallSet()
13823 F->getBuiltinID() && F->isImplicit()) in buildOverloadedCallSet()
13837 // Add the functions denoted by the callee to the set of candidate in buildOverloadedCallSet()
13838 // functions, including those from argument-dependent lookup. in buildOverloadedCallSet()
13842 CurContext->isDependentContext() && !isSFINAEContext() && in buildOverloadedCallSet()
13846 if (CandidateSet->empty() || in buildOverloadedCallSet()
13847 CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best) == in buildOverloadedCallSet()
13856 CE->markDependentForPostponedNameLookup(); in buildOverloadedCallSet()
13862 if (CandidateSet->empty()) in buildOverloadedCallSet()
13877 if (Candidate.Function->isInvalidDecl()) in chooseRecoveryType()
13879 QualType T = Candidate.Function->getReturnType(); in chooseRecoveryType()
13892 if (Best && *Best != CS.end()) in chooseRecoveryType()
13907 if (Value.isNull() || Value->isUndeducedType()) in chooseRecoveryType()
13912 /// FinishOverloadedCallExpr - given an OverloadCandidateSet, builds and returns
13927 FunctionDecl *FDecl = (*Best)->Function; in FinishOverloadedCallExpr()
13928 SemaRef.CheckUnresolvedLookupAccess(ULE, (*Best)->FoundDecl); in FinishOverloadedCallExpr()
13929 if (SemaRef.DiagnoseUseOfDecl(FDecl, ULE->getNameLoc())) in FinishOverloadedCallExpr()
13932 SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl); in FinishOverloadedCallExpr()
13937 /*IsExecConfig=*/false, (*Best)->IsADLCandidate); in FinishOverloadedCallExpr()
13941 if (*Best != CandidateSet->end() && in FinishOverloadedCallExpr()
13942 CandidateSet->getKind() == in FinishOverloadedCallExpr()
13945 dyn_cast_if_present<CXXMethodDecl>((*Best)->Function); in FinishOverloadedCallExpr()
13946 M && M->isImplicitObjectMemberFunction()) { in FinishOverloadedCallExpr()
13947 CandidateSet->NoteCandidates( in FinishOverloadedCallExpr()
13949 Fn->getBeginLoc(), in FinishOverloadedCallExpr()
13960 CandidateSet->empty(), in FinishOverloadedCallExpr()
13965 // If the user passes in a function that we can't take the address of, we in FinishOverloadedCallExpr()
13966 // generally end up emitting really bad error messages. Here, we attempt to in FinishOverloadedCallExpr()
13969 if (!Arg->getType()->isFunctionType()) in FinishOverloadedCallExpr()
13971 if (auto *DRE = dyn_cast<DeclRefExpr>(Arg->IgnoreParenImpCasts())) { in FinishOverloadedCallExpr()
13972 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()); in FinishOverloadedCallExpr()
13975 Arg->getExprLoc())) in FinishOverloadedCallExpr()
13980 CandidateSet->NoteCandidates( in FinishOverloadedCallExpr()
13982 Fn->getBeginLoc(), in FinishOverloadedCallExpr()
13984 << ULE->getName() << Fn->getSourceRange()), in FinishOverloadedCallExpr()
13990 CandidateSet->NoteCandidates( in FinishOverloadedCallExpr()
13991 PartialDiagnosticAt(Fn->getBeginLoc(), in FinishOverloadedCallExpr()
13993 << ULE->getName() << Fn->getSourceRange()), in FinishOverloadedCallExpr()
13998 FunctionDecl *FDecl = (*Best)->Function; in FinishOverloadedCallExpr()
13999 SemaRef.DiagnoseUseOfDeletedFunction(Fn->getBeginLoc(), in FinishOverloadedCallExpr()
14000 Fn->getSourceRange(), ULE->getName(), in FinishOverloadedCallExpr()
14006 SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl); in FinishOverloadedCallExpr()
14011 /*IsExecConfig=*/false, (*Best)->IsADLCandidate); in FinishOverloadedCallExpr()
14017 SubExprs.append(Args.begin(), Args.end()); in FinishOverloadedCallExpr()
14018 return SemaRef.CreateRecoveryExpr(Fn->getBeginLoc(), RParenLoc, SubExprs, in FinishOverloadedCallExpr()
14024 for (auto I = CS.begin(), E = CS.end(); I != E; ++I) { in markUnaddressableCandidatesUnviable()
14025 if (I->Viable && in markUnaddressableCandidatesUnviable()
14026 !S.checkAddressOfFunctionIsAvailable(I->Function, /*Complain=*/false)) { in markUnaddressableCandidatesUnviable()
14027 I->Viable = false; in markUnaddressableCandidatesUnviable()
14028 I->FailureKind = ovl_fail_addr_not_available; in markUnaddressableCandidatesUnviable()
14042 Fn->getExprLoc(), CalleesAddressIsTaken in BuildOverloadedCallExpr()
14058 CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best); in BuildOverloadedCallExpr()
14062 // the UnresolvedLookupExpr was type-dependent. in BuildOverloadedCallExpr()
14064 const FunctionDecl *FDecl = Best->Function; in BuildOverloadedCallExpr()
14065 if (FDecl && FDecl->isTemplateInstantiation() && in BuildOverloadedCallExpr()
14066 FDecl->getReturnType()->isUndeducedType()) { in BuildOverloadedCallExpr()
14068 FDecl->getTemplateInstantiationPattern(/*ForDefinition=*/false); in BuildOverloadedCallExpr()
14069 TP && TP->willHaveBody()) { in BuildOverloadedCallExpr()
14087 Context, NamingClass, NNSLoc, DNI, PerformADL, Fns.begin(), Fns.end(), in CreateUnresolvedLookupExpr()
14094 // Convert the expression to match the conversion function's implicit object in BuildCXXMemberCallExpr()
14097 if (Method->isExplicitObjectMemberFunction()) in BuildCXXMemberCallExpr()
14105 if (Method->getParent()->isLambda() && in BuildCXXMemberCallExpr()
14106 Method->getConversionType()->isBlockPointerType()) { in BuildCXXMemberCallExpr()
14107 // This is a lambda conversion to block pointer; check if the argument in BuildCXXMemberCallExpr()
14111 if (CE && CE->getCastKind() == CK_NoOp) in BuildCXXMemberCallExpr()
14112 SubE = CE->getSubExpr(); in BuildCXXMemberCallExpr()
14113 SubE = SubE->IgnoreParens(); in BuildCXXMemberCallExpr()
14115 SubE = BE->getSubExpr(); in BuildCXXMemberCallExpr()
14117 // For the conversion to block pointer on a lambda expression, we in BuildCXXMemberCallExpr()
14119 // a difference in ARC, but outside of ARC the resulting block literal in BuildCXXMemberCallExpr()
14120 // follows the normal lifetime rules for block literals instead of being in BuildCXXMemberCallExpr()
14125 Exp.get()->getExprLoc(), Exp.get()->getExprLoc(), Method, Exp.get()); in BuildCXXMemberCallExpr()
14130 Diag(Exp.get()->getExprLoc(), diag::note_lambda_to_block_conv); in BuildCXXMemberCallExpr()
14135 QualType ResultType = Method->getReturnType(); in BuildCXXMemberCallExpr()
14138 if (Method->isExplicitObjectMemberFunction()) { in BuildCXXMemberCallExpr()
14141 HadMultipleCandidates, E->getBeginLoc()); in BuildCXXMemberCallExpr()
14146 ResultType, VK, Exp.get()->getEndLoc(), in BuildCXXMemberCallExpr()
14152 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), in BuildCXXMemberCallExpr()
14157 Exp.get()->getEndLoc(), in BuildCXXMemberCallExpr()
14162 Method->getType()->castAs<FunctionProtoType>())) in BuildCXXMemberCallExpr()
14165 return CheckForImmediateInvocation(CE, CE->getDirectCallee()); in BuildCXXMemberCallExpr()
14184 // For post-increment and post-decrement, add the implicit '0' as in CreateOverloadedUnaryOp()
14185 // the second argument, so that we know this is a post-increment or in CreateOverloadedUnaryOp()
14186 // post-decrement. in CreateOverloadedUnaryOp()
14196 if (Input->isTypeDependent()) { in CreateOverloadedUnaryOp()
14199 // The * operator yields an lvalue of type in CreateOverloadedUnaryOp()
14244 // We found a built-in operator or an overloaded operator. in CreateOverloadedUnaryOp()
14245 FunctionDecl *FnDecl = Best->Function; in CreateOverloadedUnaryOp()
14254 CheckMemberOperatorAccess(OpLoc, Input, nullptr, Best->FoundDecl); in CreateOverloadedUnaryOp()
14257 if (Method->isExplicitObjectMemberFunction()) in CreateOverloadedUnaryOp()
14261 Input, /*Qualifier=*/nullptr, Best->FoundDecl, Method); in CreateOverloadedUnaryOp()
14270 FnDecl->getParamDecl(0)), in CreateOverloadedUnaryOp()
14279 ExprResult FnExpr = CreateFunctionRefExpr(*this, FnDecl, Best->FoundDecl, in CreateOverloadedUnaryOp()
14286 QualType ResultTy = FnDecl->getReturnType(); in CreateOverloadedUnaryOp()
14293 CurFPFeatureOverrides(), Best->IsADLCandidate); in CreateOverloadedUnaryOp()
14295 if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl)) in CreateOverloadedUnaryOp()
14299 FnDecl->getType()->castAs<FunctionProtoType>())) in CreateOverloadedUnaryOp()
14303 // We matched a built-in operator. Convert the arguments, then in CreateOverloadedUnaryOp()
14304 // break out so that we will build the appropriate built-in in CreateOverloadedUnaryOp()
14307 Input, Best->BuiltinParamTypes[0], Best->Conversions[0], AA_Passing, in CreateOverloadedUnaryOp()
14317 // This is an erroneous use of an operator which can be overloaded by in CreateOverloadedUnaryOp()
14318 // a non-member function. Check for non-member operators which were in CreateOverloadedUnaryOp()
14325 // built-in operator, which will produce an error message for us. in CreateOverloadedUnaryOp()
14333 << Input->getType() << Input->getSourceRange()), in CreateOverloadedUnaryOp()
14339 // CreateOverloadedUnaryOp fills the first element of ArgsArray with the in CreateOverloadedUnaryOp()
14340 // object whose method was called. Later in NoteCandidates size of ArgsArray in CreateOverloadedUnaryOp()
14341 // is passed further and it eventually ends up compared to number of in CreateOverloadedUnaryOp()
14344 StringLiteral *Msg = Best->Function->getDeletedMessage(); in CreateOverloadedUnaryOp()
14349 << (Msg ? Msg->getString() : StringRef()) in CreateOverloadedUnaryOp()
14350 << Input->getSourceRange()), in CreateOverloadedUnaryOp()
14358 // built-in operator. In either case, fall through to trying to in CreateOverloadedUnaryOp()
14359 // build a built-in operation. in CreateOverloadedUnaryOp()
14394 // performed for an assignment operator (nor for operator[] nor operator->, in LookupOverloadedBinOp()
14413 // incorrect; a builtin candidate could be hidden by a non-viable candidate, in LookupOverloadedBinOp()
14433 LHS=RHS=nullptr; // Please use only Args instead of LHS/RHS couple in CreateOverloadedBinOp()
14440 // If either side is type-dependent, create an appropriate dependent in CreateOverloadedBinOp()
14442 if (Args[0]->isTypeDependent() || Args[1]->isTypeDependent()) { in CreateOverloadedBinOp()
14456 // FIXME: save results of ADL from here? in CreateOverloadedBinOp()
14471 // create a built-in binary operator. in CreateOverloadedBinOp()
14487 // Always do placeholder-like conversions on the RHS. in CreateOverloadedBinOp()
14491 // Do placeholder-like conversion on the LHS; note that we should in CreateOverloadedBinOp()
14493 assert(Args[0]->getObjectKind() != OK_ObjCProperty); in CreateOverloadedBinOp()
14498 // if the left-hand side is a class or enumeration type. This is actually in CreateOverloadedBinOp()
14500 // various built-in candidates, but as DR507 points out, this can lead to in CreateOverloadedBinOp()
14503 if (Opc == BO_Assign && !Args[0]->getType()->isOverloadableType()) in CreateOverloadedBinOp()
14520 // We found a built-in operator or an overloaded operator. in CreateOverloadedBinOp()
14521 FunctionDecl *FnDecl = Best->Function; in CreateOverloadedBinOp()
14523 bool IsReversed = Best->isReversed(); in CreateOverloadedBinOp()
14529 if (FnDecl->isInvalidDecl()) in CreateOverloadedBinOp()
14537 FnDecl->getDeclName().getCXXOverloadedOperator(); in CreateOverloadedBinOp()
14542 if (Best->RewriteKind && ChosenOp == OO_EqualEqual && in CreateOverloadedBinOp()
14543 !FnDecl->getReturnType()->isBooleanType()) { in CreateOverloadedBinOp()
14545 FnDecl->getReturnType()->isIntegralOrUnscopedEnumerationType(); in CreateOverloadedBinOp()
14548 << FnDecl->getReturnType() << BinaryOperator::getOpcodeStr(Opc) in CreateOverloadedBinOp()
14549 << Args[0]->getSourceRange() << Args[1]->getSourceRange(); in CreateOverloadedBinOp()
14550 Diag(FnDecl->getLocation(), diag::note_declared_at); in CreateOverloadedBinOp()
14559 // better conversion for either parameter. If so, this call is in CreateOverloadedBinOp()
14568 Best->Conversions[ArgIdx]) == in CreateOverloadedBinOp()
14583 << Args[0]->getType() << Args[1]->getType() << AmbiguousWithSelf in CreateOverloadedBinOp()
14584 << Args[0]->getSourceRange() << Args[1]->getSourceRange(); in CreateOverloadedBinOp()
14586 Diag(FnDecl->getLocation(), in CreateOverloadedBinOp()
14594 !MD->isConst() && in CreateOverloadedBinOp()
14595 !MD->hasCXXExplicitFunctionObjectParameter() && in CreateOverloadedBinOp()
14597 MD->getFunctionObjectParameterType(), in CreateOverloadedBinOp()
14598 MD->getParamDecl(0)->getType().getNonReferenceType()) && in CreateOverloadedBinOp()
14600 MD->getFunctionObjectParameterType(), in CreateOverloadedBinOp()
14601 Args[0]->getType()) && in CreateOverloadedBinOp()
14603 MD->getFunctionObjectParameterType(), in CreateOverloadedBinOp()
14604 Args[1]->getType())) in CreateOverloadedBinOp()
14605 Diag(FnDecl->getLocation(), in CreateOverloadedBinOp()
14608 Diag(FnDecl->getLocation(), in CreateOverloadedBinOp()
14611 Diag(F->getLocation(), in CreateOverloadedBinOp()
14621 diagnoseNullableToNonnullConversion(Args[0]->getType(), in CreateOverloadedBinOp()
14622 Args[1]->getType(), OpLoc); in CreateOverloadedBinOp()
14626 // Best->Access is only meaningful for class members. in CreateOverloadedBinOp()
14627 CheckMemberOperatorAccess(OpLoc, Args[0], Args[1], Best->FoundDecl); in CreateOverloadedBinOp()
14631 if (Method->isExplicitObjectMemberFunction()) { in CreateOverloadedBinOp()
14636 Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method); in CreateOverloadedBinOp()
14640 Context, FnDecl->getParamDecl(ParamIdx)), in CreateOverloadedBinOp()
14651 FnDecl->getParamDecl(0)), in CreateOverloadedBinOp()
14659 FnDecl->getParamDecl(1)), in CreateOverloadedBinOp()
14669 Best->FoundDecl, Base, in CreateOverloadedBinOp()
14675 QualType ResultTy = FnDecl->getReturnType(); in CreateOverloadedBinOp()
14687 CurFPFeatureOverrides(), Best->IsADLCandidate); in CreateOverloadedBinOp()
14690 Method && Method->isImplicitObjectMemberFunction()) { in CreateOverloadedBinOp()
14696 if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, in CreateOverloadedBinOp()
14707 QualType ThisType = Context.getPointerType(ImplicitThis->getType()); in CreateOverloadedBinOp()
14709 cast<CXXMethodDecl>(FnDecl)->getFunctionObjectParameterType()); in CreateOverloadedBinOp()
14716 isa<CXXMethodDecl>(FnDecl), OpLoc, TheCall->getSourceRange(), in CreateOverloadedBinOp()
14728 // if needed. Perform the rest of the rewrite now. in CreateOverloadedBinOp()
14729 if ((Best->RewriteKind & CRK_DifferentOperator) || in CreateOverloadedBinOp()
14759 if (Best->RewriteKind != CRK_None) in CreateOverloadedBinOp()
14764 // We matched a built-in operator. Convert the arguments, then in CreateOverloadedBinOp()
14765 // break out so that we will build the appropriate built-in in CreateOverloadedBinOp()
14768 Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0], in CreateOverloadedBinOp()
14775 Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1], in CreateOverloadedBinOp()
14788 // built-in operator and interpreted according to clause 5. in CreateOverloadedBinOp()
14792 // When defaulting an 'operator<=>', we can try to synthesize a three-way in CreateOverloadedBinOp()
14802 // operator do not fall through to handling in built-in, but report that in CreateOverloadedBinOp()
14810 if (Args[0]->getType()->isRecordType() && in CreateOverloadedBinOp()
14814 << Args[0]->getSourceRange() << Args[1]->getSourceRange(); in CreateOverloadedBinOp()
14815 if (Args[0]->getType()->isIncompleteType()) { in CreateOverloadedBinOp()
14817 << Args[0]->getType() in CreateOverloadedBinOp()
14818 << Args[0]->getSourceRange() << Args[1]->getSourceRange(); in CreateOverloadedBinOp()
14821 // This is an erroneous use of an operator which can be overloaded by in CreateOverloadedBinOp()
14822 // a non-member function. Check for non-member operators which were in CreateOverloadedBinOp()
14828 // No viable function; try to create a built-in operation, which will in CreateOverloadedBinOp()
14829 // produce an error. Then, show the non-viable candidates. in CreateOverloadedBinOp()
14842 << Args[0]->getType() in CreateOverloadedBinOp()
14843 << Args[1]->getType() in CreateOverloadedBinOp()
14844 << Args[0]->getSourceRange() in CreateOverloadedBinOp()
14845 << Args[1]->getSourceRange()), in CreateOverloadedBinOp()
14851 if (isImplicitlyDeleted(Best->Function)) { in CreateOverloadedBinOp()
14852 FunctionDecl *DeletedFD = Best->Function; in CreateOverloadedBinOp()
14856 << Args[0]->getType() in CreateOverloadedBinOp()
14861 << Args[0]->getType() << DeletedFD; in CreateOverloadedBinOp()
14870 StringLiteral *Msg = Best->Function->getDeletedMessage(); in CreateOverloadedBinOp()
14875 << getOperatorSpelling(Best->Function->getDeclName() in CreateOverloadedBinOp()
14877 << (Msg != nullptr) << (Msg ? Msg->getString() : StringRef()) in CreateOverloadedBinOp()
14878 << Args[0]->getSourceRange() << Args[1]->getSourceRange()), in CreateOverloadedBinOp()
14885 // We matched a built-in operator; build it. in CreateOverloadedBinOp()
14893 Context.CompCategories.lookupInfoForType(DefaultedFn->getReturnType()); in BuildSynthesizedThreeWayComparison()
14895 // synthesize a three-way comparison. Let the caller diagnose this. in BuildSynthesizedThreeWayComparison()
14900 // apply the temporary materialization conversion to the operands. in BuildSynthesizedThreeWayComparison()
14901 assert(LHS->isGLValue() && RHS->isGLValue() && in BuildSynthesizedThreeWayComparison()
14907 // each of them multiple times below. in BuildSynthesizedThreeWayComparison()
14909 OpaqueValueExpr(LHS->getExprLoc(), LHS->getType(), LHS->getValueKind(), in BuildSynthesizedThreeWayComparison()
14910 LHS->getObjectKind(), LHS); in BuildSynthesizedThreeWayComparison()
14912 OpaqueValueExpr(RHS->getExprLoc(), RHS->getType(), RHS->getValueKind(), in BuildSynthesizedThreeWayComparison()
14913 RHS->getObjectKind(), RHS); in BuildSynthesizedThreeWayComparison()
14926 if (Info->isPartial()) { in BuildSynthesizedThreeWayComparison()
14933 // Form the list of comparisons we're going to perform. in BuildSynthesizedThreeWayComparison()
14938 { {Eq, Info->isStrong() ? ComparisonCategoryResult::Equal in BuildSynthesizedThreeWayComparison()
14945 int I = Info->isPartial() ? 3 : 2; in BuildSynthesizedThreeWayComparison()
14949 for (; I >= 0; --I) { in BuildSynthesizedThreeWayComparison()
14951 auto *VI = Info->lookupValueInfo(Comparisons[I].Result); in BuildSynthesizedThreeWayComparison()
14956 BuildDeclarationNameExpr(CXXScopeSpec(), DeclarationNameInfo(), VI->VD); in BuildSynthesizedThreeWayComparison()
14971 // Build a PseudoObjectExpr to model the rewriting of an <=> operator, and to in BuildSynthesizedThreeWayComparison()
14974 Context, OrigLHS, OrigRHS, BO_Cmp, Result.get()->getType(), in BuildSynthesizedThreeWayComparison()
14975 Result.get()->getValueKind(), Result.get()->getObjectKind(), OpLoc, in BuildSynthesizedThreeWayComparison()
14985 const auto *Proto = Method->getType()->castAs<FunctionProtoType>(); in PrepareArgumentsForCallToObjectOfClassType()
14986 unsigned NumParams = Proto->getNumParams(); in PrepareArgumentsForCallToObjectOfClassType()
14990 // parameter is placed at the beginning of the list). in PrepareArgumentsForCallToObjectOfClassType()
15001 S.Context, Method->getParamDecl(i)), in PrepareArgumentsForCallToObjectOfClassType()
15007 S.BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i)); in PrepareArgumentsForCallToObjectOfClassType()
15034 : SourceRange(ArgExpr.front()->getBeginLoc(), in CreateOverloadedArraySubscriptExpr()
15035 ArgExpr.back()->getEndLoc()); in CreateOverloadedArraySubscriptExpr()
15037 // If either side is type-dependent, create an appropriate dependent in CreateOverloadedArraySubscriptExpr()
15079 // We found a built-in operator or an overloaded operator. in CreateOverloadedArraySubscriptExpr()
15080 FunctionDecl *FnDecl = Best->Function; in CreateOverloadedArraySubscriptExpr()
15086 CheckMemberOperatorAccess(LLoc, Args[0], ArgExpr, Best->FoundDecl); in CreateOverloadedArraySubscriptExpr()
15093 if (Method->isExplicitObjectMemberFunction()) { in CreateOverloadedArraySubscriptExpr()
15102 Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method); in CreateOverloadedArraySubscriptExpr()
15118 *this, FnDecl, Best->FoundDecl, Base, HadMultipleCandidates, in CreateOverloadedArraySubscriptExpr()
15124 QualType ResultTy = FnDecl->getReturnType(); in CreateOverloadedArraySubscriptExpr()
15132 if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl)) in CreateOverloadedArraySubscriptExpr()
15136 Method->getType()->castAs<FunctionProtoType>())) in CreateOverloadedArraySubscriptExpr()
15142 // We matched a built-in operator. Convert the arguments, then in CreateOverloadedArraySubscriptExpr()
15143 // break out so that we will build the appropriate built-in in CreateOverloadedArraySubscriptExpr()
15146 Args[0], Best->BuiltinParamTypes[0], Best->Conversions[0], in CreateOverloadedArraySubscriptExpr()
15153 Args[1], Best->BuiltinParamTypes[1], Best->Conversions[1], in CreateOverloadedArraySubscriptExpr()
15167 << Args[0]->getType() << /*subscript*/ 0 in CreateOverloadedArraySubscriptExpr()
15168 << Args[0]->getSourceRange() << Range) in CreateOverloadedArraySubscriptExpr()
15170 << Args[0]->getType() << Args[0]->getSourceRange() << Range); in CreateOverloadedArraySubscriptExpr()
15181 << "[]" << Args[0]->getType() << Args[1]->getType() in CreateOverloadedArraySubscriptExpr()
15182 << Args[0]->getSourceRange() << Range), in CreateOverloadedArraySubscriptExpr()
15188 << Args[0]->getType() in CreateOverloadedArraySubscriptExpr()
15189 << Args[0]->getSourceRange() << Range), in CreateOverloadedArraySubscriptExpr()
15195 StringLiteral *Msg = Best->Function->getDeletedMessage(); in CreateOverloadedArraySubscriptExpr()
15200 << (Msg ? Msg->getString() : StringRef()) in CreateOverloadedArraySubscriptExpr()
15201 << Args[0]->getSourceRange() << Range), in CreateOverloadedArraySubscriptExpr()
15207 // We matched a built-in operator; build it. in CreateOverloadedArraySubscriptExpr()
15217 assert(MemExprE->getType() == Context.BoundMemberTy || in BuildCallToMemberFunction()
15218 MemExprE->getType() == Context.OverloadTy); in BuildCallToMemberFunction()
15222 Expr *NakedMemExpr = MemExprE->IgnoreParens(); in BuildCallToMemberFunction()
15224 // Determine whether this is a call to a pointer-to-member function. in BuildCallToMemberFunction()
15226 assert(op->getType() == Context.BoundMemberTy); in BuildCallToMemberFunction()
15227 assert(op->getOpcode() == BO_PtrMemD || op->getOpcode() == BO_PtrMemI); in BuildCallToMemberFunction()
15230 op->getRHS()->getType()->castAs<MemberPointerType>()->getPointeeType(); in BuildCallToMemberFunction()
15232 const FunctionProtoType *proto = fnType->castAs<FunctionProtoType>(); in BuildCallToMemberFunction()
15233 QualType resultType = proto->getCallResultType(Context); in BuildCallToMemberFunction()
15234 ExprValueKind valueKind = Expr::getValueKindForType(proto->getReturnType()); in BuildCallToMemberFunction()
15238 Qualifiers funcQuals = proto->getMethodQuals(); in BuildCallToMemberFunction()
15240 QualType objectType = op->getLHS()->getType(); in BuildCallToMemberFunction()
15241 if (op->getOpcode() == BO_PtrMemI) in BuildCallToMemberFunction()
15242 objectType = objectType->castAs<PointerType>()->getPointeeType(); in BuildCallToMemberFunction()
15245 Qualifiers difference = objectQuals - funcQuals; in BuildCallToMemberFunction()
15258 CurFPFeatureOverrides(), proto->getNumParams()); in BuildCallToMemberFunction()
15260 if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getBeginLoc(), in BuildCallToMemberFunction()
15281 return CreateRecoveryExpr(MemExprE->getBeginLoc(), RParenLoc, SubExprs, in BuildCallToMemberFunction()
15299 Method = cast<CXXMethodDecl>(MemExpr->getMemberDecl()); in BuildCallToMemberFunction()
15300 FoundDecl = MemExpr->getFoundDecl(); in BuildCallToMemberFunction()
15301 Qualifier = MemExpr->getQualifier(); in BuildCallToMemberFunction()
15305 Qualifier = UnresExpr->getQualifier(); in BuildCallToMemberFunction()
15307 QualType ObjectType = UnresExpr->getBaseType(); in BuildCallToMemberFunction()
15309 = UnresExpr->isArrow()? Expr::Classification::makeSimpleLValue() in BuildCallToMemberFunction()
15310 : UnresExpr->getBase()->Classify(Context); in BuildCallToMemberFunction()
15313 OverloadCandidateSet CandidateSet(UnresExpr->getMemberLoc(), in BuildCallToMemberFunction()
15318 if (UnresExpr->hasExplicitTemplateArgs()) { in BuildCallToMemberFunction()
15319 UnresExpr->copyTemplateArgumentsInto(TemplateArgsBuffer); in BuildCallToMemberFunction()
15323 for (UnresolvedMemberExpr::decls_iterator I = UnresExpr->decls_begin(), in BuildCallToMemberFunction()
15324 E = UnresExpr->decls_end(); I != E; ++I) { in BuildCallToMemberFunction()
15329 CXXRecordDecl *ActingDC = cast<CXXRecordDecl>(Func->getDeclContext()); in BuildCallToMemberFunction()
15331 Func = cast<UsingShadowDecl>(Func)->getTargetDecl(); in BuildCallToMemberFunction()
15335 M && M->hasCXXExplicitFunctionObjectParameter()) in BuildCallToMemberFunction()
15339 M->getTemplatedDecl()->hasCXXExplicitFunctionObjectParameter()) in BuildCallToMemberFunction()
15352 // non-template member function. in BuildCallToMemberFunction()
15370 DeclarationName DeclName = UnresExpr->getMemberName(); in BuildCallToMemberFunction()
15376 switch (CandidateSet.BestViableFunction(*this, UnresExpr->getBeginLoc(), in BuildCallToMemberFunction()
15379 Method = cast<CXXMethodDecl>(Best->Function); in BuildCallToMemberFunction()
15380 FoundDecl = Best->FoundDecl; in BuildCallToMemberFunction()
15381 CheckUnresolvedMemberAccess(UnresExpr, Best->FoundDecl); in BuildCallToMemberFunction()
15382 if (DiagnoseUseOfOverloadedDecl(Best->FoundDecl, UnresExpr->getNameLoc())) in BuildCallToMemberFunction()
15391 DiagnoseUseOfOverloadedDecl(Method, UnresExpr->getNameLoc())) in BuildCallToMemberFunction()
15399 UnresExpr->getMemberLoc(), in BuildCallToMemberFunction()
15401 << DeclName << MemExprE->getSourceRange()), in BuildCallToMemberFunction()
15406 PartialDiagnosticAt(UnresExpr->getMemberLoc(), in BuildCallToMemberFunction()
15408 << DeclName << MemExprE->getSourceRange()), in BuildCallToMemberFunction()
15413 UnresExpr->getMemberLoc(), MemExprE->getSourceRange(), DeclName, in BuildCallToMemberFunction()
15414 CandidateSet, Best->Function, Args, /*IsMember=*/true); in BuildCallToMemberFunction()
15428 // build a non-member call based on that function. in BuildCallToMemberFunction()
15429 if (Method->isStatic()) { in BuildCallToMemberFunction()
15434 MemExpr = cast<MemberExpr>(MemExprE->IgnoreParens()); in BuildCallToMemberFunction()
15437 QualType ResultType = Method->getReturnType(); in BuildCallToMemberFunction()
15442 const auto *Proto = Method->getType()->castAs<FunctionProtoType>(); in BuildCallToMemberFunction()
15446 if (Method->isExplicitObjectMemberFunction()) { in BuildCallToMemberFunction()
15447 if (PrepareExplicitObjectArgument(*this, Method, MemExpr->getBase(), Args, in BuildCallToMemberFunction()
15454 HadMultipleCandidates, MemExpr->getExprLoc()); in BuildCallToMemberFunction()
15460 CurFPFeatureOverrides(), Proto->getNumParams()); in BuildCallToMemberFunction()
15462 // Convert the object argument (for a non-static member function call). in BuildCallToMemberFunction()
15466 MemExpr->getBase(), Qualifier, FoundDecl, Method); in BuildCallToMemberFunction()
15469 MemExpr->setBase(ObjectArg.get()); in BuildCallToMemberFunction()
15472 Proto->getNumParams()); in BuildCallToMemberFunction()
15476 if (CheckCallReturnType(Method->getReturnType(), MemExpr->getMemberLoc(), in BuildCallToMemberFunction()
15480 // Convert the rest of the arguments in BuildCallToMemberFunction()
15492 // that here, so it will not hide previous -- and more relevant -- errors. in BuildCallToMemberFunction()
15496 Diag(MemE->getMemberLoc(), in BuildCallToMemberFunction()
15498 << Method << Method->getSourceRange(); in BuildCallToMemberFunction()
15499 Diag(Method->getLocation(), in BuildCallToMemberFunction()
15501 << Attr->getCond()->getSourceRange() << Attr->getMessage(); in BuildCallToMemberFunction()
15507 TheCall->getDirectCallee()->isPureVirtual()) { in BuildCallToMemberFunction()
15508 const FunctionDecl *MD = TheCall->getDirectCallee(); in BuildCallToMemberFunction()
15510 if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts()) && in BuildCallToMemberFunction()
15511 MemExpr->performsVirtualDispatch(getLangOpts())) { in BuildCallToMemberFunction()
15512 Diag(MemExpr->getBeginLoc(), in BuildCallToMemberFunction()
15514 << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext) in BuildCallToMemberFunction()
15515 << MD->getParent(); in BuildCallToMemberFunction()
15517 Diag(MD->getBeginLoc(), diag::note_previous_decl) << MD->getDeclName(); in BuildCallToMemberFunction()
15519 Diag(MemExpr->getBeginLoc(), diag::note_pure_qualified_call_kext) in BuildCallToMemberFunction()
15520 << MD->getParent() << MD->getDeclName(); in BuildCallToMemberFunction()
15524 if (auto *DD = dyn_cast<CXXDestructorDecl>(TheCall->getDirectCallee())) { in BuildCallToMemberFunction()
15525 // a->A::f() doesn't go through the vtable, except in AppleKext mode. in BuildCallToMemberFunction()
15526 bool CallCanBeVirtual = !MemExpr->hasQualifier() || getLangOpts().AppleKext; in BuildCallToMemberFunction()
15527 CheckVirtualDtorCall(DD, MemExpr->getBeginLoc(), /*IsDelete=*/false, in BuildCallToMemberFunction()
15529 MemExpr->getMemberLoc()); in BuildCallToMemberFunction()
15533 TheCall->getDirectCallee()); in BuildCallToMemberFunction()
15549 assert(Object.get()->getType()->isRecordType() && in BuildCallToObjectOfClassType()
15553 // If the primary-expression E in the function call syntax in BuildCallToObjectOfClassType()
15554 // evaluates to a class object of type "cv T", then the set of in BuildCallToObjectOfClassType()
15556 // operators of T. The function call operators of T are obtained by in BuildCallToObjectOfClassType()
15557 // ordinary lookup of the name operator() in the context of in BuildCallToObjectOfClassType()
15563 if (RequireCompleteType(LParenLoc, Object.get()->getType(), in BuildCallToObjectOfClassType()
15567 const auto *Record = Object.get()->getType()->castAs<RecordType>(); in BuildCallToObjectOfClassType()
15569 LookupQualifiedName(R, Record->getDecl()); in BuildCallToObjectOfClassType()
15572 for (LookupResult::iterator Oper = R.begin(), OperEnd = R.end(); in BuildCallToObjectOfClassType()
15574 AddMethodCandidate(Oper.getPair(), Object.get()->getType(), in BuildCallToObjectOfClassType()
15575 Object.get()->Classify(Context), Args, CandidateSet, in BuildCallToObjectOfClassType()
15580 // the conversion operator to function pointer in BuildCallToObjectOfClassType()
15583 // conversion operator as the constraints are always the same. in BuildCallToObjectOfClassType()
15586 // showing 2 failed overloads instead of one. in BuildCallToObjectOfClassType()
15588 if (CandidateSet.size() == 1 && Record->getAsCXXRecordDecl()->isLambda()) { in BuildCallToObjectOfClassType()
15596 // In addition, for each (non-explicit in C++0x) conversion function in BuildCallToObjectOfClassType()
15597 // declared in T of the form in BuildCallToObjectOfClassType()
15599 // operator conversion-type-id () cv-qualifier; in BuildCallToObjectOfClassType()
15601 // where cv-qualifier is the same cv-qualification as, or a in BuildCallToObjectOfClassType()
15602 // greater cv-qualification than, cv, and where conversion-type-id in BuildCallToObjectOfClassType()
15603 // denotes the type "pointer to function of (P1,...,Pn) returning in BuildCallToObjectOfClassType()
15604 // R", or the type "reference to pointer to function of in BuildCallToObjectOfClassType()
15606 // of (P1,...,Pn) returning R", a surrogate call function [...] in BuildCallToObjectOfClassType()
15608 // surrogate call functions are added to the set of candidate in BuildCallToObjectOfClassType()
15609 // functions for each conversion function declared in an in BuildCallToObjectOfClassType()
15613 cast<CXXRecordDecl>(Record->getDecl())->getVisibleConversionFunctions(); in BuildCallToObjectOfClassType()
15614 for (auto I = Conversions.begin(), E = Conversions.end(); in BuildCallToObjectOfClassType()
15617 CXXRecordDecl *ActingContext = cast<CXXRecordDecl>(D->getDeclContext()); in BuildCallToObjectOfClassType()
15619 D = cast<UsingShadowDecl>(D)->getTargetDecl(); in BuildCallToObjectOfClassType()
15621 // Skip over templated conversion functions; they aren't in BuildCallToObjectOfClassType()
15627 if (!Conv->isExplicit()) { in BuildCallToObjectOfClassType()
15630 QualType ConvType = Conv->getConversionType().getNonReferenceType(); in BuildCallToObjectOfClassType()
15631 if (const PointerType *ConvPtrType = ConvType->getAs<PointerType>()) in BuildCallToObjectOfClassType()
15632 ConvType = ConvPtrType->getPointeeType(); in BuildCallToObjectOfClassType()
15634 if (const FunctionProtoType *Proto = ConvType->getAs<FunctionProtoType>()) in BuildCallToObjectOfClassType()
15646 switch (CandidateSet.BestViableFunction(*this, Object.get()->getBeginLoc(), in BuildCallToObjectOfClassType()
15657 << Object.get()->getType() << /*call*/ 1 in BuildCallToObjectOfClassType()
15658 << Object.get()->getSourceRange()) in BuildCallToObjectOfClassType()
15660 << Object.get()->getType() << Object.get()->getSourceRange()); in BuildCallToObjectOfClassType()
15662 PartialDiagnosticAt(Object.get()->getBeginLoc(), PD), *this, in BuildCallToObjectOfClassType()
15669 PartialDiagnosticAt(Object.get()->getBeginLoc(), in BuildCallToObjectOfClassType()
15671 << Object.get()->getType() in BuildCallToObjectOfClassType()
15672 << Object.get()->getSourceRange()), in BuildCallToObjectOfClassType()
15680 StringLiteral *Msg = Best->Function->getDeletedMessage(); in BuildCallToObjectOfClassType()
15682 PartialDiagnosticAt(Object.get()->getBeginLoc(), in BuildCallToObjectOfClassType()
15684 << Object.get()->getType() << (Msg != nullptr) in BuildCallToObjectOfClassType()
15685 << (Msg ? Msg->getString() : StringRef()) in BuildCallToObjectOfClassType()
15686 << Object.get()->getSourceRange()), in BuildCallToObjectOfClassType()
15692 if (Best == CandidateSet.end()) in BuildCallToObjectOfClassType()
15697 if (Best->Function == nullptr) { in BuildCallToObjectOfClassType()
15698 // Since there is no function declaration, this is one of the in BuildCallToObjectOfClassType()
15699 // surrogate candidates. Dig out the conversion function. in BuildCallToObjectOfClassType()
15702 Best->Conversions[0].UserDefined.ConversionFunction); in BuildCallToObjectOfClassType()
15705 Best->FoundDecl); in BuildCallToObjectOfClassType()
15706 if (DiagnoseUseOfDecl(Best->FoundDecl, LParenLoc)) in BuildCallToObjectOfClassType()
15708 assert(Conv == Best->FoundDecl.getDecl() && in BuildCallToObjectOfClassType()
15709 "Found Decl & conversion-to-functionptr should be same, right?!"); in BuildCallToObjectOfClassType()
15710 // We selected one of the surrogate functions that converts the in BuildCallToObjectOfClassType()
15711 // object parameter to a function pointer. Perform the conversion in BuildCallToObjectOfClassType()
15714 // Create an implicit member expr to refer to the conversion operator. in BuildCallToObjectOfClassType()
15716 ExprResult Call = BuildCXXMemberCallExpr(Object.get(), Best->FoundDecl, in BuildCallToObjectOfClassType()
15720 // Record usage of conversion in an implicit cast. in BuildCallToObjectOfClassType()
15722 Context, Call.get()->getType(), CK_UserDefinedConversion, Call.get(), in BuildCallToObjectOfClassType()
15728 CheckMemberOperatorAccess(LParenLoc, Object.get(), nullptr, Best->FoundDecl); in BuildCallToObjectOfClassType()
15733 CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function); in BuildCallToObjectOfClassType()
15736 if (Method->isInvalidDecl()) in BuildCallToObjectOfClassType()
15739 const auto *Proto = Method->getType()->castAs<FunctionProtoType>(); in BuildCallToObjectOfClassType()
15740 unsigned NumParams = Proto->getNumParams(); in BuildCallToObjectOfClassType()
15745 ExprResult NewFn = CreateFunctionRefExpr(*this, Method, Best->FoundDecl, in BuildCallToObjectOfClassType()
15759 if (Method->isExplicitObjectMemberFunction()) { in BuildCallToObjectOfClassType()
15763 Object.get(), /*Qualifier=*/nullptr, Best->FoundDecl, Method); in BuildCallToObjectOfClassType()
15775 if (Proto->isVariadic()) { in BuildCallToObjectOfClassType()
15790 // Once we've built TheCall, all of the expressions are properly owned. in BuildCallToObjectOfClassType()
15791 QualType ResultTy = Method->getReturnType(); in BuildCallToObjectOfClassType()
15799 if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method)) in BuildCallToObjectOfClassType()
15811 assert(Base->getType()->isRecordType() && in BuildOverloadedArrowExpr()
15812 "left-hand side must have class type"); in BuildOverloadedArrowExpr()
15817 SourceLocation Loc = Base->getExprLoc(); in BuildOverloadedArrowExpr()
15821 // [...] An expression x->m is interpreted as (x.operator->())->m in BuildOverloadedArrowExpr()
15822 // for a class object x of type T if T::operator->() exists and if in BuildOverloadedArrowExpr()
15829 if (RequireCompleteType(Loc, Base->getType(), in BuildOverloadedArrowExpr()
15834 LookupQualifiedName(R, Base->getType()->castAs<RecordType>()->getDecl()); in BuildOverloadedArrowExpr()
15837 for (LookupResult::iterator Oper = R.begin(), OperEnd = R.end(); in BuildOverloadedArrowExpr()
15839 AddMethodCandidate(Oper.getPair(), Base->getType(), Base->Classify(Context), in BuildOverloadedArrowExpr()
15856 QualType BaseType = Base->getType(); in BuildOverloadedArrowExpr()
15858 // Report this specific error to the caller instead of emitting a in BuildOverloadedArrowExpr()
15864 << BaseType << Base->getSourceRange(); in BuildOverloadedArrowExpr()
15865 if (BaseType->isRecordType() && !BaseType->isPointerType()) { in BuildOverloadedArrowExpr()
15871 << "operator->" << Base->getSourceRange(); in BuildOverloadedArrowExpr()
15879 << "->" << Base->getType() in BuildOverloadedArrowExpr()
15880 << Base->getSourceRange()), in BuildOverloadedArrowExpr()
15885 StringLiteral *Msg = Best->Function->getDeletedMessage(); in BuildOverloadedArrowExpr()
15888 << "->" << (Msg != nullptr) in BuildOverloadedArrowExpr()
15889 << (Msg ? Msg->getString() : StringRef()) in BuildOverloadedArrowExpr()
15890 << Base->getSourceRange()), in BuildOverloadedArrowExpr()
15896 CheckMemberOperatorAccess(OpLoc, Base, nullptr, Best->FoundDecl); in BuildOverloadedArrowExpr()
15899 CXXMethodDecl *Method = cast<CXXMethodDecl>(Best->Function); in BuildOverloadedArrowExpr()
15901 if (Method->isExplicitObjectMemberFunction()) { in BuildOverloadedArrowExpr()
15908 Base, /*Qualifier=*/nullptr, Best->FoundDecl, Method); in BuildOverloadedArrowExpr()
15915 ExprResult FnExpr = CreateFunctionRefExpr(*this, Method, Best->FoundDecl, in BuildOverloadedArrowExpr()
15920 QualType ResultTy = Method->getReturnType(); in BuildOverloadedArrowExpr()
15928 if (CheckCallReturnType(Method->getReturnType(), OpLoc, TheCall, Method)) in BuildOverloadedArrowExpr()
15932 Method->getType()->castAs<FunctionProtoType>())) in BuildOverloadedArrowExpr()
15976 FunctionDecl *FD = Best->Function; in BuildLiteralOperatorCall()
15977 ExprResult Fn = CreateFunctionRefExpr(*this, FD, Best->FoundDecl, in BuildLiteralOperatorCall()
15984 // Check the argument types. This should almost always be a no-op, except in BuildLiteralOperatorCall()
15985 // that array-to-pointer decay is applied to string literals. in BuildLiteralOperatorCall()
15989 InitializedEntity::InitializeParameter(Context, FD->getParamDecl(ArgIdx)), in BuildLiteralOperatorCall()
15996 QualType ResultTy = FD->getReturnType(); in BuildLiteralOperatorCall()
16004 if (CheckCallReturnType(FD->getReturnType(), UDSuffixLoc, UDL, FD)) in BuildLiteralOperatorCall()
16022 CandidateSet->clear(OverloadCandidateSet::CSK_Normal); in BuildForRangeBeginEndCall()
16025 BuildMemberReferenceExpr(Range, Range->getType(), Loc, in BuildForRangeBeginEndCall()
16037 if (CallExpr->isInvalid()) { in BuildForRangeBeginEndCall()
16051 if (CandidateSet->empty() || CandidateSetError) { in BuildForRangeBeginEndCall()
16057 CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best); in BuildForRangeBeginEndCall()
16067 if (CallExpr->isInvalid() || OverloadResult != OR_Success) { in BuildForRangeBeginEndCall()
16079 FixOverloadedFunctionReference(PE->getSubExpr(), Found, Fn); in FixOverloadedFunctionReference()
16082 if (SubExpr.get() == PE->getSubExpr()) in FixOverloadedFunctionReference()
16086 ParenExpr(PE->getLParen(), PE->getRParen(), SubExpr.get()); in FixOverloadedFunctionReference()
16091 FixOverloadedFunctionReference(ICE->getSubExpr(), Found, Fn); in FixOverloadedFunctionReference()
16094 assert(Context.hasSameType(ICE->getSubExpr()->getType(), in FixOverloadedFunctionReference()
16095 SubExpr.get()->getType()) && in FixOverloadedFunctionReference()
16097 assert(ICE->path_empty() && "fixing up hierarchy conversion?"); in FixOverloadedFunctionReference()
16098 if (SubExpr.get() == ICE->getSubExpr()) in FixOverloadedFunctionReference()
16101 return ImplicitCastExpr::Create(Context, ICE->getType(), ICE->getCastKind(), in FixOverloadedFunctionReference()
16102 SubExpr.get(), nullptr, ICE->getValueKind(), in FixOverloadedFunctionReference()
16107 if (!GSE->isResultDependent()) { in FixOverloadedFunctionReference()
16109 FixOverloadedFunctionReference(GSE->getResultExpr(), Found, Fn); in FixOverloadedFunctionReference()
16112 if (SubExpr.get() == GSE->getResultExpr()) in FixOverloadedFunctionReference()
16117 ArrayRef<Expr *> A = GSE->getAssocExprs(); in FixOverloadedFunctionReference()
16118 SmallVector<Expr *, 4> AssocExprs(A.begin(), A.end()); in FixOverloadedFunctionReference()
16119 unsigned ResultIdx = GSE->getResultIndex(); in FixOverloadedFunctionReference()
16122 if (GSE->isExprPredicate()) in FixOverloadedFunctionReference()
16124 Context, GSE->getGenericLoc(), GSE->getControllingExpr(), in FixOverloadedFunctionReference()
16125 GSE->getAssocTypeSourceInfos(), AssocExprs, GSE->getDefaultLoc(), in FixOverloadedFunctionReference()
16126 GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), in FixOverloadedFunctionReference()
16129 Context, GSE->getGenericLoc(), GSE->getControllingType(), in FixOverloadedFunctionReference()
16130 GSE->getAssocTypeSourceInfos(), AssocExprs, GSE->getDefaultLoc(), in FixOverloadedFunctionReference()
16131 GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), in FixOverloadedFunctionReference()
16140 assert(UnOp->getOpcode() == UO_AddrOf && in FixOverloadedFunctionReference()
16141 "Can only take the address of an overloaded function"); in FixOverloadedFunctionReference()
16143 if (!Method->isImplicitObjectMemberFunction()) { in FixOverloadedFunctionReference()
16144 // Do nothing: the address of static and in FixOverloadedFunctionReference()
16145 // explicit object member functions is a (non-member) function pointer. in FixOverloadedFunctionReference()
16151 FixOverloadedFunctionReference(UnOp->getSubExpr(), Found, Fn); in FixOverloadedFunctionReference()
16154 if (SubExpr.get() == UnOp->getSubExpr()) in FixOverloadedFunctionReference()
16157 if (CheckUseOfCXXMethodAsAddressOfOperand(UnOp->getBeginLoc(), in FixOverloadedFunctionReference()
16163 assert(cast<DeclRefExpr>(SubExpr.get())->getQualifier() && in FixOverloadedFunctionReference()
16166 // We have taken the address of a pointer to member in FixOverloadedFunctionReference()
16170 = Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext())); in FixOverloadedFunctionReference()
16172 = Context.getMemberPointerType(Fn->getType(), ClassType.getTypePtr()); in FixOverloadedFunctionReference()
16175 (void)isCompleteType(UnOp->getOperatorLoc(), MemPtrType); in FixOverloadedFunctionReference()
16179 UnOp->getOperatorLoc(), false, in FixOverloadedFunctionReference()
16184 FixOverloadedFunctionReference(UnOp->getSubExpr(), Found, Fn); in FixOverloadedFunctionReference()
16187 if (SubExpr.get() == UnOp->getSubExpr()) in FixOverloadedFunctionReference()
16190 return CreateBuiltinUnaryOp(UnOp->getOperatorLoc(), UO_AddrOf, in FixOverloadedFunctionReference()
16197 if (ULE->hasExplicitTemplateArgs()) { in FixOverloadedFunctionReference()
16198 ULE->copyTemplateArgumentsInto(TemplateArgsBuffer); in FixOverloadedFunctionReference()
16202 QualType Type = Fn->getType(); in FixOverloadedFunctionReference()
16204 getLangOpts().CPlusPlus && !Fn->hasCXXExplicitFunctionObjectParameter() in FixOverloadedFunctionReference()
16209 if (unsigned BID = Fn->getBuiltinID()) { in FixOverloadedFunctionReference()
16217 Fn, Type, ValueKind, ULE->getNameInfo(), ULE->getQualifierLoc(), in FixOverloadedFunctionReference()
16218 Found.getDecl(), ULE->getTemplateKeywordLoc(), TemplateArgs); in FixOverloadedFunctionReference()
16219 DRE->setHadMultipleCandidates(ULE->getNumDecls() > 1); in FixOverloadedFunctionReference()
16226 if (MemExpr->hasExplicitTemplateArgs()) { in FixOverloadedFunctionReference()
16227 MemExpr->copyTemplateArgumentsInto(TemplateArgsBuffer); in FixOverloadedFunctionReference()
16235 if (MemExpr->isImplicitAccess()) { in FixOverloadedFunctionReference()
16236 if (cast<CXXMethodDecl>(Fn)->isStatic()) { in FixOverloadedFunctionReference()
16238 Fn, Fn->getType(), VK_LValue, MemExpr->getNameInfo(), in FixOverloadedFunctionReference()
16239 MemExpr->getQualifierLoc(), Found.getDecl(), in FixOverloadedFunctionReference()
16240 MemExpr->getTemplateKeywordLoc(), TemplateArgs); in FixOverloadedFunctionReference()
16241 DRE->setHadMultipleCandidates(MemExpr->getNumDecls() > 1); in FixOverloadedFunctionReference()
16244 SourceLocation Loc = MemExpr->getMemberLoc(); in FixOverloadedFunctionReference()
16245 if (MemExpr->getQualifier()) in FixOverloadedFunctionReference()
16246 Loc = MemExpr->getQualifierLoc().getBeginLoc(); in FixOverloadedFunctionReference()
16248 BuildCXXThisExpr(Loc, MemExpr->getBaseType(), /*IsImplicit=*/true); in FixOverloadedFunctionReference()
16251 Base = MemExpr->getBase(); in FixOverloadedFunctionReference()
16255 if (cast<CXXMethodDecl>(Fn)->isStatic()) { in FixOverloadedFunctionReference()
16257 type = Fn->getType(); in FixOverloadedFunctionReference()
16264 Base, MemExpr->isArrow(), MemExpr->getOperatorLoc(), in FixOverloadedFunctionReference()
16265 MemExpr->getQualifierLoc(), MemExpr->getTemplateKeywordLoc(), Fn, Found, in FixOverloadedFunctionReference()
16266 /*HadMultipleCandidates=*/true, MemExpr->getMemberNameInfo(), in FixOverloadedFunctionReference()
16283 if (Function->isVariadic()) in shouldEnforceArgLimit()
16286 dyn_cast<FunctionProtoType>(Function->getFunctionType())) in shouldEnforceArgLimit()
16287 if (Proto->isTemplateVariadic()) in shouldEnforceArgLimit()
16289 if (auto *Pattern = Function->getTemplateInstantiationPattern()) in shouldEnforceArgLimit()
16291 dyn_cast<FunctionProtoType>(Pattern->getFunctionType())) in shouldEnforceArgLimit()
16292 if (Proto->isTemplateVariadic()) in shouldEnforceArgLimit()
16302 StringLiteral *Msg = Fn->getDeletedMessage(); in DiagnoseUseOfDeletedFunction()
16306 << (Msg ? Msg->getString() : StringRef()) in DiagnoseUseOfDeletedFunction()