This patch implements a `__is_bitwise_cloneable` builtin in clang. The builtin is used as a guard to check a type can be safely bitwise copied by memcpy. It's functionally similar to `__is_trivially_copyable`, but covers a wider range of types (e.g. classes with virtual functions). The compiler guarantees that after copy, the destination object has the same object representations as the source object. And it is up to user to guarantee that program semantic constraints are satisfied. Context: https://discourse.llvm.org/t/extension-for-creating-objects-via-memcpy
9 lines
391 B
C++
9 lines
391 B
C++
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
//
|
|
struct DynamicClass { virtual int Foo(); };
|
|
static_assert(!__is_trivially_copyable(DynamicClass));
|
|
static_assert(__is_bitwise_cloneable(DynamicClass));
|
|
|
|
struct InComplete; // expected-note{{forward declaration}}
|
|
static_assert(!__is_bitwise_cloneable(InComplete)); // expected-error{{incomplete type 'InComplete' used in type trait expression}}
|