Skip to content

Commit 7f999b9

Browse files
committed
Fixed case with destructor and added test, fixed typo
1 parent 437992d commit 7f999b9

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,10 +2107,11 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
21072107
<< diag::TraitNotSatisfiedReason::NTCField << Field
21082108
<< Field->getType() << Field->getSourceRange();
21092109
}
2110-
if (D->hasDeletedDestructor())
2110+
CXXDestructorDecl *Dtr = D->getDestructor();
2111+
if (D->hasDeletedDestructor() || (Dtr && !Dtr->isTrivial()))
21112112
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2112-
<< diag::TraitNotSatisfiedReason::DeletedDtr << 0
2113-
<< D->getDestructor()->getSourceRange();
2113+
<< diag::TraitNotSatisfiedReason::DeletedDtr
2114+
<< !D->hasDeletedDestructor() << D->getDestructor()->getSourceRange();
21142115

21152116
for (const CXXMethodDecl *Method : D->methods()) {
21162117
if (Method->isTrivial() || !Method->isUserProvided()) {
@@ -2136,16 +2137,10 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
21362137
<< IsMove << Method->getSourceRange();
21372138
break;
21382139
}
2139-
default: {
2140+
default:
21402141
break;
21412142
}
2142-
}
21432143
}
2144-
CXXDestructorDecl *Dtr = D->getDestructor();
2145-
if (Dtr && !Dtr->isTrivial())
2146-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2147-
<< diag::TraitNotSatisfiedReason::DeletedDtr << 1
2148-
<< Dtr->getSourceRange();
21492144
}
21502145

21512146
static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,

clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,14 @@ static_assert(__is_trivially_copyable(S11));
279279
// expected-note@-1 {{because it has a non-trivially-copyable base 'B6'}} \
280280
// expected-note@-1 {{'S11' is not trivially copyable}} \
281281
// expected-note@#tc-S11 {{'S11' defined here}}
282+
283+
struct S12 : B6 { // #tc-S12
284+
~S12() = delete;
285+
};
286+
static_assert(__is_trivially_copyable(S12));
287+
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S12)'}} \
288+
// expected-note@-1 {{because it has a non-trivially-copyable base 'B6'}} \
289+
// expected-note@-1 {{because it has a deleted destructor}} \
290+
// expected-note@-1 {{'S12' is not trivially copyable}} \
291+
// expected-note@#tc-S12 {{'S12' defined here}}
282292
}

0 commit comments

Comments
 (0)