30 #include "llvm/ADT/DenseSet.h" 31 #include "llvm/ADT/Optional.h" 32 #include "llvm/ADT/STLExtras.h" 33 #include "llvm/ADT/SmallPtrSet.h" 34 #include "llvm/ADT/SmallString.h" 38 using namespace clang;
43 return P->hasAttr<PassObjectSizeAttr>();
50 const Expr *
Base,
bool HadMultipleCandidates,
67 if (HadMultipleCandidates)
72 CK_FunctionToPointerDecay);
76 bool InOverloadResolution,
79 bool AllowObjCWritebackConversion);
83 bool InOverloadResolution,
91 bool AllowObjCConversionOnExplicit);
144 return Rank[(int)Kind];
154 "Function-to-pointer",
155 "Function pointer conversion",
157 "Integral promotion",
158 "Floating point promotion",
160 "Integral conversion",
161 "Floating conversion",
162 "Complex conversion",
163 "Floating-integral conversion",
164 "Pointer conversion",
165 "Pointer-to-member conversion",
166 "Boolean conversion",
167 "Compatible-types conversion",
168 "Derived-to-base conversion",
171 "Complex-real conversion",
172 "Block Pointer conversion",
173 "Transparent Union Conversion",
174 "Writeback conversion",
175 "OpenCL Zero Event Conversion",
176 "C specific type conversion",
177 "Incompatible pointer conversion" 188 DeprecatedStringLiteralToCharPtr =
false;
189 QualificationIncludesObjCLifetime =
false;
190 ReferenceBinding =
false;
191 DirectBinding =
false;
192 IsLvalueReference =
true;
193 BindsToFunctionLvalue =
false;
194 BindsToRvalue =
false;
195 BindsImplicitObjectArgumentWithoutRefQualifier =
false;
196 ObjCLifetimeConversionBinding =
false;
197 CopyConstructor =
nullptr;
224 (getFromType()->isPointerType() ||
225 getFromType()->isMemberPointerType() ||
226 getFromType()->isObjCObjectPointerType() ||
227 getFromType()->isBlockPointerType() ||
228 getFromType()->isNullPtrType() ||
261 while (
const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Converted)) {
262 switch (ICE->getCastKind()) {
264 case CK_IntegralCast:
265 case CK_IntegralToBoolean:
266 case CK_IntegralToFloating:
267 case CK_BooleanToSignedIntegral:
268 case CK_FloatingToIntegral:
269 case CK_FloatingToBoolean:
270 case CK_FloatingCast:
271 Converted = ICE->getSubExpr();
295 QualType &ConstantType,
bool IgnoreFloatToIntegralConversion)
const {
296 assert(Ctx.
getLangOpts().CPlusPlus &&
"narrowing check outside C++");
307 ToType = ET->getDecl()->getIntegerType();
312 if (FromType->isRealFloatingType())
313 goto FloatingIntegralConversion;
314 if (FromType->isIntegralOrUnscopedEnumerationType())
315 goto IntegralConversion;
327 FloatingIntegralConversion:
328 if (FromType->isRealFloatingType() && ToType->
isIntegralType(Ctx)) {
330 }
else if (FromType->isIntegralOrUnscopedEnumerationType() &&
332 if (IgnoreFloatToIntegralConversion)
334 llvm::APSInt IntConstantValue;
336 assert(Initializer &&
"Unknown conversion expression");
345 Result.convertFromAPInt(IntConstantValue, IntConstantValue.isSigned(),
346 llvm::APFloat::rmNearestTiesToEven);
348 llvm::APSInt ConvertedValue = IntConstantValue;
350 Result.convertToInteger(ConvertedValue,
351 llvm::APFloat::rmTowardZero, &ignored);
353 if (IntConstantValue != ConvertedValue) {
354 ConstantValue =
APValue(IntConstantValue);
355 ConstantType = Initializer->
getType();
381 assert(ConstantValue.
isFloat());
382 llvm::APFloat FloatVal = ConstantValue.
getFloat();
385 llvm::APFloat::opStatus ConvertStatus = FloatVal.convert(
387 llvm::APFloat::rmNearestTiesToEven, &ignored);
390 if (ConvertStatus & llvm::APFloat::opOverflow) {
391 ConstantType = Initializer->
getType();
406 IntegralConversion: {
407 assert(FromType->isIntegralOrUnscopedEnumerationType());
409 const bool FromSigned = FromType->isSignedIntegerOrEnumerationType();
410 const unsigned FromWidth = Ctx.
getIntWidth(FromType);
414 if (FromWidth > ToWidth ||
415 (FromWidth == ToWidth && FromSigned != ToSigned) ||
416 (FromSigned && !ToSigned)) {
418 llvm::APSInt InitializerValue;
429 bool Narrowing =
false;
430 if (FromWidth < ToWidth) {
433 if (InitializerValue.isSigned() && InitializerValue.isNegative())
438 InitializerValue = InitializerValue.extend(
439 InitializerValue.getBitWidth() + 1);
441 llvm::APSInt ConvertedValue = InitializerValue;
442 ConvertedValue = ConvertedValue.trunc(ToWidth);
443 ConvertedValue.setIsSigned(ToSigned);
444 ConvertedValue = ConvertedValue.extend(InitializerValue.getBitWidth());
445 ConvertedValue.setIsSigned(InitializerValue.isSigned());
447 if (ConvertedValue != InitializerValue)
451 ConstantType = Initializer->
getType();
452 ConstantValue =
APValue(InitializerValue);
468 raw_ostream &OS = llvm::errs();
469 bool PrintedSomething =
false;
472 PrintedSomething =
true;
476 if (PrintedSomething) {
481 if (CopyConstructor) {
482 OS <<
" (by copy constructor)";
483 }
else if (DirectBinding) {
484 OS <<
" (direct reference binding)";
485 }
else if (ReferenceBinding) {
486 OS <<
" (reference binding)";
488 PrintedSomething =
true;
492 if (PrintedSomething) {
496 PrintedSomething =
true;
499 if (!PrintedSomething) {
500 OS <<
"No conversions required";
507 raw_ostream &OS = llvm::errs();
508 if (Before.First || Before.Second || Before.Third) {
512 if (ConversionFunction)
513 OS <<
'\'' << *ConversionFunction <<
'\'';
515 OS <<
"aggregate initialization";
525 raw_ostream &OS = llvm::errs();
526 if (isStdInitializerListElement())
527 OS <<
"Worst std::initializer_list element conversion: ";
528 switch (ConversionKind) {
529 case StandardConversion:
530 OS <<
"Standard conversion: ";
533 case UserDefinedConversion:
534 OS <<
"User-defined conversion: ";
537 case EllipsisConversion:
538 OS <<
"Ellipsis conversion";
540 case AmbiguousConversion:
541 OS <<
"Ambiguous conversion";
544 OS <<
"Bad conversion";
556 conversions().~ConversionSet();
569 struct DFIArguments {
575 struct DFIParamWithArguments : DFIArguments {
580 struct DFIDeducedMismatchArgs : DFIArguments {
582 unsigned CallArgIndex;
593 Result.
Result =
static_cast<unsigned>(TDK);
602 Result.
Data =
nullptr;
607 Result.
Data = Info.
Param.getOpaqueValue();
613 auto *Saved =
new (Context) DFIDeducedMismatchArgs;
616 Saved->TemplateArgs = Info.
take();
624 DFIArguments *Saved =
new (Context) DFIArguments;
636 DFIParamWithArguments *Saved =
new (Context) DFIParamWithArguments;
637 Saved->Param = Info.
Param;
656 llvm_unreachable(
"not a deduction failure");
663 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
689 Diag->~PartialDiagnosticAt();
690 HasDiagnostic =
false;
707 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
723 return TemplateParameter::getFromOpaqueValue(Data);
728 return static_cast<DFIParamWithArguments*
>(Data)->Param;
739 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
757 return static_cast<DFIDeducedMismatchArgs*
>(Data)->TemplateArgs;
771 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
790 return &
static_cast<DFIArguments*
>(Data)->FirstArg;
801 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
820 return &
static_cast<DFIArguments*
>(Data)->SecondArg;
831 switch (static_cast<Sema::TemplateDeductionResult>(Result)) {
834 return static_cast<DFIDeducedMismatchArgs*
>(Data)->CallArgIndex;
841 void OverloadCandidateSet::destroyCandidates() {
842 for (iterator i = begin(), e = end(); i != e; ++i) {
843 for (
auto &C : i->Conversions)
844 C.~ImplicitConversionSequence();
846 i->DeductionFailure.Destroy();
852 SlabAllocator.Reset();
853 NumInlineBytesUsed = 0;
860 class UnbridgedCastsSet {
870 Entry entry = { &E, E };
871 Entries.push_back(entry);
877 i = Entries.begin(), e = Entries.end(); i != e; ++i)
892 UnbridgedCastsSet *unbridgedCasts =
nullptr) {
896 if (placeholder->getKind() == BuiltinType::Overload)
return false;
900 if (placeholder->getKind() == BuiltinType::ARCUnbridgedCast &&
902 unbridgedCasts->save(S, E);
923 UnbridgedCastsSet &unbridged) {
924 for (
unsigned i = 0, e = Args.size(); i != e; ++i)
966 NamedDecl *&Match,
bool NewIsUsingDecl) {
971 bool OldIsUsingDecl =
false;
972 if (isa<UsingShadowDecl>(OldD)) {
973 OldIsUsingDecl =
true;
977 if (NewIsUsingDecl)
continue;
979 OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl();
984 if ((OldIsUsingDecl || NewIsUsingDecl) && !isVisible(*I))
992 bool UseMemberUsingDeclRules =
993 (OldIsUsingDecl || NewIsUsingDecl) && CurContext->isRecord() &&
997 if (!IsOverload(New, OldF, UseMemberUsingDeclRules)) {
998 if (UseMemberUsingDeclRules && OldIsUsingDecl) {
999 HideUsingShadowDecl(S, cast<UsingShadowDecl>(*I));
1003 if (!isa<FunctionTemplateDecl>(OldD) &&
1004 !shouldLinkPossiblyHiddenDecl(*I, New))
1013 if (!getASTContext().canBuiltinBeRedeclared(OldF)) {
1015 return Ovl_NonFunction;
1017 }
else if (isa<UsingDecl>(OldD) || isa<UsingPackDecl>(OldD)) {
1021 }
else if (isa<TagDecl>(OldD)) {
1023 }
else if (
auto *UUD = dyn_cast<UnresolvedUsingValueDecl>(OldD)) {
1030 if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) {
1032 return Ovl_NonFunction;
1039 return Ovl_NonFunction;
1063 if (CheckFunctionTemplateSpecialization(New,
nullptr, TemplateSpecResult,
1066 return Ovl_Overload;
1073 return Ovl_Overload;
1077 bool UseMemberUsingDeclRules,
bool ConsiderCudaAttrs) {
1092 if ((OldTemplate ==
nullptr) != (NewTemplate ==
nullptr))
1105 if (isa<FunctionNoProtoType>(OldQType.
getTypePtr()) ||
1106 isa<FunctionNoProtoType>(NewQType.
getTypePtr()))
1115 if (OldQType != NewQType &&
1117 OldType->
isVariadic() != NewType->isVariadic() ||
1118 !FunctionParamTypesAreEqual(OldType, NewType)))
1133 if (!UseMemberUsingDeclRules && NewTemplate &&
1136 false, TPL_TemplateMatch) ||
1151 if (OldMethod && NewMethod &&
1152 !OldMethod->
isStatic() && !NewMethod->isStatic()) {
1154 if (!UseMemberUsingDeclRules &&
1156 NewMethod->getRefQualifier() ==
RQ_None)) {
1163 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
1175 auto NewQuals = NewMethod->getMethodQualifiers();
1176 if (!getLangOpts().
CPlusPlus14 && NewMethod->isConstexpr() &&
1177 !isa<CXXConstructorDecl>(NewMethod))
1180 OldQuals.removeRestrict();
1181 NewQuals.removeRestrict();
1182 if (OldQuals != NewQuals)
1200 NewI != NewE || OldI != OldE; ++NewI, ++OldI) {
1201 if (NewI == NewE || OldI == OldE)
1203 llvm::FoldingSetNodeID NewID, OldID;
1204 NewI->getCond()->Profile(NewID, Context,
true);
1205 OldI->getCond()->Profile(OldID, Context,
true);
1210 if (getLangOpts().CUDA && ConsiderCudaAttrs) {
1213 if (isa<CXXDestructorDecl>(New))
1217 OldTarget = IdentifyCUDATarget(Old);
1218 if (NewTarget == CFT_InvalidTarget)
1221 assert((OldTarget != CFT_InvalidTarget) &&
"Unexpected invalid target.");
1225 return NewTarget != OldTarget;
1242 Decl *C = cast<Decl>(CurContext);
1256 bool SuppressUserConversions,
1258 bool InOverloadResolution,
1260 bool AllowObjCWritebackConversion,
1261 bool AllowObjCConversionOnExplicit) {
1264 if (SuppressUserConversions) {
1275 Conversions, AllowExplicit,
1276 AllowObjCConversionOnExplicit)) {
1293 if (Constructor->isCopyConstructor() &&
1294 (FromCanon == ToCanon ||
1305 if (ToCanon != FromCanon)
1316 Cand != Conversions.
end(); ++Cand)
1359 bool SuppressUserConversions,
1361 bool InOverloadResolution,
1363 bool AllowObjCWritebackConversion,
1364 bool AllowObjCConversionOnExplicit) {
1367 ICS.
Standard, CStyle, AllowObjCWritebackConversion)){
1407 AllowExplicit, InOverloadResolution, CStyle,
1408 AllowObjCWritebackConversion,
1409 AllowObjCConversionOnExplicit);
1414 bool SuppressUserConversions,
1416 bool InOverloadResolution,
1418 bool AllowObjCWritebackConversion) {
1420 SuppressUserConversions, AllowExplicit,
1421 InOverloadResolution, CStyle,
1422 AllowObjCWritebackConversion,
1435 return PerformImplicitConversion(From, ToType, Action, AllowExplicit, ICS);
1446 bool AllowObjCWritebackConversion
1447 = getLangOpts().ObjCAutoRefCount &&
1448 (Action == AA_Passing || Action == AA_Sending);
1449 if (getLangOpts().ObjC)
1450 CheckObjCBridgeRelatedConversions(From->
getBeginLoc(), ToType,
1457 AllowObjCWritebackConversion,
1459 return PerformImplicitConversion(From, ToType, ICS, Action);
1480 if (TyClass != CanFrom->getTypeClass())
return false;
1481 if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto) {
1482 if (TyClass == Type::Pointer) {
1485 }
else if (TyClass == Type::BlockPointer) {
1488 }
else if (TyClass == Type::MemberPointer) {
1492 if (ToMPT->getClass() != FromMPT->
getClass())
1494 CanTo = ToMPT->getPointeeType();
1500 TyClass = CanTo->getTypeClass();
1501 if (TyClass != CanFrom->getTypeClass())
return false;
1502 if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto)
1506 const auto *FromFn = cast<FunctionType>(CanFrom);
1509 const auto *ToFn = cast<FunctionType>(CanTo);
1512 bool Changed =
false;
1515 if (FromEInfo.getNoReturn() && !ToEInfo.getNoReturn()) {
1521 if (
const auto *FromFPT = dyn_cast<FunctionProtoType>(FromFn)) {
1522 const auto *ToFPT = cast<FunctionProtoType>(ToFn);
1523 if (FromFPT->isNothrow() && !ToFPT->isNothrow()) {
1524 FromFn = cast<FunctionType>(
1535 bool CanUseToFPT, CanUseFromFPT;
1537 CanUseFromFPT, NewParamInfos) &&
1538 CanUseToFPT && !CanUseFromFPT) {
1541 NewParamInfos.empty() ? nullptr : NewParamInfos.data();
1543 FromFPT->getParamTypes(), ExtInfo);
1552 assert(
QualType(FromFn, 0).isCanonical());
1553 if (
QualType(FromFn, 0) != CanTo)
return false;
1605 bool InOverloadResolution,
1618 bool InOverloadResolution,
1621 bool AllowObjCWritebackConversion) {
1668 if (Method && !Method->
isStatic()) {
1670 "Non-unary operator on non-static member address");
1673 "Non-address-of operator on non-static member address");
1674 const Type *ClassType
1680 "Non-address-of operator for overloaded function expression");
1707 FromType = Atomic->getValueType();
1742 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
1762 bool IncompatibleObjC =
false;
1813 if (Float128AndLongDouble &&
1815 &llvm::APFloat::PPCDoubleDouble()))
1830 }
else if (AllowObjCWritebackConversion &&
1834 FromType, IncompatibleObjC)) {
1840 InOverloadResolution, FromType)) {
1852 InOverloadResolution,
1879 bool ObjCLifetimeConversion;
1885 ObjCLifetimeConversion)) {
1904 CanonFrom = CanonTo;
1909 if (CanonFrom == CanonTo)
1914 if (S.
getLangOpts().CPlusPlus || !InOverloadResolution)
1958 bool InOverloadResolution,
1968 for (
const auto *it : UD->
fields()) {
1971 ToType = it->getType();
2001 return To->
getKind() == BuiltinType::Int;
2004 return To->
getKind() == BuiltinType::UInt;
2028 if (FromEnumType->getDecl()->isScoped())
2035 if (FromEnumType->getDecl()->isFixed()) {
2036 QualType Underlying = FromEnumType->getDecl()->getIntegerType();
2038 IsIntegralPromotion(
nullptr, Underlying, ToType);
2045 ToType, FromEnumType->getDecl()->getPromotionType());
2052 if (getLangOpts().CPlusPlus)
2070 uint64_t FromSize = Context.
getTypeSize(FromType);
2079 for (
int Idx = 0; Idx < 6; ++Idx) {
2080 uint64_t ToSize = Context.
getTypeSize(PromoteTypes[Idx]);
2081 if (FromSize < ToSize ||
2082 (FromSize == ToSize &&
2083 FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) {
2108 llvm::APSInt BitWidth;
2110 MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) {
2111 llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
2115 if (BitWidth < ToSize ||
2117 return To->
getKind() == BuiltinType::Int;
2123 return To->
getKind() == BuiltinType::UInt;
2148 if (FromBuiltin->getKind() == BuiltinType::Float &&
2149 ToBuiltin->getKind() == BuiltinType::Double)
2155 if (!getLangOpts().CPlusPlus &&
2156 (FromBuiltin->getKind() == BuiltinType::Float ||
2157 FromBuiltin->getKind() == BuiltinType::Double) &&
2158 (ToBuiltin->getKind() == BuiltinType::LongDouble ||
2159 ToBuiltin->getKind() == BuiltinType::Float128))
2163 if (!getLangOpts().NativeHalfType &&
2164 FromBuiltin->getKind() == BuiltinType::Half &&
2165 ToBuiltin->getKind() == BuiltinType::Float)
2202 bool StripObjCLifetime =
false) {
2205 "Invalid similarly-qualified pointer type");
2216 if (StripObjCLifetime)
2227 if (isa<ObjCObjectPointerType>(ToType))
2236 if (isa<ObjCObjectPointerType>(ToType))
2242 bool InOverloadResolution,
2248 return !InOverloadResolution;
2272 bool InOverloadResolution,
2274 bool &IncompatibleObjC) {
2275 IncompatibleObjC =
false;
2276 if (isObjCPointerConversion(FromType, ToType, ConvertedType,
2283 ConvertedType = ToType;
2290 ConvertedType = ToType;
2297 ConvertedType = ToType;
2305 ConvertedType = ToType;
2315 ConvertedType = ToType;
2323 !getLangOpts().ObjCAutoRefCount) {
2354 if (getLangOpts().MSVCCompat && FromPointeeType->
isFunctionType() &&
2388 IsDerivedFrom(From->
getBeginLoc(), FromPointeeType, ToPointeeType)) {
2425 bool &IncompatibleObjC) {
2426 if (!getLangOpts().ObjC)
2438 if (ToObjCPtr && FromObjCPtr) {
2449 if (getLangOpts().
CPlusPlus && LHS && RHS &&
2451 FromObjCPtr->getPointeeType()))
2456 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2464 IncompatibleObjC =
true;
2468 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2480 if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) {
2508 isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
2509 IncompatibleObjC)) {
2511 IncompatibleObjC =
true;
2513 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2520 isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
2521 IncompatibleObjC)) {
2524 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2536 if (FromFunctionType && ToFunctionType) {
2545 if (FromFunctionType->
getNumParams() != ToFunctionType->getNumParams() ||
2546 FromFunctionType->
isVariadic() != ToFunctionType->isVariadic() ||
2547 FromFunctionType->
getMethodQuals() != ToFunctionType->getMethodQuals())
2550 bool HasObjCConversion =
false;
2554 }
else if (isObjCPointerConversion(FromFunctionType->
getReturnType(),
2555 ToFunctionType->getReturnType(),
2556 ConvertedType, IncompatibleObjC)) {
2558 HasObjCConversion =
true;
2565 for (
unsigned ArgIdx = 0, NumArgs = FromFunctionType->
getNumParams();
2566 ArgIdx != NumArgs; ++ArgIdx) {
2568 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
2572 }
else if (isObjCPointerConversion(FromArgType, ToArgType,
2573 ConvertedType, IncompatibleObjC)) {
2575 HasObjCConversion =
true;
2582 if (HasObjCConversion) {
2586 IncompatibleObjC =
true;
2605 if (!getLangOpts().ObjCAutoRefCount ||
2647 bool IncompatibleObjC;
2649 FromPointee = ToPointee;
2650 else if (!isObjCPointerConversion(FromPointee, ToPointee, FromPointee,
2685 if (!FromFunctionType || !ToFunctionType)
2688 if (Context.
hasSameType(FromPointeeType, ToPointeeType))
2693 if (FromFunctionType->
getNumParams() != ToFunctionType->getNumParams() ||
2694 FromFunctionType->
isVariadic() != ToFunctionType->isVariadic())
2699 if (FromEInfo != ToEInfo)
2702 bool IncompatibleObjC =
false;
2704 ToFunctionType->getReturnType())) {
2708 QualType LHS = ToFunctionType->getReturnType();
2715 }
else if (isObjCPointerConversion(RHS, LHS,
2716 ConvertedType, IncompatibleObjC)) {
2717 if (IncompatibleObjC)
2726 for (
unsigned ArgIdx = 0, NumArgs = FromFunctionType->
getNumParams();
2727 ArgIdx != NumArgs; ++ArgIdx) {
2728 IncompatibleObjC =
false;
2730 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
2731 if (Context.
hasSameType(FromArgType, ToArgType)) {
2733 }
else if (isObjCPointerConversion(ToArgType, FromArgType,
2734 ConvertedType, IncompatibleObjC)) {
2735 if (IncompatibleObjC)
2744 bool CanUseToFPT, CanUseFromFPT;
2746 CanUseToFPT, CanUseFromFPT,
2750 ConvertedType = ToType;
2826 if (!FromFunction || !ToFunction) {
2831 if (FromFunction->
getNumParams() != ToFunction->getNumParams()) {
2839 if (!FunctionParamTypesAreEqual(FromFunction, ToFunction, &ArgPos)) {
2841 << ToFunction->getParamType(ArgPos)
2848 ToFunction->getReturnType())) {
2854 if (FromFunction->
getMethodQuals() != ToFunction->getMethodQuals()) {
2864 cast<FunctionProtoType>(ToFunction->getCanonicalTypeUnqualified())
2884 O && (O != E); ++O, ++N) {
2886 N->getUnqualifiedType())) {
2904 bool IgnoreBaseAccess,
2907 bool IsCStyleOrFunctionalCast = IgnoreBaseAccess;
2911 if (Diagnose && !IsCStyleOrFunctionalCast && !FromType->
isAnyPointerType() &&
2915 DiagRuntimeBehavior(From->
getExprLoc(), From,
2916 PDiag(diag::warn_impcast_bool_to_null_pointer)
2918 else if (!isUnevaluatedContext())
2927 if (FromPointeeType->
isRecordType() && ToPointeeType->isRecordType() &&
2931 unsigned InaccessibleID = 0;
2932 unsigned AmbigiousID = 0;
2934 InaccessibleID = diag::err_upcast_to_inaccessible_base;
2935 AmbigiousID = diag::err_ambiguous_derived_to_base_conv;
2937 if (CheckDerivedToBaseConversion(
2938 FromPointeeType, ToPointeeType, InaccessibleID, AmbigiousID,
2940 &BasePath, IgnoreBaseAccess))
2944 Kind = CK_DerivedToBase;
2947 if (Diagnose && !IsCStyleOrFunctionalCast &&
2948 FromPointeeType->
isFunctionType() && ToPointeeType->isVoidType()) {
2949 assert(getLangOpts().MSVCCompat &&
2950 "this should only be possible with MSVCCompat!");
2962 if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType())
2965 Kind = CK_BlockPointerToObjCPointerCast;
2967 Kind = CK_CPointerToObjCPointerCast;
2971 Kind = CK_AnyPointerToBlockPointerCast;
2977 Kind = CK_NullToPointer;
2989 bool InOverloadResolution,
2999 ConvertedType = ToType;
3014 IsDerivedFrom(From->
getBeginLoc(), ToClass, FromClass)) {
3032 bool IgnoreBaseAccess) {
3039 "Expr must be null pointer constant!");
3040 Kind = CK_NullToMemberPointer;
3045 assert(ToPtrType &&
"No member pointer cast has a target type " 3046 "that is not a member pointer.");
3052 assert(FromClass->
isRecordType() &&
"Pointer into non-class.");
3053 assert(ToClass->isRecordType() &&
"Pointer into non-class.");
3057 bool DerivationOkay =
3058 IsDerivedFrom(From->
getBeginLoc(), ToClass, FromClass, Paths);
3059 assert(DerivationOkay &&
3060 "Should not have been called if derivation isn't OK.");
3061 (void)DerivationOkay;
3064 getUnqualifiedType())) {
3065 std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
3067 << 0 << FromClass << ToClass << PathDisplayStr << From->
getSourceRange();
3071 if (
const RecordType *VBase = Paths.getDetectedVirtual()) {
3073 << FromClass << ToClass <<
QualType(VBase, 0)
3078 if (!IgnoreBaseAccess)
3079 CheckBaseClassAccess(From->
getExprLoc(), FromClass, ToClass,
3081 diag::err_downcast_from_inaccessible_base);
3085 Kind = CK_BaseToDerivedMemberPointer;
3110 bool CStyle,
bool &ObjCLifetimeConversion) {
3113 ObjCLifetimeConversion =
false;
3123 bool PreviousToQualsIncludeConst =
true;
3124 bool UnwrappedAnyPointer =
false;
3132 UnwrappedAnyPointer =
true;
3144 UnwrappedAnyPointer) {
3147 ObjCLifetimeConversion =
true;
3172 && !PreviousToQualsIncludeConst)
3177 PreviousToQualsIncludeConst
3178 = PreviousToQualsIncludeConst && ToQuals.
hasConst();
3204 bool InOverloadResolution,
3213 InOverloadResolution, InnerSCS,
3217 SCS.
Second = InnerSCS.Second;
3218 SCS.
setToType(1, InnerSCS.getToType(1));
3219 SCS.
Third = InnerSCS.Third;
3221 = InnerSCS.QualificationIncludesObjCLifetime;
3222 SCS.
setToType(2, InnerSCS.getToType(2));
3244 bool AllowExplicit) {
3251 bool Usable = !Info.Constructor->isInvalidDecl() &&
3253 (AllowExplicit || !Info.Constructor->isExplicit());
3258 S.
Context, Info.Constructor, ToType);
3259 if (Info.ConstructorTmpl)
3262 CandidateSet, SuppressUserConversions);
3265 CandidateSet, SuppressUserConversions);
3269 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
3272 switch (
auto Result =
3296 llvm_unreachable(
"Invalid OverloadResult!");
3318 bool AllowObjCConversionOnExplicit) {
3319 assert(AllowExplicit || !AllowObjCConversionOnExplicit);
3323 bool ConstructorsOnly =
false;
3339 ConstructorsOnly =
true;
3344 = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
3346 Expr **Args = &From;
3347 unsigned NumArgs = 1;
3348 bool ListInitializing =
false;
3349 if (
InitListExpr *InitList = dyn_cast<InitListExpr>(From)) {
3352 S, From, ToType, ToRecordDecl, User, CandidateSet, AllowExplicit);
3361 Args = InitList->getInits();
3362 NumArgs = InitList->getNumInits();
3363 ListInitializing =
true;
3371 bool Usable = !Info.Constructor->isInvalidDecl();
3372 if (ListInitializing)
3373 Usable = Usable && (AllowExplicit || !Info.Constructor->isExplicit());
3376 Info.Constructor->isConvertingConstructor(AllowExplicit);
3378 bool SuppressUserConversions = !ConstructorsOnly;
3379 if (SuppressUserConversions && ListInitializing) {
3380 SuppressUserConversions =
false;
3385 S.
Context, Info.Constructor, ToType);
3388 if (Info.ConstructorTmpl)
3390 Info.ConstructorTmpl, Info.FoundDecl,
3391 nullptr, llvm::makeArrayRef(Args, NumArgs),
3392 CandidateSet, SuppressUserConversions);
3397 llvm::makeArrayRef(Args, NumArgs),
3398 CandidateSet, SuppressUserConversions);
3405 if (ConstructorsOnly || isa<InitListExpr>(From)) {
3408 }
else if (
const RecordType *FromRecordType =
3411 = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) {
3413 const auto &Conversions = FromRecordDecl->getVisibleConversionFunctions();
3414 for (
auto I = Conversions.
begin(), E = Conversions.
end(); I != E; ++I) {
3418 if (isa<UsingShadowDecl>(D))
3419 D = cast<UsingShadowDecl>(D)->getTargetDecl();
3423 if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(D)))
3426 Conv = cast<CXXConversionDecl>(D);
3428 if (AllowExplicit || !Conv->isExplicit()) {
3431 ActingContext, From, ToType,
3433 AllowObjCConversionOnExplicit);
3436 From, ToType, CandidateSet,
3437 AllowObjCConversionOnExplicit);
3443 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
3446 switch (
auto Result =
3452 = dyn_cast<CXXConstructorDecl>(Best->Function)) {
3459 QualType ThisType = Constructor->getThisType();
3460 if (isa<InitListExpr>(From)) {
3464 if (Best->Conversions[0].isEllipsis())
3467 User.
Before = Best->Conversions[0].Standard;
3480 = dyn_cast<CXXConversionDecl>(Best->Function)) {
3487 User.
Before = Best->Conversions[0].Standard;
3502 User.
After = Best->FinalConversion;
3505 llvm_unreachable(
"Not a constructor or conversion function?");
3514 llvm_unreachable(
"Invalid OverloadResult!");
3524 CandidateSet,
false,
false);
3529 if (!RequireCompleteType(From->
getBeginLoc(), ToType,
3530 diag::err_typecheck_nonviable_condition_incomplete,
3566 if (Block1 != Block2)
3653 if (!ICS1.
isBad()) {
3786 else if (Rank2 < Rank1)
3807 bool SCS1ConvertsToVoid
3809 bool SCS2ConvertsToVoid
3811 if (SCS1ConvertsToVoid != SCS2ConvertsToVoid) {
3816 }
else if (!SCS1ConvertsToVoid && !SCS2ConvertsToVoid) {
3822 }
else if (SCS1ConvertsToVoid && SCS2ConvertsToVoid &&
3851 if (FromObjCPtr1 && FromObjCPtr2) {
3856 if (AssignLeft != AssignRight) {
3889 if (UnqualT1 == UnqualT2) {
3901 if (isa<ArrayType>(T1) && T1Quals)
3903 if (isa<ArrayType>(T2) && T2Quals)
3949 if (SCS1IsCompatibleVectorConversion != SCS2IsCompatibleVectorConversion)
3950 return SCS1IsCompatibleVectorConversion
3987 if (UnqualT1 == UnqualT2)
3992 if (isa<ArrayType>(T1) && T1Quals)
3994 if (isa<ArrayType>(T2) && T2Quals)
4120 if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
4128 if (FromPointee1 != FromPointee2 && ToPointee1 == ToPointee2) {
4145 if (FromPtr1 && FromPtr2 && ToPtr1 && ToPtr2) {
4152 bool FromAssignRight
4161 if (ToPtr1->isObjCIdType() &&
4162 (ToPtr2->isObjCQualifiedIdType() || ToPtr2->getInterfaceDecl()))
4164 if (ToPtr2->isObjCIdType() &&
4165 (ToPtr1->isObjCQualifiedIdType() || ToPtr1->getInterfaceDecl()))
4170 if (ToPtr1->isObjCQualifiedIdType() && ToPtr2->getInterfaceDecl())
4172 if (ToPtr2->isObjCQualifiedIdType() && ToPtr1->getInterfaceDecl())
4177 if (ToPtr1->isObjCClassType() &&
4178 (ToPtr2->isObjCQualifiedClassType() || ToPtr2->getInterfaceDecl()))
4180 if (ToPtr2->isObjCClassType() &&
4181 (ToPtr1->isObjCQualifiedClassType() || ToPtr1->getInterfaceDecl()))
4186 if (ToPtr1->isObjCQualifiedClassType() && ToPtr2->getInterfaceDecl())
4188 if (ToPtr2->isObjCQualifiedClassType() && ToPtr1->getInterfaceDecl())
4194 (ToAssignLeft != ToAssignRight)) {
4205 }
else if (IsSecondSame)
4214 (FromAssignLeft != FromAssignRight))
4232 const Type *FromPointeeType1 = FromMemPointer1->
getClass();
4233 const Type *ToPointeeType1 = ToMemPointer1->getClass();
4234 const Type *FromPointeeType2 = FromMemPointer2->getClass();
4235 const Type *ToPointeeType2 = ToMemPointer2->getClass();
4241 if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
4248 if (ToPointee1 == ToPointee2 && FromPointee1 != FromPointee2) {
4289 return !Record->isInvalidDecl();
4304 bool &DerivedToBase,
4305 bool &ObjCConversion,
4306 bool &ObjCLifetimeConversion) {
4308 "T1 must be the pointee type of the reference type");
4309 assert(!OrigT2->
isReferenceType() &&
"T2 cannot be a reference type");
4321 DerivedToBase =
false;
4322 ObjCConversion =
false;
4323 ObjCLifetimeConversion =
false;
4325 if (UnqualT1 == UnqualT2) {
4327 }
else if (isCompleteType(Loc, OrigT2) &&
4329 IsDerivedFrom(Loc, UnqualT2, UnqualT1))
4330 DerivedToBase =
true;
4334 ObjCConversion =
true;
4336 IsFunctionConversion(UnqualT2, UnqualT1, ConvertedT2))
4343 return Ref_Compatible;
4345 return Ref_Incompatible;
4352 if (isa<ArrayType>(T1) && T1Quals)
4354 if (isa<ArrayType>(T2) && T2Quals)
4372 ObjCLifetimeConversion =
true;
4383 return Ref_Compatible;
4394 bool AllowExplicit) {
4395 assert(T2->
isRecordType() &&
"Can only find conversions of record types.");
4401 const auto &Conversions = T2RecordDecl->getVisibleConversionFunctions();
4402 for (
auto I = Conversions.begin(), E = Conversions.end(); I != E; ++I) {
4405 if (isa<UsingShadowDecl>(D))
4406 D = cast<UsingShadowDecl>(D)->getTargetDecl();
4414 Conv = cast<CXXConversionDecl>(D);
4418 if (!AllowExplicit && Conv->isExplicit())
4422 bool DerivedToBase =
false;
4423 bool ObjCConversion =
false;
4424 bool ObjCLifetimeConversion =
false;
4435 if (!ConvTemplate &&
4438 Conv->getConversionType().getNonReferenceType()
4439 .getUnqualifiedType(),
4441 DerivedToBase, ObjCConversion, ObjCLifetimeConversion) ==
4459 Init, DeclType, CandidateSet,
4463 DeclType, CandidateSet,
4467 bool HadMultipleCandidates = (CandidateSet.size() > 1);
4470 switch (CandidateSet.BestViableFunction(S, DeclLoc, Best)) {
4482 if (!Best->FinalConversion.DirectBinding)
4494 "Expected a direct reference binding!");
4500 Cand != CandidateSet.end(); ++Cand)
4512 llvm_unreachable(
"Invalid OverloadResult!");
4520 bool SuppressUserConversions,
4521 bool AllowExplicit) {
4522 assert(DeclType->
isReferenceType() &&
"Reference init needs a reference");
4543 bool DerivedToBase =
false;
4544 bool ObjCConversion =
false;
4545 bool ObjCLifetimeConversion =
false;
4549 ObjCConversion, ObjCLifetimeConversion);
4577 ICS.Standard.setToType(0, T2);
4578 ICS.Standard.setToType(1, T1);
4579 ICS.Standard.setToType(2, T1);
4580 ICS.Standard.ReferenceBinding =
true;
4581 ICS.Standard.DirectBinding =
true;
4582 ICS.Standard.IsLvalueReference = !isRValRef;
4584 ICS.Standard.BindsToRvalue =
false;
4585 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier =
false;
4586 ICS.Standard.ObjCLifetimeConversionBinding = ObjCLifetimeConversion;
4587 ICS.Standard.CopyConstructor =
nullptr;
4588 ICS.Standard.DeprecatedStringLiteralToCharPtr =
false;
4635 ICS.Standard.setToType(0, T2);
4636 ICS.Standard.setToType(1, T1);
4637 ICS.Standard.setToType(2, T1);
4638 ICS.Standard.ReferenceBinding =
true;
4644 ICS.Standard.DirectBinding =
4647 ICS.Standard.IsLvalueReference = !isRValRef;
4649 ICS.Standard.BindsToRvalue = InitCategory.
isRValue();
4650 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier =
false;
4651 ICS.Standard.ObjCLifetimeConversionBinding = ObjCLifetimeConversion;
4652 ICS.Standard.CopyConstructor =
nullptr;
4653 ICS.Standard.DeprecatedStringLiteralToCharPtr =
false;
4676 if (ICS.isUserDefined() && isRValRef &&
4748 if (ICS.isStandard()) {
4749 ICS.Standard.ReferenceBinding =
true;
4750 ICS.Standard.IsLvalueReference = !isRValRef;
4751 ICS.Standard.BindsToFunctionLvalue =
false;
4752 ICS.Standard.BindsToRvalue =
true;
4753 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier =
false;
4754 ICS.Standard.ObjCLifetimeConversionBinding =
false;
4755 }
else if (ICS.isUserDefined()) {
4757 ICS.UserDefined.ConversionFunction->getReturnType()
4774 ICS.UserDefined.After.ReferenceBinding =
true;
4775 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
4776 ICS.UserDefined.After.BindsToFunctionLvalue =
false;
4777 ICS.UserDefined.After.BindsToRvalue = !LValRefType;
4778 ICS.UserDefined.After.BindsImplicitObjectArgumentWithoutRefQualifier =
false;
4779 ICS.UserDefined.After.ObjCLifetimeConversionBinding =
false;
4787 bool SuppressUserConversions,
4788 bool InOverloadResolution,
4789 bool AllowObjCWritebackConversion,
4790 bool AllowExplicit =
false);
4796 bool SuppressUserConversions,
4797 bool InOverloadResolution,
4798 bool AllowObjCWritebackConversion) {
4827 SuppressUserConversions,
4828 InOverloadResolution,
4829 AllowObjCWritebackConversion);
4862 bool toStdInitializerList =
false;
4869 for (
unsigned i = 0, e = From->
getNumInits(); i < e; ++i) {
4873 InOverloadResolution,
4874 AllowObjCWritebackConversion);
4911 InOverloadResolution,
false,
4912 AllowObjCWritebackConversion,
4969 Init, ToType,
false, Found))
4974 bool dummy1 =
false;
4975 bool dummy2 =
false;
4976 bool dummy3 =
false;
4983 SuppressUserConversions,
4991 InOverloadResolution,
4992 AllowObjCWritebackConversion);
4993 if (Result.isFailure())
4995 assert(!Result.isEllipsis() &&
4996 "Sub-initialization cannot result in ellipsis conversion.");
5002 Result.UserDefined.After;
5023 if (NumInits == 1 && !isa<InitListExpr>(From->
getInit(0)))
5025 SuppressUserConversions,
5026 InOverloadResolution,
5027 AllowObjCWritebackConversion);
5030 else if (NumInits == 0) {
5053 bool SuppressUserConversions,
5054 bool InOverloadResolution,
5055 bool AllowObjCWritebackConversion,
5056 bool AllowExplicit) {
5057 if (
InitListExpr *FromInitList = dyn_cast<InitListExpr>(From))
5059 InOverloadResolution,AllowObjCWritebackConversion);
5064 SuppressUserConversions, AllowExplicit);
5067 SuppressUserConversions,
5069 InOverloadResolution,
5071 AllowObjCWritebackConversion,
5084 return !ICS.
isBad();
5099 if (isa<CXXDestructorDecl>(Method)) {
5118 assert(FromClassification.
isLValue());
5144 != FromTypeCanon.getLocalCVRQualifiers() &&
5147 FromType, ImplicitParamType);
5151 if (FromTypeCanon.getQualifiers().hasAddressSpace()) {
5153 Qualifiers QualsFromType = FromTypeCanon.getQualifiers();
5156 FromType, ImplicitParamType);
5171 FromType, ImplicitParamType);
5191 if (!FromClassification.
isRValue()) {
5234 FromRecordType = From->
getType();
5235 DestType = ImplicitParamRecordType;
5236 FromClassification = From->
Classify(Context);
5240 From = CreateMaterializeTemporaryExpr(FromRecordType, From,
5252 switch (ICS.Bad.Kind) {
5259 << Method->getDeclName() << FromRecordType << (CVR - 1)
5261 Diag(Method->getLocation(), diag::note_previous_decl)
5262 << Method->getDeclName();
5270 bool IsRValueQualified =
5273 << Method->getDeclName() << FromClassification.
isRValue()
5274 << IsRValueQualified;
5275 Diag(Method->getLocation(), diag::note_previous_decl)
5276 << Method->getDeclName();
5285 return Diag(From->
getBeginLoc(), diag::err_member_function_call_bad_type)
5286 << ImplicitParamRecordType << FromRecordType
5292 PerformObjectMemberConversion(From, Qualifier, FoundDecl, Method);
5295 From = FromRes.
get();
5300 From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion,
5303 From = ImpCastExprToType(From, DestType, CK_NoOp,
5330 return PerformImplicitConversion(From, Context.
BoolTy, ICS, AA_Converting);
5332 if (!DiagnoseMultipleUserDefinedConversion(From, Context.
BoolTy))