[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 3 06:54:03 PDT 2024


================
@@ -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.
+
+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.
----------------
ilya-biryukov wrote:

NIT: by compiler optimizations **and sanitizers**

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


More information about the cfe-commits mailing list