[clang] Moves destructor type-trait deduction to a public function (PR #238456)

Christopher Di Bella via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 10:01:51 PST 2026


================
@@ -653,6 +653,96 @@ static ComparisonCategoryResult EvaluateTypeOrder(Sema &S, QualType LHS,
                     : ComparisonCategoryResult::Less;
 }
 
+DestructibleTraits::DestructibleTraits(Sema &S, const ASTContext &C,
+                                       SourceLocation Loc, QualType T)
+    : Loc(Loc), Kind(Destructibility::TriviallyDestructible) {
+  // C++14 [meta.unary.prop]:
+  //   For reference types, is_destructible<T>::value is true.
+  if (T->isReferenceType()) {
+    Kind = Destructibility::TriviallyDestructible;
+    return;
+  }
+
+  // Objective-C++ ARC: autorelease types don't require destruction.
+  if (T->isObjCLifetimeType() &&
+      T.getObjCLifetime() == Qualifiers::OCL_Autoreleasing) {
+    Kind = Destructibility::TriviallyDestructible;
+    return;
+  }
+
+  // C++14 [meta.unary.prop]:
+  //   For incomplete types and function types, is_destructible<T>::value is
+  //   false.
+  if (T->isIncompleteType() || T->isFunctionType()) {
+    Kind = Destructibility::NotAvailable;
+    return;
+  }
+
+  // A type that requires destruction (via a non-trivial destructor or ARC
+  // lifetime semantics) is not trivially-destructible.
+  if (T.isDestructedType())
+    Kind = Destructibility::Destructible;
+
+  // C++14 [meta.unary.prop]:
+  //   For object types and given U equal to remove_all_extents_t<T>, if the
+  //   expression std::declval<U&>().~U() is well-formed when treated as an
+  //   unevaluated operand (Clause 5), then is_destructible<T>::value is true
+  auto *RD = C.getBaseElementType(T)->getAsCXXRecordDecl();
+  if (!RD)
+    return;
+
+  Destructor = S.LookupDestructor(RD);
+  if (!Destructor) {
+    Kind = Destructibility::NotAvailable;
+    return;
+  }
+
+  //  C++14 [dcl.fct.def.delete]p2:
+  //    A program that refers to a deleted function implicitly or
+  //    explicitly, other than to declare it, is ill-formed.
+  if (Destructor->isDeleted()) {
+    Kind = Destructibility::NotAvailable;
+    return;
+  }
+
+  if (C.getLangOpts().AccessControl && Destructor->getAccess() != AS_public) {
+    Kind = Destructibility::NotAvailable;
+    return;
+  }
+}
+
+DestructibleTraits::Destructibility DestructibleTraits::GetKind() const {
+  return Kind;
+}
+
+bool DestructibleTraits::IsDestructible() const {
+  return Kind != Destructibility::NotAvailable;
+}
+
+bool DestructibleTraits::IsTriviallyDestructible() const {
----------------
cjdb wrote:

```suggestion
bool DestructibleTraits::isTriviallyDestructible() const {
```

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


More information about the cfe-commits mailing list