@@ -5664,10 +5664,15 @@ static ImplicitConversionSequence TryObjectArgumentInitialization(
5664
5664
assert(FromType->isRecordType());
5665
5665
5666
5666
QualType ClassType = S.Context.getTypeDeclType(ActingContext);
5667
- // [class.dtor]p2: A destructor can be invoked for a const, volatile or
5668
- // const volatile object.
5667
+ // C++98 [class.dtor]p2:
5668
+ // A destructor can be invoked for a const, volatile or const volatile
5669
+ // object.
5670
+ // C++98 [over.match.funcs]p4:
5671
+ // For static member functions, the implicit object parameter is considered
5672
+ // to match any object (since if the function is selected, the object is
5673
+ // discarded).
5669
5674
Qualifiers Quals = Method->getMethodQualifiers();
5670
- if (isa<CXXDestructorDecl>(Method)) {
5675
+ if (isa<CXXDestructorDecl>(Method) || Method->isStatic() ) {
5671
5676
Quals.addConst();
5672
5677
Quals.addVolatile();
5673
5678
}
@@ -15061,15 +15066,15 @@ ExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
15061
15066
CXXMethodDecl *Method = cast<CXXMethodDecl>(FnDecl);
15062
15067
SmallVector<Expr *, 2> MethodArgs;
15063
15068
15064
- // Handle 'this' parameter if the selected function is not static .
15069
+ // Initialize the object parameter .
15065
15070
if (Method->isExplicitObjectMemberFunction()) {
15066
15071
ExprResult Res =
15067
15072
InitializeExplicitObjectArgument(*this, Args[0], Method);
15068
15073
if (Res.isInvalid())
15069
15074
return ExprError();
15070
15075
Args[0] = Res.get();
15071
15076
ArgExpr = Args;
15072
- } else if (Method->isInstance()) {
15077
+ } else {
15073
15078
ExprResult Arg0 = PerformImplicitObjectArgumentInitialization(
15074
15079
Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method);
15075
15080
if (Arg0.isInvalid())
@@ -15097,15 +15102,9 @@ ExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
15097
15102
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
15098
15103
ResultTy = ResultTy.getNonLValueExprType(Context);
15099
15104
15100
- CallExpr *TheCall;
15101
- if (Method->isInstance())
15102
- TheCall = CXXOperatorCallExpr::Create(
15103
- Context, OO_Subscript, FnExpr.get(), MethodArgs, ResultTy, VK,
15104
- RLoc, CurFPFeatureOverrides());
15105
- else
15106
- TheCall =
15107
- CallExpr::Create(Context, FnExpr.get(), MethodArgs, ResultTy, VK,
15108
- RLoc, CurFPFeatureOverrides());
15105
+ CallExpr *TheCall = CXXOperatorCallExpr::Create(
15106
+ Context, OO_Subscript, FnExpr.get(), MethodArgs, ResultTy, VK, RLoc,
15107
+ CurFPFeatureOverrides());
15109
15108
15110
15109
if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl))
15111
15110
return ExprError();
@@ -15733,15 +15732,13 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
15733
15732
15734
15733
bool IsError = false;
15735
15734
15736
- // Initialize the implicit object parameter if needed.
15737
- // Since C++23, this could also be a call to a static call operator
15738
- // which we emit as a regular CallExpr.
15735
+ // Initialize the object parameter.
15739
15736
llvm::SmallVector<Expr *, 8> NewArgs;
15740
15737
if (Method->isExplicitObjectMemberFunction()) {
15741
15738
// FIXME: we should do that during the definition of the lambda when we can.
15742
15739
DiagnoseInvalidExplicitObjectParameterInLambda(Method);
15743
15740
PrepareExplicitObjectArgument(*this, Method, Obj, Args, NewArgs);
15744
- } else if (Method->isInstance()) {
15741
+ } else {
15745
15742
ExprResult ObjRes = PerformImplicitObjectArgumentInitialization(
15746
15743
Object.get(), /*Qualifier=*/nullptr, Best->FoundDecl, Method);
15747
15744
if (ObjRes.isInvalid())
@@ -15775,14 +15772,9 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
15775
15772
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
15776
15773
ResultTy = ResultTy.getNonLValueExprType(Context);
15777
15774
15778
- CallExpr *TheCall;
15779
- if (Method->isInstance())
15780
- TheCall = CXXOperatorCallExpr::Create(Context, OO_Call, NewFn.get(),
15781
- MethodArgs, ResultTy, VK, RParenLoc,
15782
- CurFPFeatureOverrides());
15783
- else
15784
- TheCall = CallExpr::Create(Context, NewFn.get(), MethodArgs, ResultTy, VK,
15785
- RParenLoc, CurFPFeatureOverrides());
15775
+ CallExpr *TheCall = CXXOperatorCallExpr::Create(
15776
+ Context, OO_Call, NewFn.get(), MethodArgs, ResultTy, VK, RParenLoc,
15777
+ CurFPFeatureOverrides());
15786
15778
15787
15779
if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
15788
15780
return true;
0 commit comments