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 for (
const auto *Constructor : Record->ctors()) {
28 if (Constructor->isCopyConstructor() && Constructor->isDeleted())
35 const ASTContext &Context) {
36 if (Type->isDependentType() || Type->isIncompleteType())
38 return !Type.isTriviallyCopyableType(Context) &&
44 const ASTContext &Context) {
45 const auto *ClassDecl = dyn_cast<CXXRecordDecl>(&RecordDecl);
51 if (RecordDecl.isInvalidDecl())
55 if (ClassDecl->hasUserProvidedDefaultConstructor())
58 if (ClassDecl->isPolymorphic())
61 if (ClassDecl->hasTrivialDefaultConstructor())
66 for (
const FieldDecl *Field : ClassDecl->fields()) {
67 if (Field->hasInClassInitializer())
73 for (
const CXXBaseSpecifier &Base : ClassDecl->bases()) {
88 if (Type->isArrayType())
94 if (Type->isIncompleteType())
97 if (Context.getLangOpts().ObjCAutoRefCount) {
98 switch (Type.getObjCLifetime()) {
99 case Qualifiers::OCL_ExplicitNone:
102 case Qualifiers::OCL_Strong:
103 case Qualifiers::OCL_Weak:
104 case Qualifiers::OCL_Autoreleasing:
107 case Qualifiers::OCL_None:
108 if (Type->isObjCLifetimeType())
114 QualType CanonicalType = Type.getCanonicalType();
115 if (CanonicalType->isDependentType())
119 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
122 if (
const auto *RD = CanonicalType->getAsRecordDecl()) {
135 if (Type->isIncompleteType())
138 if (Type.getCanonicalType()->isDependentType())
141 return Type.isDestructedType() == QualType::DK_none;
145 auto *Record = Type->getAsCXXRecordDecl();
146 return Record && Record->hasDefinition() &&
147 Record->hasNonTrivialMoveConstructor();
151 auto *Record = Type->getAsCXXRecordDecl();
152 return Record && Record->hasDefinition() &&
153 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.