[clang] [clang] Implement `__is_virtual_base_of()` intrinsic (PR #100393)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 24 12:11:58 PDT 2024
================
@@ -6027,6 +6027,33 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI
return cast<CXXRecordDecl>(rhsRecord->getDecl())
->isDerivedFrom(cast<CXXRecordDecl>(lhsRecord->getDecl()));
}
+ case BTT_IsVirtualBaseOf: {
+ const RecordType *BaseRecord = LhsT->getAs<RecordType>();
+ const RecordType *DerivedRecord = RhsT->getAs<RecordType>();
+
+ if (!BaseRecord || !DerivedRecord) {
+ DiagnoseVLAInCXXTypeTrait(Self, Lhs, tok::kw___is_virtual_base_of);
+ DiagnoseVLAInCXXTypeTrait(Self, Rhs, tok::kw___is_virtual_base_of);
+ return false;
+ }
+
+ if (BaseRecord->isUnionType() || DerivedRecord->isUnionType())
+ return false;
+
+ if (!BaseRecord->isStructureOrClassType() ||
+ !DerivedRecord->isStructureOrClassType())
+ return false;
+
+ if (Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
----------------
Sirraide wrote:
The proposal only mentions that the second type has to be complete. My guess is that the reasoning behind this is that in e.g. `__is_virtual_base_of(A, B)`, if `B` is complete but `A` isn’t, then `A` can’t be a base of `B`—since a complete class can’t have an incomplete base—and therefore, it can’t be a virtual base either.
https://github.com/llvm/llvm-project/pull/100393
More information about the cfe-commits
mailing list