summaryrefslogtreecommitdiff
path: root/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp628
1 files changed, 334 insertions, 294 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 08af485ef4c72..52be0598fbc03 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -63,8 +63,8 @@ CreateFunctionRefExpr(Sema &S, FunctionDecl *Fn, NamedDecl *FoundDecl,
return ExprError();
if (auto *FPT = Fn->getType()->getAs<FunctionProtoType>())
S.ResolveExceptionSpec(Loc, FPT);
- DeclRefExpr *DRE = new (S.Context) DeclRefExpr(Fn, false, Fn->getType(),
- VK_LValue, Loc, LocInfo);
+ DeclRefExpr *DRE = new (S.Context)
+ DeclRefExpr(S.Context, Fn, false, Fn->getType(), VK_LValue, Loc, LocInfo);
if (HadMultipleCandidates)
DRE->setHadMultipleCandidates(true);
@@ -1041,6 +1041,36 @@ Sema::CheckOverload(Scope *S, FunctionDecl *New, const LookupResult &Old,
}
}
+ // C++ [temp.friend]p1:
+ // For a friend function declaration that is not a template declaration:
+ // -- if the name of the friend is a qualified or unqualified template-id,
+ // [...], otherwise
+ // -- if the name of the friend is a qualified-id and a matching
+ // non-template function is found in the specified class or namespace,
+ // the friend declaration refers to that function, otherwise,
+ // -- if the name of the friend is a qualified-id and a matching function
+ // template is found in the specified class or namespace, the friend
+ // declaration refers to the deduced specialization of that function
+ // template, otherwise
+ // -- the name shall be an unqualified-id [...]
+ // If we get here for a qualified friend declaration, we've just reached the
+ // third bullet. If the type of the friend is dependent, skip this lookup
+ // until instantiation.
+ if (New->getFriendObjectKind() && New->getQualifier() &&
+ !New->getDependentSpecializationInfo() &&
+ !New->getType()->isDependentType()) {
+ LookupResult TemplateSpecResult(LookupResult::Temporary, Old);
+ TemplateSpecResult.addAllDecls(Old);
+ if (CheckFunctionTemplateSpecialization(New, nullptr, TemplateSpecResult,
+ /*QualifiedFriend*/true)) {
+ New->setInvalidDecl();
+ return Ovl_Overload;
+ }
+
+ Match = TemplateSpecResult.getAsSingle<FunctionDecl>();
+ return Ovl_Match;
+ }
+
return Ovl_Overload;
}
@@ -1105,7 +1135,8 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old,
(!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(),
OldTemplate->getTemplateParameters(),
false, TPL_TemplateMatch) ||
- OldType->getReturnType() != NewType->getReturnType()))
+ !Context.hasSameType(Old->getDeclaredReturnType(),
+ New->getDeclaredReturnType())))
return true;
// If the function is a class member, its signature includes the
@@ -1141,8 +1172,9 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old,
// function yet (because we haven't yet resolved whether this is a static
// or non-static member function). Add it now, on the assumption that this
// is a redeclaration of OldMethod.
- unsigned OldQuals = OldMethod->getTypeQualifiers();
- unsigned NewQuals = NewMethod->getTypeQualifiers();
+ // FIXME: OpenCL: Need to consider address spaces
+ unsigned OldQuals = OldMethod->getTypeQualifiers().getCVRUQualifiers();
+ unsigned NewQuals = NewMethod->getTypeQualifiers().getCVRUQualifiers();
if (!getLangOpts().CPlusPlus14 && NewMethod->isConstexpr() &&
!isa<CXXConstructorDecl>(NewMethod))
NewQuals |= Qualifiers::Const;
@@ -1263,7 +1295,7 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
= S.Context.getCanonicalType(ToType).getUnqualifiedType();
if (Constructor->isCopyConstructor() &&
(FromCanon == ToCanon ||
- S.IsDerivedFrom(From->getLocStart(), FromCanon, ToCanon))) {
+ S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) {
// Turn this into a "standard" conversion sequence, so that it
// gets ranked with standard conversion sequences.
DeclAccessPair Found = ICS.UserDefined.FoundConversionFunction;
@@ -1355,7 +1387,7 @@ TryImplicitConversion(Sema &S, Expr *From, QualType ToType,
QualType FromType = From->getType();
if (ToType->getAs<RecordType>() && FromType->getAs<RecordType>() &&
(S.Context.hasSameUnqualifiedType(FromType, ToType) ||
- S.IsDerivedFrom(From->getLocStart(), FromType, ToType))) {
+ S.IsDerivedFrom(From->getBeginLoc(), FromType, ToType))) {
ICS.setStandard();
ICS.Standard.setAsIdentityConversion();
ICS.Standard.setFromType(FromType);
@@ -1417,9 +1449,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
bool AllowObjCWritebackConversion
= getLangOpts().ObjCAutoRefCount &&
(Action == AA_Passing || Action == AA_Sending);
- if (getLangOpts().ObjC1)
- CheckObjCBridgeRelatedConversions(From->getLocStart(),
- ToType, From->getType(), From);
+ if (getLangOpts().ObjC)
+ CheckObjCBridgeRelatedConversions(From->getBeginLoc(), ToType,
+ From->getType(), From);
ICS = ::TryImplicitConversion(*this, From, ToType,
/*SuppressUserConversions=*/false,
AllowExplicit,
@@ -2011,7 +2043,7 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) {
// We have already pre-calculated the promotion type, so this is trivial.
if (ToType->isIntegerType() &&
- isCompleteType(From->getLocStart(), FromType))
+ isCompleteType(From->getBeginLoc(), FromType))
return Context.hasSameUnqualifiedType(
ToType, FromEnumType->getDecl()->getPromotionType());
@@ -2353,10 +2385,10 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
//
// Note that we do not check for ambiguity or inaccessibility
// here. That is handled by CheckPointerConversion.
- if (getLangOpts().CPlusPlus &&
- FromPointeeType->isRecordType() && ToPointeeType->isRecordType() &&
+ if (getLangOpts().CPlusPlus && FromPointeeType->isRecordType() &&
+ ToPointeeType->isRecordType() &&
!Context.hasSameUnqualifiedType(FromPointeeType, ToPointeeType) &&
- IsDerivedFrom(From->getLocStart(), FromPointeeType, ToPointeeType)) {
+ IsDerivedFrom(From->getBeginLoc(), FromPointeeType, ToPointeeType)) {
ConvertedType = BuildSimilarlyQualifiedPointerType(FromTypePtr,
ToPointeeType,
ToType, Context);
@@ -2394,7 +2426,7 @@ static QualType AdoptQualifiers(ASTContext &Context, QualType T, Qualifiers Qs){
bool Sema::isObjCPointerConversion(QualType FromType, QualType ToType,
QualType& ConvertedType,
bool &IncompatibleObjC) {
- if (!getLangOpts().ObjC1)
+ if (!getLangOpts().ObjC)
return false;
// The set of qualifiers on the type we're converting from.
@@ -2822,10 +2854,9 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
return;
}
- unsigned FromQuals = FromFunction->getTypeQuals(),
- ToQuals = ToFunction->getTypeQuals();
- if (FromQuals != ToQuals) {
- PDiag << ft_qualifer_mismatch << ToQuals << FromQuals;
+ if (FromFunction->getTypeQuals() != ToFunction->getTypeQuals()) {
+ PDiag << ft_qualifer_mismatch << ToFunction->getTypeQuals()
+ << FromFunction->getTypeQuals();
return;
}
@@ -2983,7 +3014,7 @@ bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType,
QualType ToClass(ToTypePtr->getClass(), 0);
if (!Context.hasSameUnqualifiedType(FromClass, ToClass) &&
- IsDerivedFrom(From->getLocStart(), ToClass, FromClass)) {
+ IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass)) {
ConvertedType = Context.getMemberPointerType(FromTypePtr->getPointeeType(),
ToClass.getTypePtr());
return true;
@@ -3027,7 +3058,7 @@ bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType,
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
/*DetectVirtual=*/true);
bool DerivationOkay =
- IsDerivedFrom(From->getLocStart(), ToClass, FromClass, Paths);
+ IsDerivedFrom(From->getBeginLoc(), ToClass, FromClass, Paths);
assert(DerivationOkay &&
"Should not have been called if derivation isn't OK.");
(void)DerivationOkay;
@@ -3242,13 +3273,12 @@ IsInitializerListConstructorConversion(Sema &S, Expr *From, QualType ToType,
OverloadCandidateSet::iterator Best;
switch (auto Result =
- CandidateSet.BestViableFunction(S, From->getLocStart(),
- Best)) {
+ CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) {
case OR_Deleted:
case OR_Success: {
// Record the standard conversion we used and the conversion function.
CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Best->Function);
- QualType ThisType = Constructor->getThisType(S.Context);
+ QualType ThisType = Constructor->getThisType();
// Initializer lists don't have conversions as such.
User.Before.setAsIdentityConversion();
User.HadMultipleCandidates = HadMultipleCandidates;
@@ -3308,7 +3338,7 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
// the parentheses of the initializer.
if (S.Context.hasSameUnqualifiedType(ToType, From->getType()) ||
(From->getType()->getAs<RecordType>() &&
- S.IsDerivedFrom(From->getLocStart(), From->getType(), ToType)))
+ S.IsDerivedFrom(From->getBeginLoc(), From->getType(), ToType)))
ConstructorsOnly = true;
if (!S.isCompleteType(From->getExprLoc(), ToType)) {
@@ -3376,10 +3406,10 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
// Enumerate conversion functions, if we're allowed to.
if (ConstructorsOnly || isa<InitListExpr>(From)) {
- } else if (!S.isCompleteType(From->getLocStart(), From->getType())) {
+ } else if (!S.isCompleteType(From->getBeginLoc(), From->getType())) {
// No conversion functions from incomplete types.
- } else if (const RecordType *FromRecordType
- = From->getType()->getAs<RecordType>()) {
+ } else if (const RecordType *FromRecordType =
+ From->getType()->getAs<RecordType>()) {
if (CXXRecordDecl *FromRecordDecl
= dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) {
// Add all of the conversion functions as candidates.
@@ -3416,8 +3446,8 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
bool HadMultipleCandidates = (CandidateSet.size() > 1);
OverloadCandidateSet::iterator Best;
- switch (auto Result = CandidateSet.BestViableFunction(S, From->getLocStart(),
- Best)) {
+ switch (auto Result =
+ CandidateSet.BestViableFunction(S, From->getBeginLoc(), Best)) {
case OR_Success:
case OR_Deleted:
// Record the standard conversion we used and the conversion function.
@@ -3429,7 +3459,7 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
// sequence converts the source type to the type required by
// the argument of the constructor.
//
- QualType ThisType = Constructor->getThisType(S.Context);
+ QualType ThisType = Constructor->getThisType();
if (isa<InitListExpr>(From)) {
// Initializer lists don't have conversions as such.
User.Before.setAsIdentityConversion();
@@ -3496,13 +3526,13 @@ Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) {
IsUserDefinedConversion(*this, From, ToType, ICS.UserDefined,
CandidateSet, false, false);
if (OvResult == OR_Ambiguous)
- Diag(From->getLocStart(), diag::err_typecheck_ambiguous_condition)
+ Diag(From->getBeginLoc(), diag::err_typecheck_ambiguous_condition)
<< From->getType() << ToType << From->getSourceRange();
else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty()) {
- if (!RequireCompleteType(From->getLocStart(), ToType,
+ if (!RequireCompleteType(From->getBeginLoc(), ToType,
diag::err_typecheck_nonviable_condition_incomplete,
From->getType(), From->getSourceRange()))
- Diag(From->getLocStart(), diag::err_typecheck_nonviable_condition)
+ Diag(From->getBeginLoc(), diag::err_typecheck_nonviable_condition)
<< false << From->getType() << From->getSourceRange() << ToType;
} else
return false;
@@ -3516,7 +3546,7 @@ Sema::DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType) {
static ImplicitConversionSequence::CompareKind
compareConversionFunctions(Sema &S, FunctionDecl *Function1,
FunctionDecl *Function2) {
- if (!S.getLangOpts().ObjC1 || !S.getLangOpts().CPlusPlus11)
+ if (!S.getLangOpts().ObjC || !S.getLangOpts().CPlusPlus11)
return ImplicitConversionSequence::Indistinguishable;
// Objective-C++:
@@ -3900,6 +3930,31 @@ CompareStandardConversionSequences(Sema &S, SourceLocation Loc,
S.Context.getTypeSize(SCS1.getToType(2)))
return ImplicitConversionSequence::Better;
+ // Prefer a compatible vector conversion over a lax vector conversion
+ // For example:
+ //
+ // typedef float __v4sf __attribute__((__vector_size__(16)));
+ // void f(vector float);
+ // void f(vector signed int);
+ // int main() {
+ // __v4sf a;
+ // f(a);
+ // }
+ // Here, we'd like to choose f(vector float) and not
+ // report an ambiguous call error
+ if (SCS1.Second == ICK_Vector_Conversion &&
+ SCS2.Second == ICK_Vector_Conversion) {
+ bool SCS1IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes(
+ SCS1.getFromType(), SCS1.getToType(2));
+ bool SCS2IsCompatibleVectorConversion = S.Context.areCompatibleVectorTypes(
+ SCS2.getFromType(), SCS2.getToType(2));
+
+ if (SCS1IsCompatibleVectorConversion != SCS2IsCompatibleVectorConversion)
+ return SCS1IsCompatibleVectorConversion
+ ? ImplicitConversionSequence::Better
+ : ImplicitConversionSequence::Worse;
+ }
+
return ImplicitConversionSequence::Indistinguishable;
}
@@ -4750,7 +4805,7 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
// We need a complete type for what follows. Incomplete types can never be
// initialized from init lists.
- if (!S.isCompleteType(From->getLocStart(), ToType))
+ if (!S.isCompleteType(From->getBeginLoc(), ToType))
return Result;
// Per DR1467:
@@ -4767,7 +4822,7 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
if (ToType->isRecordType()) {
QualType InitType = From->getInit(0)->getType();
if (S.Context.hasSameUnqualifiedType(InitType, ToType) ||
- S.IsDerivedFrom(From->getLocStart(), InitType, ToType))
+ S.IsDerivedFrom(From->getBeginLoc(), InitType, ToType))
return TryCopyInitialization(S, From->getInit(0), ToType,
SuppressUserConversions,
InOverloadResolution,
@@ -4823,10 +4878,9 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
break;
}
// Otherwise, look for the worst conversion.
- if (Result.isBad() ||
- CompareImplicitConversionSequences(S, From->getLocStart(), ICS,
- Result) ==
- ImplicitConversionSequence::Worse)
+ if (Result.isBad() || CompareImplicitConversionSequences(
+ S, From->getBeginLoc(), ICS, Result) ==
+ ImplicitConversionSequence::Worse)
Result = ICS;
}
@@ -4920,12 +4974,12 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType,
bool dummy1 = false;
bool dummy2 = false;
bool dummy3 = false;
- Sema::ReferenceCompareResult RefRelationship
- = S.CompareReferenceRelationship(From->getLocStart(), T1, T2, dummy1,
+ Sema::ReferenceCompareResult RefRelationship =
+ S.CompareReferenceRelationship(From->getBeginLoc(), T1, T2, dummy1,
dummy2, dummy3);
if (RefRelationship >= Sema::Ref_Related) {
- return TryReferenceInit(S, Init, ToType, /*FIXME*/From->getLocStart(),
+ return TryReferenceInit(S, Init, ToType, /*FIXME*/ From->getBeginLoc(),
SuppressUserConversions,
/*AllowExplicit=*/false);
}
@@ -5006,9 +5060,8 @@ TryCopyInitialization(Sema &S, Expr *From, QualType ToType,
if (ToType->isReferenceType())
return TryReferenceInit(S, From, ToType,
- /*FIXME:*/From->getLocStart(),
- SuppressUserConversions,
- AllowExplicit);
+ /*FIXME:*/ From->getBeginLoc(),
+ SuppressUserConversions, AllowExplicit);
return TryImplicitConversion(S, From, ToType,
SuppressUserConversions,
@@ -5042,9 +5095,15 @@ TryObjectArgumentInitialization(Sema &S, SourceLocation Loc, QualType FromType,
QualType ClassType = S.Context.getTypeDeclType(ActingContext);
// [class.dtor]p2: A destructor can be invoked for a const, volatile or
// const volatile object.
- unsigned Quals = isa<CXXDestructorDecl>(Method) ?
- Qualifiers::Const | Qualifiers::Volatile : Method->getTypeQualifiers();
- QualType ImplicitParamType = S.Context.getCVRQualifiedType(ClassType, Quals);
+ Qualifiers Quals;
+ if (isa<CXXDestructorDecl>(Method)) {
+ Quals.addConst();
+ Quals.addVolatile();
+ } else {
+ Quals = Method->getTypeQualifiers();
+ }
+
+ QualType ImplicitParamType = S.Context.getQualifiedType(ClassType, Quals);
// Set up the conversion sequence as a "bad" conversion, to allow us
// to exit early.
@@ -5110,7 +5169,7 @@ TryObjectArgumentInitialization(Sema &S, SourceLocation Loc, QualType FromType,
break;
case RQ_LValue:
- if (!FromClassification.isLValue() && Quals != Qualifiers::Const) {
+ if (!FromClassification.isLValue() && !Quals.hasOnlyConst()) {
// non-const lvalue reference cannot bind to an rvalue
ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, FromType,
ImplicitParamType);
@@ -5154,12 +5213,12 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
CXXMethodDecl *Method) {
QualType FromRecordType, DestType;
QualType ImplicitParamRecordType =
- Method->getThisType(Context)->getAs<PointerType>()->getPointeeType();
+ Method->getThisType()->getAs<PointerType>()->getPointeeType();
Expr::Classification FromClassification;
if (const PointerType *PT = From->getType()->getAs<PointerType>()) {
FromRecordType = PT->getPointeeType();
- DestType = Method->getThisType(Context);
+ DestType = Method->getThisType();
FromClassification = Expr::Classification::makeSimpleLValue();
} else {
FromRecordType = From->getType();
@@ -5177,7 +5236,7 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
// Note that we always use the true parent context when performing
// the actual argument initialization.
ImplicitConversionSequence ICS = TryObjectArgumentInitialization(
- *this, From->getLocStart(), From->getType(), FromClassification, Method,
+ *this, From->getBeginLoc(), From->getType(), FromClassification, Method,
Method->getParent());
if (ICS.isBad()) {
switch (ICS.Bad.Kind) {
@@ -5186,10 +5245,9 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
Qualifiers ToQs = DestType.getQualifiers();
unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
if (CVR) {
- Diag(From->getLocStart(),
- diag::err_member_function_call_bad_cvr)
- << Method->getDeclName() << FromRecordType << (CVR - 1)
- << From->getSourceRange();
+ Diag(From->getBeginLoc(), diag::err_member_function_call_bad_cvr)
+ << Method->getDeclName() << FromRecordType << (CVR - 1)
+ << From->getSourceRange();
Diag(Method->getLocation(), diag::note_previous_decl)
<< Method->getDeclName();
return ExprError();
@@ -5201,9 +5259,9 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
case BadConversionSequence::rvalue_ref_to_lvalue: {
bool IsRValueQualified =
Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
- Diag(From->getLocStart(), diag::err_member_function_call_bad_ref)
- << Method->getDeclName() << FromClassification.isRValue()
- << IsRValueQualified;
+ Diag(From->getBeginLoc(), diag::err_member_function_call_bad_ref)
+ << Method->getDeclName() << FromClassification.isRValue()
+ << IsRValueQualified;
Diag(Method->getLocation(), diag::note_previous_decl)
<< Method->getDeclName();
return ExprError();
@@ -5214,9 +5272,9 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
break;
}
- return Diag(From->getLocStart(),
- diag::err_member_function_call_bad_type)
- << ImplicitParamRecordType << FromRecordType << From->getSourceRange();
+ return Diag(From->getBeginLoc(), diag::err_member_function_call_bad_type)
+ << ImplicitParamRecordType << FromRecordType
+ << From->getSourceRange();
}
if (ICS.Standard.Second == ICK_Derived_To_Base) {
@@ -5227,9 +5285,14 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
From = FromRes.get();
}
- if (!Context.hasSameType(From->getType(), DestType))
- From = ImpCastExprToType(From, DestType, CK_NoOp,
+ if (!Context.hasSameType(From->getType(), DestType)) {
+ if (From->getType().getAddressSpace() != DestType.getAddressSpace())
+ From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion,
From->getValueKind()).get();
+ else
+ From = ImpCastExprToType(From, DestType, CK_NoOp,
+ From->getValueKind()).get();
+ }
return From;
}
@@ -5257,9 +5320,8 @@ ExprResult Sema::PerformContextuallyConvertToBool(Expr *From) {
return PerformImplicitConversion(From, Context.BoolTy, ICS, AA_Converting);
if (!DiagnoseMultipleUserDefinedConversion(From, Context.BoolTy))
- return Diag(From->getLocStart(),
- diag::err_typecheck_bool_condition)
- << From->getType() << From->getSourceRange();
+ return Diag(From->getBeginLoc(), diag::err_typecheck_bool_condition)
+ << From->getType() << From->getSourceRange();
return ExprError();
}
@@ -5372,9 +5434,9 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
case ImplicitConversionSequence::AmbiguousConversion:
case ImplicitConversionSequence::BadConversion:
if (!S.DiagnoseMultipleUserDefinedConversion(From, T))
- return S.Diag(From->getLocStart(),
+ return S.Diag(From->getBeginLoc(),
diag::err_typecheck_converted_constant_expression)
- << From->getType() << From->getSourceRange() << T;
+ << From->getType() << From->getSourceRange() << T;
return ExprError();
case ImplicitConversionSequence::EllipsisConversion:
@@ -5383,15 +5445,15 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
// Check that we would only use permitted conversions.
if (!CheckConvertedConstantConversions(S, *SCS)) {
- return S.Diag(From->getLocStart(),
+ return S.Diag(From->getBeginLoc(),
diag::err_typecheck_converted_constant_expression_disallowed)
- << From->getType() << From->getSourceRange() << T;
+ << From->getType() << From->getSourceRange() << T;
}
// [...] and where the reference binding (if any) binds directly.
if (SCS->ReferenceBinding && !SCS->DirectBinding) {
- return S.Diag(From->getLocStart(),
+ return S.Diag(From->getBeginLoc(),
diag::err_typecheck_converted_constant_expression_indirect)
- << From->getType() << From->getSourceRange() << T;
+ << From->getType() << From->getSourceRange() << T;
}
ExprResult Result =
@@ -5414,14 +5476,14 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
break;
case NK_Constant_Narrowing:
- S.Diag(From->getLocStart(), diag::ext_cce_narrowing)
- << CCE << /*Constant*/1
- << PreNarrowingValue.getAsString(S.Context, PreNarrowingType) << T;
+ S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing)
+ << CCE << /*Constant*/ 1
+ << PreNarrowingValue.getAsString(S.Context, PreNarrowingType) << T;
break;
case NK_Type_Narrowing:
- S.Diag(From->getLocStart(), diag::ext_cce_narrowing)
- << CCE << /*Constant*/0 << From->getType() << T;
+ S.Diag(From->getBeginLoc(), diag::ext_cce_narrowing)
+ << CCE << /*Constant*/ 0 << From->getType() << T;
break;
}
@@ -5448,7 +5510,7 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
if (Notes.empty()) {
// It's a constant expression.
- return Result;
+ return ConstantExpr::Create(S.Context, Result.get());
}
}
@@ -5457,8 +5519,8 @@ static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From,
Notes[0].second.getDiagID() == diag::note_invalid_subexpr_in_const_expr)
S.Diag(Notes[0].first, diag::err_expr_not_cce) << CCE;
else {
- S.Diag(From->getLocStart(), diag::err_expr_not_cce)
- << CCE << From->getSourceRange();
+ S.Diag(From->getBeginLoc(), diag::err_expr_not_cce)
+ << CCE << From->getSourceRange();
for (unsigned I = 0; I < Notes.size(); ++I)
S.Diag(Notes[I].first, Notes[I].second);
}
@@ -5586,10 +5648,10 @@ diagnoseNoViableConversion(Sema &SemaRef, SourceLocation Loc, Expr *&From,
ConvTy.getAsStringInternal(TypeStr, SemaRef.getPrintingPolicy());
Converter.diagnoseExplicitConv(SemaRef, Loc, T, ConvTy)
- << FixItHint::CreateInsertion(From->getLocStart(),
+ << FixItHint::CreateInsertion(From->getBeginLoc(),
"static_cast<" + TypeStr + ">(")
<< FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(From->getLocEnd()), ")");
+ SemaRef.getLocForEndOfToken(From->getEndLoc()), ")");
Converter.noteExplicitConv(SemaRef, Conversion, ConvTy);
// If we aren't in a SFINAE context, build a call to the
@@ -5925,15 +5987,13 @@ static bool IsAcceptableNonMemberOperatorCandidate(ASTContext &Context,
/// \param PartialOverloading true if we are performing "partial" overloading
/// based on an incomplete set of function arguments. This feature is used by
/// code completion.
-void
-Sema::AddOverloadCandidate(FunctionDecl *Function,
- DeclAccessPair FoundDecl,
- ArrayRef<Expr *> Args,
- OverloadCandidateSet &CandidateSet,
- bool SuppressUserConversions,
- bool PartialOverloading,
- bool AllowExplicit,
- ConversionSequenceList EarlyConversions) {
+void Sema::AddOverloadCandidate(FunctionDecl *Function,
+ DeclAccessPair FoundDecl, ArrayRef<Expr *> Args,
+ OverloadCandidateSet &CandidateSet,
+ bool SuppressUserConversions,
+ bool PartialOverloading, bool AllowExplicit,
+ ADLCallKind IsADLCandidate,
+ ConversionSequenceList EarlyConversions) {
const FunctionProtoType *Proto
= dyn_cast<FunctionProtoType>(Function->getType()->getAs<FunctionType>());
assert(Proto && "Functions without a prototype cannot be overloaded");
@@ -5992,6 +6052,7 @@ Sema::AddOverloadCandidate(FunctionDecl *Function,
Candidate.Function = Function;
Candidate.Viable = true;
Candidate.IsSurrogate = false;
+ Candidate.IsADLCandidate = IsADLCandidate;
Candidate.IgnoreObjectArgument = false;
Candidate.ExplicitCallArguments = Args.size();
@@ -6009,7 +6070,7 @@ Sema::AddOverloadCandidate(FunctionDecl *Function,
QualType ClassType = Context.getTypeDeclType(Constructor->getParent());
if (Args.size() == 1 && Constructor->isSpecializationCopyingObject() &&
(Context.hasSameUnqualifiedType(ClassType, Args[0]->getType()) ||
- IsDerivedFrom(Args[0]->getLocStart(), Args[0]->getType(),
+ IsDerivedFrom(Args[0]->getBeginLoc(), Args[0]->getType(),
ClassType))) {
Candidate.Viable = false;
Candidate.FailureKind = ovl_fail_illegal_constructor;
@@ -6215,24 +6276,6 @@ Sema::SelectBestMethod(Selector Sel, MultiExprArg Args, bool IsInstance,
return nullptr;
}
-// specific_attr_iterator iterates over enable_if attributes in reverse, and
-// enable_if is order-sensitive. As a result, we need to reverse things
-// sometimes. Size of 4 elements is arbitrary.
-static SmallVector<EnableIfAttr *, 4>
-getOrderedEnableIfAttrs(const FunctionDecl *Function) {
- SmallVector<EnableIfAttr *, 4> Result;
- if (!Function->hasAttrs())
- return Result;
-
- const auto &FuncAttrs = Function->getAttrs();
- for (Attr *Attr : FuncAttrs)
- if (auto *EnableIf = dyn_cast<EnableIfAttr>(Attr))
- Result.push_back(EnableIf);
-
- std::reverse(Result.begin(), Result.end());
- return Result;
-}
-
static bool
convertArgsForAvailabilityChecks(Sema &S, FunctionDecl *Function, Expr *ThisArg,
ArrayRef<Expr *> Args, Sema::SFINAETrap &Trap,
@@ -6306,9 +6349,8 @@ convertArgsForAvailabilityChecks(Sema &S, FunctionDecl *Function, Expr *ThisArg,
EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
bool MissingImplicitThis) {
- SmallVector<EnableIfAttr *, 4> EnableIfAttrs =
- getOrderedEnableIfAttrs(Function);
- if (EnableIfAttrs.empty())
+ auto EnableIfAttrs = Function->specific_attrs<EnableIfAttr>();
+ if (EnableIfAttrs.begin() == EnableIfAttrs.end())
return nullptr;
SFINAETrap Trap(*this);
@@ -6318,7 +6360,7 @@ EnableIfAttr *Sema::CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args,
if (!convertArgsForAvailabilityChecks(
*this, Function, /*ThisArg=*/nullptr, Args, Trap,
/*MissingImplicitThis=*/true, DiscardedThis, ConvertedArgs))
- return EnableIfAttrs[0];
+ return *EnableIfAttrs.begin();
for (auto *EIA : EnableIfAttrs) {
APValue Result;
@@ -6427,7 +6469,12 @@ void Sema::AddFunctionCandidates(const UnresolvedSetImpl &Fns,
if (Expr *E = Args[0]) {
// Use the explicit base to restrict the lookup:
ObjectType = E->getType();
- ObjectClassification = E->Classify(Context);
+ // Pointers in the object arguments are implicitly dereferenced, so we
+ // always classify them as l-values.
+ if (!ObjectType.isNull() && ObjectType->isPointerType())
+ ObjectClassification = Expr::Classification::makeSimpleLValue();
+ else
+ ObjectClassification = E->Classify(Context);
} // .. else there is an implicit base.
FunctionArgs = Args.slice(1);
}
@@ -6708,14 +6755,11 @@ Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
/// Add a C++ function template specialization as a candidate
/// in the candidate set, using template argument deduction to produce
/// an appropriate function template specialization.
-void
-Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
- DeclAccessPair FoundDecl,
- TemplateArgumentListInfo *ExplicitTemplateArgs,
- ArrayRef<Expr *> Args,
- OverloadCandidateSet& CandidateSet,
- bool SuppressUserConversions,
- bool PartialOverloading) {
+void Sema::AddTemplateOverloadCandidate(
+ FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
+ TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
+ OverloadCandidateSet &CandidateSet, bool SuppressUserConversions,
+ bool PartialOverloading, ADLCallKind IsADLCandidate) {
if (!CandidateSet.isNewCandidate(FunctionTemplate))
return;
@@ -6744,6 +6788,7 @@ Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
Candidate.Function = FunctionTemplate->getTemplatedDecl();
Candidate.Viable = false;
Candidate.IsSurrogate = false;
+ Candidate.IsADLCandidate = IsADLCandidate;
// Ignore the object argument if there is one, since we don't have an object
// type.
Candidate.IgnoreObjectArgument =
@@ -6765,7 +6810,7 @@ Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
assert(Specialization && "Missing function template specialization?");
AddOverloadCandidate(Specialization, FoundDecl, Args, CandidateSet,
SuppressUserConversions, PartialOverloading,
- /*AllowExplicit*/false, Conversions);
+ /*AllowExplicit*/ false, IsADLCandidate, Conversions);
}
/// Check that implicit conversion sequences can be formed for each argument
@@ -6966,15 +7011,15 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion,
// lvalues/rvalues and the type. Fortunately, we can allocate this
// call on the stack and we don't need its arguments to be
// well-formed.
- DeclRefExpr ConversionRef(Conversion, false, Conversion->getType(),
- VK_LValue, From->getLocStart());
+ DeclRefExpr ConversionRef(Context, Conversion, false, Conversion->getType(),
+ VK_LValue, From->getBeginLoc());
ImplicitCastExpr ConversionFn(ImplicitCastExpr::OnStack,
Context.getPointerType(Conversion->getType()),
CK_FunctionToPointerDecay,
&ConversionRef, VK_RValue);
QualType ConversionType = Conversion->getConversionType();
- if (!isCompleteType(From->getLocStart(), ConversionType)) {
+ if (!isCompleteType(From->getBeginLoc(), ConversionType)) {
Candidate.Viable = false;
Candidate.FailureKind = ovl_fail_bad_final_conversion;
return;
@@ -6986,13 +7031,17 @@ Sema::AddConversionCandidate(CXXConversionDecl *Conversion,
// there are 0 arguments (i.e., nothing is allocated using ASTContext's
// allocator).
QualType CallResultType = ConversionType.getNonLValueExprType(Context);
- CallExpr Call(Context, &ConversionFn, None, CallResultType, VK,
- From->getLocStart());
+
+ llvm::AlignedCharArray<alignof(CallExpr), sizeof(CallExpr) + sizeof(Stmt *)>
+ Buffer;
+ CallExpr *TheTemporaryCall = CallExpr::CreateTemporary(
+ Buffer.buffer, &ConversionFn, CallResultType, VK, From->getBeginLoc());
+
ImplicitConversionSequence ICS =
- TryCopyInitialization(*this, &Call, ToType,
- /*SuppressUserConversions=*/true,
- /*InOverloadResolution=*/false,
- /*AllowObjCWritebackConversion=*/false);
+ TryCopyInitialization(*this, TheTemporaryCall, ToType,
+ /*SuppressUserConversions=*/true,
+ /*InOverloadResolution=*/false,
+ /*AllowObjCWritebackConversion=*/false);
switch (ICS.getKind()) {
case ImplicitConversionSequence::StandardConversion:
@@ -8928,16 +8977,20 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
// set.
for (ADLResult::iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) {
DeclAccessPair FoundDecl = DeclAccessPair::make(*I, AS_none);
+
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
if (ExplicitTemplateArgs)
continue;
- AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet, false,
- PartialOverloading);
- } else
- AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*I),
- FoundDecl, ExplicitTemplateArgs,
- Args, CandidateSet, PartialOverloading);
+ AddOverloadCandidate(FD, FoundDecl, Args, CandidateSet,
+ /*SupressUserConversions=*/false, PartialOverloading,
+ /*AllowExplicit=*/false, ADLCallKind::UsesADL);
+ } else {
+ AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*I), FoundDecl,
+ ExplicitTemplateArgs, Args, CandidateSet,
+ /*SupressUserConversions=*/false,
+ PartialOverloading, ADLCallKind::UsesADL);
+ }
}
}
@@ -8967,31 +9020,31 @@ static Comparison compareEnableIfAttrs(const Sema &S, const FunctionDecl *Cand1,
return Cand1Attr ? Comparison::Better : Comparison::Worse;
}
- // FIXME: The next several lines are just
- // specific_attr_iterator<EnableIfAttr> but going in declaration order,
- // instead of reverse order which is how they're stored in the AST.
- auto Cand1Attrs = getOrderedEnableIfAttrs(Cand1);
- auto Cand2Attrs = getOrderedEnableIfAttrs(Cand2);
-
- // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1
- // has fewer enable_if attributes than Cand2.
- if (Cand1Attrs.size() < Cand2Attrs.size())
- return Comparison::Worse;
+ auto Cand1Attrs = Cand1->specific_attrs<EnableIfAttr>();
+ auto Cand2Attrs = Cand2->specific_attrs<EnableIfAttr>();
- auto Cand1I = Cand1Attrs.begin();
llvm::FoldingSetNodeID Cand1ID, Cand2ID;
- for (auto &Cand2A : Cand2Attrs) {
+ for (auto Pair : zip_longest(Cand1Attrs, Cand2Attrs)) {
+ Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair);
+ Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair);
+
+ // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1
+ // has fewer enable_if attributes than Cand2, and vice versa.
+ if (!Cand1A)
+ return Comparison::Worse;
+ if (!Cand2A)
+ return Comparison::Better;
+
Cand1ID.clear();
Cand2ID.clear();
- auto &Cand1A = *Cand1I++;
- Cand1A->getCond()->Profile(Cand1ID, S.getASTContext(), true);
- Cand2A->getCond()->Profile(Cand2ID, S.getASTContext(), true);
+ (*Cand1A)->getCond()->Profile(Cand1ID, S.getASTContext(), true);
+ (*Cand2A)->getCond()->Profile(Cand2ID, S.getASTContext(), true);
if (Cand1ID != Cand2ID)
return Comparison::Worse;
}
- return Cand1I == Cand1Attrs.end() ? Comparison::Equal : Comparison::Better;
+ return Comparison::Equal;
}
static bool isBetterMultiversionCandidate(const OverloadCandidate &Cand1,
@@ -9000,6 +9053,11 @@ static bool isBetterMultiversionCandidate(const OverloadCandidate &Cand1,
!Cand2.Function->isMultiVersion())
return false;
+ // If Cand1 is invalid, it cannot be a better match, if Cand2 is invalid, this
+ // is obviously better.
+ if (Cand1.Function->isInvalidDecl()) return false;
+ if (Cand2.Function->isInvalidDecl()) return true;
+
// If this is a cpu_dispatch/cpu_specific multiversion situation, prefer
// cpu_dispatch, else arbitrarily based on the identifiers.
bool Cand1CPUDisp = Cand1.Function->hasAttr<CPUDispatchAttr>();
@@ -9506,7 +9564,7 @@ static bool checkAddressOfFunctionIsAvailable(Sema &S, const FunctionDecl *FD,
if (!isFunctionAlwaysEnabled(S.Context, FD)) {
if (Complain) {
if (InOverloadResolution)
- S.Diag(FD->getLocStart(),
+ S.Diag(FD->getBeginLoc(),
diag::note_addrof_ovl_candidate_disabled_by_enable_if_attr);
else
S.Diag(Loc, diag::err_addrof_function_disabled_by_enable_if_attr) << FD;
@@ -10010,7 +10068,7 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
DeductionFailure.getFirstArg()->getNonTypeTemplateArgumentType();
QualType T2 =
DeductionFailure.getSecondArg()->getNonTypeTemplateArgumentType();
- if (!S.Context.hasSameType(T1, T2)) {
+ if (!T1.isNull() && !T2.isNull() && !S.Context.hasSameType(T1, T2)) {
S.Diag(Templated->getLocation(),
diag::note_ovl_candidate_inconsistent_deduction_types)
<< ParamD->getDeclName() << *DeductionFailure.getFirstArg() << T1
@@ -10268,7 +10326,8 @@ static void DiagnoseOpenCLExtensionDisabled(Sema &S, OverloadCandidate *Cand) {
FunctionDecl *Callee = Cand->Function;
S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension);
+ diag::note_ovl_candidate_disabled_by_extension)
+ << S.getOpenCLExtensionsFromDeclExtMap(Callee);
}
/// Generates a 'note' diagnostic for an overload candidate. We've
@@ -10836,8 +10895,7 @@ void TemplateSpecCandidateSet::NoteCandidates(Sema &S, SourceLocation Loc) {
// in general, want to list every possible builtin candidate.
}
- llvm::sort(Cands.begin(), Cands.end(),
- CompareTemplateSpecCandidatesForDisplay(S));
+ llvm::sort(Cands, CompareTemplateSpecCandidatesForDisplay(S));
// FIXME: Perhaps rename OverloadsShown and getShowOverloads()
// for generalization purposes (?).
@@ -11023,7 +11081,7 @@ private:
// Note: We explicitly leave Matches unmodified if there isn't a clear best
// option, so we can potentially give the user a better error
- if (!std::all_of(Matches.begin(), Matches.end(), IsBestOrInferiorToBest))
+ if (!llvm::all_of(Matches, IsBestOrInferiorToBest))
return false;
Matches[0] = *Best;
Matches.resize(1);
@@ -11114,7 +11172,7 @@ private:
// If any candidate has a placeholder return type, trigger its deduction
// now.
- if (completeFunctionType(S, FunDecl, SourceExpr->getLocStart(),
+ if (completeFunctionType(S, FunDecl, SourceExpr->getBeginLoc(),
Complain)) {
HasComplained |= Complain;
return false;
@@ -11190,7 +11248,7 @@ private:
// here, since the no_viable diagnostic has index 0.
UnresolvedSetIterator Result = S.getMostSpecialized(
MatchesCopy.begin(), MatchesCopy.end(), FailedCandidates,
- SourceExpr->getLocStart(), S.PDiag(),
+ SourceExpr->getBeginLoc(), S.PDiag(),
S.PDiag(diag::err_addr_ovl_ambiguous)
<< Matches[0].second->getDeclName(),
S.PDiag(diag::note_ovl_candidate)
@@ -11226,7 +11284,7 @@ private:
public:
void ComplainNoMatchesFound() const {
assert(Matches.empty());
- S.Diag(OvlExpr->getLocStart(), diag::err_addr_ovl_no_viable)
+ S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_no_viable)
<< OvlExpr->getName() << TargetFunctionType
<< OvlExpr->getSourceRange();
if (FailedCandidates.empty())
@@ -11244,7 +11302,7 @@ public:
if (!functionHasPassObjectSizeParams(Fun))
S.NoteOverloadCandidate(*I, Fun, TargetFunctionType,
/*TakingAddress=*/true);
- FailedCandidates.NoteCandidates(S, OvlExpr->getLocStart());
+ FailedCandidates.NoteCandidates(S, OvlExpr->getBeginLoc());
}
}
@@ -11266,21 +11324,20 @@ public:
}
void ComplainIsStaticMemberFunctionFromBoundPointer() const {
- S.Diag(OvlExpr->getLocStart(),
+ S.Diag(OvlExpr->getBeginLoc(),
diag::err_invalid_form_pointer_member_function)
- << OvlExpr->getSourceRange();
+ << OvlExpr->getSourceRange();
}
void ComplainOfInvalidConversion() const {
- S.Diag(OvlExpr->getLocStart(), diag::err_addr_ovl_not_func_ptrref)
- << OvlExpr->getName() << TargetType;
+ S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_not_func_ptrref)
+ << OvlExpr->getName() << TargetType;
}
void ComplainMultipleMatchesFound() const {
assert(Matches.size() > 1);
- S.Diag(OvlExpr->getLocStart(), diag::err_addr_ovl_ambiguous)
- << OvlExpr->getName()
- << OvlExpr->getSourceRange();
+ S.Diag(OvlExpr->getBeginLoc(), diag::err_addr_ovl_ambiguous)
+ << OvlExpr->getName() << OvlExpr->getSourceRange();
S.NoteAllOverloadCandidates(OvlExpr, TargetFunctionType,
/*TakingAddress=*/true);
}
@@ -11530,7 +11587,7 @@ bool Sema::ResolveAndFixSingleFunctionTemplateSpecialization(
ExprResult SingleFunctionExpression;
if (FunctionDecl *fn = ResolveSingleFunctionTemplateSpecialization(
ovl.Expression, /*complain*/ false, &found)) {
- if (DiagnoseUseOfDecl(fn, SrcExpr.get()->getLocStart())) {
+ if (DiagnoseUseOfDecl(fn, SrcExpr.get()->getBeginLoc())) {
SrcExpr = ExprError();
return true;
}
@@ -11966,14 +12023,14 @@ bool Sema::buildOverloadedCallSet(Scope *S, Expr *Fn,
OverloadCandidateSet::iterator Best;
if (CandidateSet->empty() ||
- CandidateSet->BestViableFunction(*this, Fn->getLocStart(), Best) ==
+ CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best) ==
OR_No_Viable_Function) {
- // In Microsoft mode, if we are inside a template class member function then
- // create a type dependent CallExpr. The goal is to postpone name lookup
- // to instantiation time to be able to search into type dependent base
- // classes.
- CallExpr *CE = new (Context) CallExpr(
- Context, Fn, Args, Context.DependentTy, VK_RValue, RParenLoc);
+ // In Microsoft mode, if we are inside a template class member function
+ // then create a type dependent CallExpr. The goal is to postpone name
+ // lookup to instantiation time to be able to search into type dependent
+ // base classes.
+ CallExpr *CE = CallExpr::Create(Context, Fn, Args, Context.DependentTy,
+ VK_RValue, RParenLoc);
CE->setTypeDependent(true);
CE->setValueDependent(true);
CE->setInstantiationDependent(true);
@@ -12015,7 +12072,8 @@ static ExprResult FinishOverloadedCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
return ExprError();
Fn = SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl);
return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc,
- ExecConfig);
+ ExecConfig, /*IsExecConfig=*/false,
+ (*Best)->IsADLCandidate);
}
case OR_No_Viable_Function: {
@@ -12043,24 +12101,23 @@ static ExprResult FinishOverloadedCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
}
}
- SemaRef.Diag(Fn->getLocStart(), diag::err_ovl_no_viable_function_in_call)
+ SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_no_viable_function_in_call)
<< ULE->getName() << Fn->getSourceRange();
CandidateSet->NoteCandidates(SemaRef, OCD_AllCandidates, Args);
break;
}
case OR_Ambiguous:
- SemaRef.Diag(Fn->getLocStart(), diag::err_ovl_ambiguous_call)
- << ULE->getName() << Fn->getSourceRange();
+ SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_ambiguous_call)
+ << ULE->getName() << Fn->getSourceRange();
CandidateSet->NoteCandidates(SemaRef, OCD_ViableCandidates, Args);
break;
case OR_Deleted: {
- SemaRef.Diag(Fn->getLocStart(), diag::err_ovl_deleted_call)
- << (*Best)->Function->isDeleted()
- << ULE->getName()
- << SemaRef.getDeletedOrUnavailableSuffix((*Best)->Function)
- << Fn->getSourceRange();
+ SemaRef.Diag(Fn->getBeginLoc(), diag::err_ovl_deleted_call)
+ << (*Best)->Function->isDeleted() << ULE->getName()
+ << SemaRef.getDeletedOrUnavailableSuffix((*Best)->Function)
+ << Fn->getSourceRange();
CandidateSet->NoteCandidates(SemaRef, OCD_AllCandidates, Args);
// We emitted an error for the unavailable/deleted function call but keep
@@ -12068,7 +12125,8 @@ static ExprResult FinishOverloadedCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
FunctionDecl *FDecl = (*Best)->Function;
Fn = SemaRef.FixOverloadedFunctionReference(Fn, (*Best)->FoundDecl, FDecl);
return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc,
- ExecConfig);
+ ExecConfig, /*IsExecConfig=*/false,
+ (*Best)->IsADLCandidate);
}
}
@@ -12116,7 +12174,7 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn,
OverloadCandidateSet::iterator Best;
OverloadingResult OverloadResult =
- CandidateSet.BestViableFunction(*this, Fn->getLocStart(), Best);
+ CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
return FinishOverloadedCallExpr(*this, S, Fn, ULE, LParenLoc, Args,
RParenLoc, ExecConfig, &CandidateSet,
@@ -12178,14 +12236,12 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
VK_RValue, OK_Ordinary, OpLoc, false);
CXXRecordDecl *NamingClass = nullptr; // lookup ignores member operators
- UnresolvedLookupExpr *Fn
- = UnresolvedLookupExpr::Create(Context, NamingClass,
- NestedNameSpecifierLoc(), OpNameInfo,
- /*ADL*/ true, IsOverloaded(Fns),
- Fns.begin(), Fns.end());
- return new (Context)
- CXXOperatorCallExpr(Context, Op, Fn, ArgsArray, Context.DependentTy,
- VK_RValue, OpLoc, FPOptions());
+ UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create(
+ Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo,
+ /*ADL*/ true, IsOverloaded(Fns), Fns.begin(), Fns.end());
+ return CXXOperatorCallExpr::Create(Context, Op, Fn, ArgsArray,
+ Context.DependentTy, VK_RValue, OpLoc,
+ FPOptions());
}
// Build an empty overload set.
@@ -12257,9 +12313,9 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
ResultTy = ResultTy.getNonLValueExprType(Context);
Args[0] = Input;
- CallExpr *TheCall =
- new (Context) CXXOperatorCallExpr(Context, Op, FnExpr.get(), ArgsArray,
- ResultTy, VK, OpLoc, FPOptions());
+ CallExpr *TheCall = CXXOperatorCallExpr::Create(
+ Context, Op, FnExpr.get(), ArgsArray, ResultTy, VK, OpLoc,
+ FPOptions(), Best->IsADLCandidate);
if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall, FnDecl))
return ExprError();
@@ -12369,14 +12425,12 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
CXXRecordDecl *NamingClass = nullptr; // lookup ignores member operators
// TODO: provide better source location info in DNLoc component.
DeclarationNameInfo OpNameInfo(OpName, OpLoc);
- UnresolvedLookupExpr *Fn
- = UnresolvedLookupExpr::Create(Context, NamingClass,
- NestedNameSpecifierLoc(), OpNameInfo,
- /*ADL*/PerformADL, IsOverloaded(Fns),
- Fns.begin(), Fns.end());
- return new (Context)
- CXXOperatorCallExpr(Context, Op, Fn, Args, Context.DependentTy,
- VK_RValue, OpLoc, FPFeatures);
+ UnresolvedLookupExpr *Fn = UnresolvedLookupExpr::Create(
+ Context, NamingClass, NestedNameSpecifierLoc(), OpNameInfo,
+ /*ADL*/ PerformADL, IsOverloaded(Fns), Fns.begin(), Fns.end());
+ return CXXOperatorCallExpr::Create(Context, Op, Fn, Args,
+ Context.DependentTy, VK_RValue, OpLoc,
+ FPFeatures);
}
// Always do placeholder-like conversions on the RHS.
@@ -12489,10 +12543,9 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
ResultTy = ResultTy.getNonLValueExprType(Context);
- CXXOperatorCallExpr *TheCall =
- new (Context) CXXOperatorCallExpr(Context, Op, FnExpr.get(),
- Args, ResultTy, VK, OpLoc,
- FPFeatures);
+ CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create(
+ Context, Op, FnExpr.get(), Args, ResultTy, VK, OpLoc, FPFeatures,
+ Best->IsADLCandidate);
if (CheckCallReturnType(FnDecl->getReturnType(), OpLoc, TheCall,
FnDecl))
@@ -12638,9 +12691,9 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
UnresolvedSetIterator());
// Can't add any actual overloads yet
- return new (Context)
- CXXOperatorCallExpr(Context, OO_Subscript, Fn, Args,
- Context.DependentTy, VK_RValue, RLoc, FPOptions());
+ return CXXOperatorCallExpr::Create(Context, OO_Subscript, Fn, Args,
+ Context.DependentTy, VK_RValue, RLoc,
+ FPOptions());
}
// Handle placeholders on both operands.
@@ -12714,10 +12767,8 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
ResultTy = ResultTy.getNonLValueExprType(Context);
CXXOperatorCallExpr *TheCall =
- new (Context) CXXOperatorCallExpr(Context, OO_Subscript,
- FnExpr.get(), Args,
- ResultTy, VK, RLoc,
- FPOptions());
+ CXXOperatorCallExpr::Create(Context, OO_Subscript, FnExpr.get(),
+ Args, ResultTy, VK, RLoc, FPOptions());
if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl))
return ExprError();
@@ -12819,7 +12870,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
// Check that the object type isn't more qualified than the
// member function we're calling.
- Qualifiers funcQuals = Qualifiers::fromCVRMask(proto->getTypeQuals());
+ Qualifiers funcQuals = proto->getTypeQuals();
QualType objectType = op->getLHS()->getType();
if (op->getOpcode() == BO_PtrMemI)
@@ -12837,11 +12888,11 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
<< (qualsString.find(' ') == std::string::npos ? 1 : 2);
}
- CXXMemberCallExpr *call
- = new (Context) CXXMemberCallExpr(Context, MemExprE, Args,
- resultType, valueKind, RParenLoc);
+ CXXMemberCallExpr *call =
+ CXXMemberCallExpr::Create(Context, MemExprE, Args, resultType,
+ valueKind, RParenLoc, proto->getNumParams());
- if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getLocStart(),
+ if (CheckCallReturnType(proto->getReturnType(), op->getRHS()->getBeginLoc(),
call, nullptr))
return ExprError();
@@ -12855,8 +12906,8 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
}
if (isa<CXXPseudoDestructorExpr>(NakedMemExpr))
- return new (Context)
- CallExpr(Context, MemExprE, Args, Context.VoidTy, VK_RValue, RParenLoc);
+ return CallExpr::Create(Context, MemExprE, Args, Context.VoidTy, VK_RValue,
+ RParenLoc);
UnbridgedCastsSet UnbridgedCasts;
if (checkArgPlaceholdersForOverload(*this, Args, UnbridgedCasts))
@@ -12927,7 +12978,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
UnbridgedCasts.restore();
OverloadCandidateSet::iterator Best;
- switch (CandidateSet.BestViableFunction(*this, UnresExpr->getLocStart(),
+ switch (CandidateSet.BestViableFunction(*this, UnresExpr->getBeginLoc(),
Best)) {
case OR_Success:
Method = cast<CXXMethodDecl>(Best->Function);
@@ -12989,9 +13040,10 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
ResultType = ResultType.getNonLValueExprType(Context);
assert(Method && "Member call to something that isn't a method?");
+ const auto *Proto = Method->getType()->getAs<FunctionProtoType>();
CXXMemberCallExpr *TheCall =
- new (Context) CXXMemberCallExpr(Context, MemExprE, Args,
- ResultType, VK, RParenLoc);
+ CXXMemberCallExpr::Create(Context, MemExprE, Args, ResultType, VK,
+ RParenLoc, Proto->getNumParams());
// Check for a valid return type.
if (CheckCallReturnType(Method->getReturnType(), MemExpr->getMemberLoc(),
@@ -13011,8 +13063,6 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
}
// Convert the rest of the arguments
- const FunctionProtoType *Proto =
- Method->getType()->getAs<FunctionProtoType>();
if (ConvertArgumentsForCall(TheCall, MemExpr, Method, Proto, Args,
RParenLoc))
return ExprError();
@@ -13044,17 +13094,15 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
if (isa<CXXThisExpr>(MemExpr->getBase()->IgnoreParenCasts()) &&
MemExpr->performsVirtualDispatch(getLangOpts())) {
- Diag(MemExpr->getLocStart(),
+ Diag(MemExpr->getBeginLoc(),
diag::warn_call_to_pure_virtual_member_function_from_ctor_dtor)
- << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext)
- << MD->getParent()->getDeclName();
+ << MD->getDeclName() << isa<CXXDestructorDecl>(CurContext)
+ << MD->getParent()->getDeclName();
- Diag(MD->getLocStart(), diag::note_previous_decl) << MD->getDeclName();
+ Diag(MD->getBeginLoc(), diag::note_previous_decl) << MD->getDeclName();
if (getLangOpts().AppleKext)
- Diag(MemExpr->getLocStart(),
- diag::note_pure_qualified_call_kext)
- << MD->getParent()->getDeclName()
- << MD->getDeclName();
+ Diag(MemExpr->getBeginLoc(), diag::note_pure_qualified_call_kext)
+ << MD->getParent()->getDeclName() << MD->getDeclName();
}
}
@@ -13062,7 +13110,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
dyn_cast<CXXDestructorDecl>(TheCall->getMethodDecl())) {
// a->A::f() doesn't go through the vtable, except in AppleKext mode.
bool CallCanBeVirtual = !MemExpr->hasQualifier() || getLangOpts().AppleKext;
- CheckVirtualDtorCall(DD, MemExpr->getLocStart(), /*IsDelete=*/false,
+ CheckVirtualDtorCall(DD, MemExpr->getBeginLoc(), /*IsDelete=*/false,
CallCanBeVirtual, /*WarnOnNonAbstractTypes=*/true,
MemExpr->getMemberLoc());
}
@@ -13167,7 +13215,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
// Perform overload resolution.
OverloadCandidateSet::iterator Best;
- switch (CandidateSet.BestViableFunction(*this, Object.get()->getLocStart(),
+ switch (CandidateSet.BestViableFunction(*this, Object.get()->getBeginLoc(),
Best)) {
case OR_Success:
// Overload resolution succeeded; we'll build the appropriate call
@@ -13176,30 +13224,26 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
case OR_No_Viable_Function:
if (CandidateSet.empty())
- Diag(Object.get()->getLocStart(), diag::err_ovl_no_oper)
- << Object.get()->getType() << /*call*/ 1
- << Object.get()->getSourceRange();
+ Diag(Object.get()->getBeginLoc(), diag::err_ovl_no_oper)
+ << Object.get()->getType() << /*call*/ 1
+ << Object.get()->getSourceRange();
else
- Diag(Object.get()->getLocStart(),
- diag::err_ovl_no_viable_object_call)
- << Object.get()->getType() << Object.get()->getSourceRange();
+ Diag(Object.get()->getBeginLoc(), diag::err_ovl_no_viable_object_call)
+ << Object.get()->getType() << Object.get()->getSourceRange();
CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args);
break;
case OR_Ambiguous:
- Diag(Object.get()->getLocStart(),
- diag::err_ovl_ambiguous_object_call)
- << Object.get()->getType() << Object.get()->getSourceRange();
+ Diag(Object.get()->getBeginLoc(), diag::err_ovl_ambiguous_object_call)
+ << Object.get()->getType() << Object.get()->getSourceRange();
CandidateSet.NoteCandidates(*this, OCD_ViableCandidates, Args);
break;
case OR_Deleted:
- Diag(Object.get()->getLocStart(),
- diag::err_ovl_deleted_object_call)
- << Best->Function->isDeleted()
- << Object.get()->getType()
- << getDeletedOrUnavailableSuffix(Best->Function)
- << Object.get()->getSourceRange();
+ Diag(Object.get()->getBeginLoc(), diag::err_ovl_deleted_object_call)
+ << Best->Function->isDeleted() << Object.get()->getType()
+ << getDeletedOrUnavailableSuffix(Best->Function)
+ << Object.get()->getSourceRange();
CandidateSet.NoteCandidates(*this, OCD_AllCandidates, Args);
break;
}
@@ -13266,29 +13310,14 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
if (NewFn.isInvalid())
return true;
+ // The number of argument slots to allocate in the call. If we have default
+ // arguments we need to allocate space for them as well. We additionally
+ // need one more slot for the object parameter.
+ unsigned NumArgsSlots = 1 + std::max<unsigned>(Args.size(), NumParams);
+
// Build the full argument list for the method call (the implicit object
// parameter is placed at the beginning of the list).
- SmallVector<Expr *, 8> MethodArgs(Args.size() + 1);
- MethodArgs[0] = Object.get();
- std::copy(Args.begin(), Args.end(), MethodArgs.begin() + 1);
-
- // Once we've built TheCall, all of the expressions are properly
- // owned.
- QualType ResultTy = Method->getReturnType();
- ExprValueKind VK = Expr::getValueKindForType(ResultTy);
- ResultTy = ResultTy.getNonLValueExprType(Context);
-
- CXXOperatorCallExpr *TheCall = new (Context)
- CXXOperatorCallExpr(Context, OO_Call, NewFn.get(), MethodArgs, ResultTy,
- VK, RParenLoc, FPOptions());
-
- if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
- return true;
-
- // We may have default arguments. If so, we need to allocate more
- // slots in the call for them.
- if (Args.size() < NumParams)
- TheCall->setNumArgs(Context, NumParams + 1);
+ SmallVector<Expr *, 8> MethodArgs(NumArgsSlots);
bool IsError = false;
@@ -13300,7 +13329,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
IsError = true;
else
Object = ObjRes;
- TheCall->setArg(0, Object.get());
+ MethodArgs[0] = Object.get();
// Check the argument types.
for (unsigned i = 0; i != NumParams; i++) {
@@ -13329,7 +13358,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
Arg = DefArg.getAs<Expr>();
}
- TheCall->setArg(i + 1, Arg);
+ MethodArgs[i + 1] = Arg;
}
// If this is a variadic call, handle args passed through "...".
@@ -13339,14 +13368,27 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
ExprResult Arg = DefaultVariadicArgumentPromotion(Args[i], VariadicMethod,
nullptr);
IsError |= Arg.isInvalid();
- TheCall->setArg(i + 1, Arg.get());
+ MethodArgs[i + 1] = Arg.get();
}
}
- if (IsError) return true;
+ if (IsError)
+ return true;
DiagnoseSentinelCalls(Method, LParenLoc, Args);
+ // Once we've built TheCall, all of the expressions are properly owned.
+ QualType ResultTy = Method->getReturnType();
+ ExprValueKind VK = Expr::getValueKindForType(ResultTy);
+ ResultTy = ResultTy.getNonLValueExprType(Context);
+
+ CXXOperatorCallExpr *TheCall =
+ CXXOperatorCallExpr::Create(Context, OO_Call, NewFn.get(), MethodArgs,
+ ResultTy, VK, RParenLoc, FPOptions());
+
+ if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
+ return true;
+
if (CheckFunctionCall(Method, TheCall, Proto))
return true;
@@ -13458,9 +13500,8 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
QualType ResultTy = Method->getReturnType();
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
ResultTy = ResultTy.getNonLValueExprType(Context);
- CXXOperatorCallExpr *TheCall =
- new (Context) CXXOperatorCallExpr(Context, OO_Arrow, FnExpr.get(),
- Base, ResultTy, VK, OpLoc, FPOptions());
+ CXXOperatorCallExpr *TheCall = CXXOperatorCallExpr::Create(
+ Context, OO_Arrow, FnExpr.get(), Base, ResultTy, VK, OpLoc, FPOptions());
if (CheckCallReturnType(Method->getReturnType(), OpLoc, TheCall, Method))
return ExprError();
@@ -13532,10 +13573,9 @@ ExprResult Sema::BuildLiteralOperatorCall(LookupResult &R,
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
ResultTy = ResultTy.getNonLValueExprType(Context);
- UserDefinedLiteral *UDL =
- new (Context) UserDefinedLiteral(Context, Fn.get(),
- llvm::makeArrayRef(ConvArgs, Args.size()),
- ResultTy, VK, LitEndLoc, UDSuffixLoc);
+ UserDefinedLiteral *UDL = UserDefinedLiteral::Create(
+ Context, Fn.get(), llvm::makeArrayRef(ConvArgs, Args.size()), ResultTy,
+ VK, LitEndLoc, UDSuffixLoc);
if (CheckCallReturnType(FD->getReturnType(), UDSuffixLoc, UDL, FD))
return ExprError();
@@ -13596,7 +13636,7 @@ Sema::BuildForRangeBeginEndCall(SourceLocation Loc,
}
OverloadCandidateSet::iterator Best;
OverloadingResult OverloadResult =
- CandidateSet->BestViableFunction(*this, Fn->getLocStart(), Best);
+ CandidateSet->BestViableFunction(*this, Fn->getBeginLoc(), Best);
if (OverloadResult == OR_No_Viable_Function) {
*CallExpr = ExprError();