[clang] [Clang] Added explanation why a is trivial copyable evaluated to false. (PR #142341)
Shamshura Egor via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 2 10:09:55 PDT 2025
================
@@ -2083,6 +2086,88 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema &SemaRef,
SemaRef.Diag(D->getLocation(), diag::note_defined_here) << D;
}
+static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
+ SourceLocation Loc,
+ const CXXRecordDecl *D) {
+ for (const CXXBaseSpecifier &B : D->bases()) {
+ assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
+ if (B.isVirtual())
+ SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::VBase << B.getType()
+ << B.getSourceRange();
+ if (!B.getType().isTriviallyCopyableType(D->getASTContext())) {
+ SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::NTCBase << B.getType()
+ << B.getSourceRange();
+ }
+ }
+ for (const FieldDecl *Field : D->fields()) {
+ if (!Field->getType().isTriviallyCopyableType(Field->getASTContext()))
+ SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::NTCField << Field
+ << Field->getType() << Field->getSourceRange();
+ }
+ if (D->hasDeletedDestructor())
+ SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
+ << diag::TraitNotSatisfiedReason::DeletedDtr << 0
+ << D->getDestructor()->getSourceRange();
+
+ for (const CXXMethodDecl *Method : D->methods()) {
+ if (Method->isIneligibleOrNotSelected() || Method->isTrivial() ||
+ !Method->isUserProvided()) {
+ continue;
+ }
+ auto SpecialMemberKind =
+ SemaRef.getDefaultedFunctionKind(Method).asSpecialMember();
+ switch (SpecialMemberKind) {
+ case CXXSpecialMemberKind::CopyConstructor:
----------------
egorshamshura wrote:
Added tests for every single case
https://github.com/llvm/llvm-project/pull/142341
More information about the cfe-commits
mailing list