llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (NeKon69)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/188093.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-1) 
- (added) clang/test/FixIt/fixit-defaulted-comparison.cpp (+18) 


``````````diff
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..c59ba45f886f8
--- /dev/null
+++ b/clang/test/FixIt/fixit-defaulted-comparison.cpp
@@ -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"
+};

``````````

</details>


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

Reply via email to