[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Tue May 14 09:24:10 PDT 2024
================
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// Scalar types are bitwise clonable.
+static_assert(__is_bitwise_cloneable(int));
+static_assert(__is_bitwise_cloneable(int*));
+// array
+static_assert(__is_bitwise_cloneable(int[10]));
+
+// non-scalar types.
+static_assert(!__is_bitwise_cloneable(int&));
+
+
+struct Forward; // expected-note 2{{forward declaration of 'Forward'}}
+static_assert(!__is_bitwise_cloneable(Forward)); // expected-error {{incomplete type 'Forward' used in type trait expression}}
+
+struct Foo { int a; };
+static_assert(__is_bitwise_cloneable(Foo));
+
+struct DynamicClass { virtual int Foo(); };
+static_assert(__is_bitwise_cloneable(DynamicClass));
----------------
ilya-biryukov wrote:
Maybe also add asserts for types not being trivially copyable?
This test is a good illustration of the differences between the two.
https://github.com/llvm/llvm-project/pull/86512
More information about the cfe-commits
mailing list