[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


================
@@ -2749,6 +2749,41 @@ bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
                                      /*IsCopyConstructible=*/false);
 }
 
+bool QualType::isBitwiseCloneableType(const ASTContext & Context) const {
+  auto CanonicalType = getCanonicalType();
+  if (CanonicalType.hasNonTrivialObjCLifetime())
+    return false;
+  if (CanonicalType->isArrayType())
+    return Context.getBaseElementType(CanonicalType)
+        .isBitwiseCloneableType(Context);
+
+  if (CanonicalType->isIncompleteType())
+    return false;
+
+  if (const auto *RD = CanonicalType->getAsRecordDecl()) { // struct/union/class
----------------
ilya-biryukov wrote:

NIT: rewrite to reduce nesting, see [LLVM Code Style](https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code).

```
const auto *RD = CanonicalType->getAsRecordDecl();
if (!RD)
  return true;
// ... Rest of the code.
```

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


More information about the cfe-commits mailing list