https://github.com/NeKon69 created 
https://github.com/llvm/llvm-project/pull/188093

This PR updates `InsertLoc` to use the token after the closing parenthesis when 
placing the `const` FixIt for comparison operators.

It also adds a test covering this case for both the spaceship operator and a 
regular comparison operator.

Closes #187887

>From 3ef30aa7fbceeaf7ec579a9c1322d06a7178d070 Mon Sep 17 00:00:00 2001
From: NeKon69 <[email protected]>
Date: Mon, 23 Mar 2026 16:36:08 +0300
Subject: [PATCH 1/2] apply fix and add a test

---
 clang/lib/Sema/SemaDeclCXX.cpp                  |  2 +-
 clang/test/FixIt/fixit-defaulted-comparison.cpp | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/FixIt/fixit-defaulted-comparison.cpp

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 87e07c8ac0d05..4a25ffd67a299 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -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.
diff --git a/clang/test/FixIt/fixit-defaulted-comparison.cpp 
b/clang/test/FixIt/fixit-defaulted-comparison.cpp
new file mode 100644
index 0000000000000..351620dc5470d
--- /dev/null
+++ b/clang/test/FixIt/fixit-defaulted-comparison.cpp
@@ -0,0 +1,12 @@
+// 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
+
+#include <compare>
+
+struct Box {
+  std::partial_ordering operator<=>(const Box& other) = default;
+  // expected-error@-1 {{defaulted member three-way comparison operator must 
be const-qualified}}
+  // CHECK: fix-it:{{.*}}:{7:54-7:54}:" const"
+};

>From ac92e1aaf63583c72c547dfc49073ccc07abf3eb Mon Sep 17 00:00:00 2001
From: NeKon69 <[email protected]>
Date: Mon, 23 Mar 2026 20:50:45 +0300
Subject: [PATCH 2/2] update tests

---
 clang/test/FixIt/fixit-defaulted-comparison.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/test/FixIt/fixit-defaulted-comparison.cpp 
b/clang/test/FixIt/fixit-defaulted-comparison.cpp
index 351620dc5470d..c59ba45f886f8 100644
--- a/clang/test/FixIt/fixit-defaulted-comparison.cpp
+++ b/clang/test/FixIt/fixit-defaulted-comparison.cpp
@@ -1,12 +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
 
-#include <compare>
+namespace std {
+struct partial_ordering {};
+} // namespace std
 
 struct Box {
-  std::partial_ordering operator<=>(const Box& other) = default;
-  // expected-error@-1 {{defaulted member three-way comparison operator must 
be const-qualified}}
-  // CHECK: fix-it:{{.*}}:{7:54-7:54}:" const"
+  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"
 };

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to