[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

Giuseppe D'Angelo via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 16 03:40:16 PDT 2024


================
@@ -857,8 +881,13 @@ void CXXRecordDecl::addedMember(Decl *D) {
         data().HasDeclaredCopyAssignmentWithConstParam = true;
     }
 
-    if (Method->isMoveAssignmentOperator())
+    if (Method->isMoveAssignmentOperator()) {
       SMKind |= SMF_MoveAssignment;
+    }
+
+    if (Method->isUserProvided() &&
+        (Method->isCopyAssignment() || Method->isMoveAssignment()))
+      data().IsNaturallyTriviallyRelocatable = false;
----------------
dangelog wrote:

I've also been asked to comment. My personal opinion is that relocability is strictly tied to the Rule Of Five. The moment a user decides to opt into the RO5 by e.g. writing a custom assignment operator, they should lose trivial relocability, unless they do something extra to gain it back (different proposals disagree on the syntax but ultimately they achieve the same). (We may then argue regarding all the subtleties about user-declared vs. user-defaulted vs. user-defined, but I don't really have a strong opinion about that.)

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


More information about the cfe-commits mailing list