[clang] [Clang] Implement diagnostics for why is_empty is false (PR #145044)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 23 08:26:07 PDT 2025
================
@@ -2285,6 +2286,68 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
}
+static void DiagnoseIsEmptyReason(Sema &S, SourceLocation Loc,
+ const CXXRecordDecl *D) {
+ // Non-static data members (ignore zero-width bitāfields).
+ for (auto *Field : D->fields()) {
+ if (Field->isBitField() && Field->getBitWidthValue() == 0)
+ continue;
+ S.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::NonEmptyMember << Field
+ << Field->getType() << Field->getSourceRange();
+ }
+
+ // Virtual functions.
+ for (auto *M : D->methods()) {
+ if (M->isVirtual()) {
+ S.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::VirtualFunction << M->getDeclName()
+ << M->getSourceRange();
+ break;
+ }
+ }
+
+ // Virtual bases and non-empty bases.
+ for (auto &B : D->bases()) {
+ auto *BR = B.getType()->getAsCXXRecordDecl();
----------------
AaronBallman wrote:
```suggestion
for (const auto &B : D->bases()) {
const CXXRecordDecl *BR = B.getType()->getAsCXXRecordDecl();
```
https://github.com/llvm/llvm-project/pull/145044
More information about the cfe-commits
mailing list