================
@@ -4016,6 +4016,34 @@ Note that the `size` argument must be a compile time 
constant.
 
 Note that this intrinsic cannot yet be called in a ``constexpr`` context.
 
+``__is_bitwise_cloneable``
+--------------------------
+
+A type trait is used to check whether a type can be safely copied by memcpy.
+
+**Syntax**:
+
+.. code-block:: c++
+
+  bool __is_bitwise_cloneable(Type)
+
+**Description**:
+
+This trait is similar to `std::is_trivially_copyable`, but additionally allows
+to have user-defined constructors, virtual functions and virtual bases. It is 
up
+to the user code to guarantee that a bitwise copy results in non-broken object
+and that the lifetime of an object is properly started.
+
+Objects of bitwise cloneable types can be bitwise copied by memcpy/memmove. The
+Clang compiler warrants that this behavior is well defined, and won't be
+broken by compiler optimizations.
+
+After the copy, the lifetime of the new object isn't started yet (unless the
+type is trivially copyable). Users must ensure its lifetime is started to avoid
+undefined behavior.
----------------
hokein wrote:

> What should the intended action taken by the user be? Is this advice 
> actionable?
I guess that if the type is implicit-lifetime-type, users could use 
start_lifetime_as (although it's not implemented in Clang).
AFAIK, there is no way to start a lifetime of other objects (e.g. containing 
virtual members).

For implicit-lifetime types, users don't need to start the lifetime explicitly, 
the `memcpy` implicitly starts the lifetime of the object, per the 
[standard](https://eel.is/c++draft/intro.object#note-6); for other types, yeah, 
this is no standard way to do it (for our case, we plan to do the trick with 
`__builtin_launder`, but I would not mention it in the public doc).

How about this?

```
For implicit-lifetime types, the lifetime of the new object is implicitly 
started after the memcpy. For other types (e.g., classes with virtual methods), 
the lifetime isn't started, and using the object results in undefined behavior 
according to the C++ Standard, and there is no standard way to start the 
lifetime.
```

https://github.com/llvm/llvm-project/pull/86512
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to