Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,7 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR)
/// base classes or fields have a no-return destructor
FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE)

/// The special members of this class which were deleted.
FIELD(HasDeletedSpecialMembers, 6, MERGE_OR)

#undef FIELD
25 changes: 21 additions & 4 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D)
ImplicitCopyAssignmentHasConstParam(true),
HasDeclaredCopyConstructorWithConstParam(false),
HasDeclaredCopyAssignmentWithConstParam(false),
IsAnyDestructorNoReturn(false), IsLambda(false),
IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false),
HasODRHash(false), Definition(D) {}
IsAnyDestructorNoReturn(false), HasDeletedSpecialMembers(0),
IsLambda(false), IsParsingBaseSpecifiers(false),
ComputedVisibleConversions(false), HasODRHash(false), Definition(D) {}

CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
return Bases.get(Definition->getASTContext().getExternalSource());
Expand Down Expand Up @@ -586,6 +586,14 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
if (hasNonTrivialMoveAssignment()) return false;
// -- has a trivial destructor.
if (!hasTrivialDestructor()) return false;
// C++17 [class]p6: that has at least one non-deleted copy constructor, move
// constructor, copy assignment operator, or move assignment operator,
if (getASTContext().getLangOpts().CPlusPlus17 &&
(data().HasDeletedSpecialMembers &
(SMF_CopyAssignment | SMF_CopyConstructor | SMF_MoveAssignment |
SMF_MoveConstructor)) == (SMF_CopyAssignment | SMF_CopyConstructor |
SMF_MoveAssignment | SMF_MoveConstructor))
return false;

return true;
}
Expand Down Expand Up @@ -1446,7 +1454,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
// out whether it's trivial yet (not until we get to the end of the
// class). We'll handle this method in
// finishedDefaultedOrDeletedMember.
} else if (MD->isTrivial()) {
return;
}

if (MD->isTrivial()) {
data().HasTrivialSpecialMembers |= SMKind;
data().HasTrivialSpecialMembersForCall |= SMKind;
} else if (MD->isTrivialForCall()) {
Expand All @@ -1462,6 +1473,10 @@ void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
if (!MD->isUserProvided())
data().DeclaredNonTrivialSpecialMembersForCall |= SMKind;
}

if (MD->isDeleted()) {
data().HasDeletedSpecialMembers |= SMKind;
}
Comment on lines +1477 to +1479
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (MD->isDeleted()) {
data().HasDeletedSpecialMembers |= SMKind;
}
if (MD->isDeleted())
data().HasDeletedSpecialMembers |= SMKind;

}

void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
Expand Down Expand Up @@ -1499,6 +1514,8 @@ void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
data().HasTrivialSpecialMembers |= SMKind;
else
data().DeclaredNonTrivialSpecialMembers |= SMKind;
if (D->isDeleted())
data().HasDeletedSpecialMembers |= SMKind;
}
}

Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/type-traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,11 @@ void is_trivial2()
static_assert(__is_trivial(UnionAr));
static_assert(__is_trivial(TrivialStruct));
static_assert(__is_trivial(AllDefaulted));
#if __cplusplus >= 201703L
static_assert(!__is_trivial(AllDeleted));
#else
static_assert(__is_trivial(AllDeleted));
#endif

static_assert(!__is_trivial(void));
static_assert(!__is_trivial(NonTrivialStruct));
Expand Down Expand Up @@ -1419,7 +1423,11 @@ void is_trivially_copyable2()
static_assert(__is_trivially_copyable(TrivialStruct));
static_assert(__is_trivially_copyable(NonTrivialStruct));
static_assert(__is_trivially_copyable(AllDefaulted));
#if __cplusplus >= 201703L
static_assert(!__is_trivially_copyable(AllDeleted));
#else
static_assert(__is_trivially_copyable(AllDeleted));
#endif

static_assert(!__is_trivially_copyable(void));
static_assert(!__is_trivially_copyable(SuperNonTrivialStruct));
Expand Down