@@ -5664,10 +5664,15 @@ static ImplicitConversionSequence TryObjectArgumentInitialization(
56645664 assert(FromType->isRecordType());
56655665
56665666 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).
56695674 Qualifiers Quals = Method->getMethodQualifiers();
5670- if (isa<CXXDestructorDecl>(Method)) {
5675+ if (isa<CXXDestructorDecl>(Method) || Method->isStatic() ) {
56715676 Quals.addConst();
56725677 Quals.addVolatile();
56735678 }
@@ -15061,15 +15066,15 @@ ExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1506115066 CXXMethodDecl *Method = cast<CXXMethodDecl>(FnDecl);
1506215067 SmallVector<Expr *, 2> MethodArgs;
1506315068
15064- // Handle 'this' parameter if the selected function is not static .
15069+ // Initialize the object parameter .
1506515070 if (Method->isExplicitObjectMemberFunction()) {
1506615071 ExprResult Res =
1506715072 InitializeExplicitObjectArgument(*this, Args[0], Method);
1506815073 if (Res.isInvalid())
1506915074 return ExprError();
1507015075 Args[0] = Res.get();
1507115076 ArgExpr = Args;
15072- } else if (Method->isInstance()) {
15077+ } else {
1507315078 ExprResult Arg0 = PerformImplicitObjectArgumentInitialization(
1507415079 Args[0], /*Qualifier=*/nullptr, Best->FoundDecl, Method);
1507515080 if (Arg0.isInvalid())
@@ -15097,15 +15102,9 @@ ExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1509715102 ExprValueKind VK = Expr::getValueKindForType(ResultTy);
1509815103 ResultTy = ResultTy.getNonLValueExprType(Context);
1509915104
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());
1510915108
1511015109 if (CheckCallReturnType(FnDecl->getReturnType(), LLoc, TheCall, FnDecl))
1511115110 return ExprError();
@@ -15733,15 +15732,13 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
1573315732
1573415733 bool IsError = false;
1573515734
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.
1573915736 llvm::SmallVector<Expr *, 8> NewArgs;
1574015737 if (Method->isExplicitObjectMemberFunction()) {
1574115738 // FIXME: we should do that during the definition of the lambda when we can.
1574215739 DiagnoseInvalidExplicitObjectParameterInLambda(Method);
1574315740 PrepareExplicitObjectArgument(*this, Method, Obj, Args, NewArgs);
15744- } else if (Method->isInstance()) {
15741+ } else {
1574515742 ExprResult ObjRes = PerformImplicitObjectArgumentInitialization(
1574615743 Object.get(), /*Qualifier=*/nullptr, Best->FoundDecl, Method);
1574715744 if (ObjRes.isInvalid())
@@ -15775,14 +15772,9 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
1577515772 ExprValueKind VK = Expr::getValueKindForType(ResultTy);
1577615773 ResultTy = ResultTy.getNonLValueExprType(Context);
1577715774
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());
1578615778
1578715779 if (CheckCallReturnType(Method->getReturnType(), LParenLoc, TheCall, Method))
1578815780 return true;
0 commit comments