10#include "clang/AST/ASTContext.h"
11#include "clang/AST/DeclCXX.h"
17 auto *Record = Type->getAsCXXRecordDecl();
18 return Record && Record->hasDefinition() &&
19 !Record->hasNonTrivialCopyConstructor() &&
20 !Record->hasNonTrivialDestructor();
24 auto *Record = Type->getAsCXXRecordDecl();
25 if (!Record || !Record->hasDefinition())
27 return llvm::any_of(Record->ctors(), [](
const auto *Constructor) {
28 return Constructor->isCopyConstructor() && Constructor->isDeleted();
33 const ASTContext &Context) {
34 if (Type->isDependentType() || Type->isIncompleteType())
36 return !Type.isTriviallyCopyableType(Context) &&
42 const ASTContext &Context) {
43 const auto *ClassDecl = dyn_cast<CXXRecordDecl>(&RecordDecl);
49 if (RecordDecl.isInvalidDecl())
53 if (ClassDecl->hasUserProvidedDefaultConstructor())
56 if (ClassDecl->isPolymorphic())
59 if (ClassDecl->hasTrivialDefaultConstructor())
64 for (
const FieldDecl *Field : ClassDecl->fields()) {
65 if (Field->hasInClassInitializer())
71 return llvm::all_of(ClassDecl->bases(), [&](
const CXXBaseSpecifier &Base) {
72 return isTriviallyDefaultConstructible(Base.getType(), Context) &&
82 if (Type->isArrayType())
88 if (Type->isIncompleteType())
91 if (Context.getLangOpts().ObjCAutoRefCount) {
92 switch (Type.getObjCLifetime()) {
93 case Qualifiers::OCL_ExplicitNone:
96 case Qualifiers::OCL_Strong:
97 case Qualifiers::OCL_Weak:
98 case Qualifiers::OCL_Autoreleasing:
101 case Qualifiers::OCL_None:
102 if (Type->isObjCLifetimeType())
108 const QualType CanonicalType = Type.getCanonicalType();
109 if (CanonicalType->isDependentType())
113 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
116 if (
const auto *RD = CanonicalType->getAsRecordDecl()) {
129 if (Type->isIncompleteType())
132 if (Type.getCanonicalType()->isDependentType())
135 return Type.isDestructedType() == QualType::DK_none;
139 auto *Record = Type->getAsCXXRecordDecl();
140 return Record && Record->hasDefinition() &&
141 Record->hasNonTrivialMoveConstructor();
145 auto *Record = Type->getAsCXXRecordDecl();
146 return Record && Record->hasDefinition() &&
147 Record->hasNonTrivialMoveAssignment();
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl, const ASTContext &Context)
Returns true if RecordDecl is trivially default constructible.
std::optional< bool > isExpensiveToCopy(QualType Type, const ASTContext &Context)
Returns true if Type is expensive to copy.
static bool classHasTrivialCopyAndDestroy(QualType Type)
bool hasNonTrivialMoveAssignment(QualType Type)
Return true if Type has a non-trivial move assignment operator.
static bool hasDeletedCopyConstructor(QualType Type)
bool hasNonTrivialMoveConstructor(QualType Type)
Returns true if Type has a non-trivial move constructor.
bool isTriviallyDestructible(QualType Type)
Returns true if Type is trivially destructible.