[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 4 03:36:27 PDT 2024
================
@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
return false;
case UTT_IsTriviallyEqualityComparable:
return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+ case UTT_IsImplicitLifetime: {
+ DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+ tok::kw___builtin_is_implicit_lifetime);
+ QualType UnqualT = T->getCanonicalTypeUnqualified();
+ if (UnqualT->isScalarType())
+ return true;
+ if (UnqualT->isArrayType())
+ return true;
+
+ const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+ if (!RD)
+ return false;
+ if (UnqualT->isAggregateType())
+ if (!RD->getDestructor()->isUserProvided())
+ return true;
+ if (RD->hasTrivialDestructor())
----------------
MitalAshok wrote:
You also need to check that it's not deleted too.
Currently the first two assertions fail here:
```c++
struct X { ~X() = delete; };
struct Y { X x; ~Y() = default; };
struct Z { X x; };
static_assert(!__builtin_is_implicit_lifetime(X));
static_assert(!__builtin_is_implicit_lifetime(Y));
static_assert( __builtin_is_implicit_lifetime(Z));
```
https://github.com/llvm/llvm-project/pull/101807
More information about the cfe-commits
mailing list