[clang][Sema] Fix const FixIt placement after comparison operator member definition (#188093)

Update `InsertLoc` to use the token after the closing parenthesis
when adding `const` qualification to a comparison operator

Fixes #187887
This commit is contained in:
NeKon69 2026-03-31 07:56:00 +03:00 committed by GitHub
parent 8a0c070309
commit d3224dc5da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -9039,7 +9039,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
} else {
Loc = MD->getLocation();
if (FunctionTypeLoc Loc = MD->getFunctionTypeLoc())
InsertLoc = Loc.getRParenLoc();
InsertLoc = getLocForEndOfToken(Loc.getRParenLoc());
}
// Don't diagnose an implicit 'operator=='; we will have diagnosed the
// corresponding defaulted 'operator<=>' already.

View File

@ -0,0 +1,18 @@
// RUN: %clang_cc1 -verify -std=c++23 %s
// RUN: cp %s %t
// RUN: not %clang_cc1 -std=c++23 -x c++ -fixit %t
// RUN: %clang_cc1 -std=c++23 -x c++ %t
// RUN: not %clang_cc1 -std=c++23 -x c++ -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
namespace std {
struct partial_ordering {};
} // namespace std
struct Box {
std::partial_ordering operator<=>(const Box& other) = default; // #ssdecl
bool operator==(const Box& other) = default; // #eqdecl
// expected-error@#ssdecl {{defaulted member three-way comparison operator must be const-qualified}}
// expected-error@#eqdecl {{defaulted member equality comparison operator must be const-qualified}}
// CHECK: fix-it:{{.*}}:{12:54-12:54}:" const"
// CHECK: fix-it:{{.*}}:{13:36-13:36}:" const"
};