[clang] [Clang] Diagnose defaulted assignment operator with incompatible object parameter (PR #70176)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 02:01:05 PDT 2023


================
@@ -7748,6 +7748,24 @@ bool Sema::CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD,
         HadError = true;
       }
     }
+    // [C++23][dcl.fct.def.default]/p2.2
+    // if F2 has an implicit object parameter of type “reference to C”,
+    // F1 may be an explicit object member function whose explicit object
+    // parameter is of (possibly different) type “reference to C”,
+    // in which case the type of F1 would differ from the type of F2
+    // in that the type of F1 has an additional parameter;
+    if (!Context.hasSameType(
+            ThisType.getNonReferenceType().getUnqualifiedType(),
+            Context.getRecordType(RD))) {
+      if (DeleteOnTypeMismatch)
+        ShouldDeleteForTypeMismatch = true;
+      else {
+        Diag(MD->getLocation(),
+             diag::err_defaulted_special_member_explicit_object_mismatch)
+            << (CSM == CXXMoveAssignment) << RD;
----------------
cor3ntin wrote:

What do you have in mind? the first parameter? I am not sure how useful it is though - we certainly don't do it for other warnings here.

https://github.com/llvm/llvm-project/pull/70176


More information about the cfe-commits mailing list