11 #include "clang/AST/ASTContext.h"
12 #include "clang/AST/DeclCXX.h"
13 #include "clang/ASTMatchers/ASTMatchFinder.h"
18 namespace type_traits {
22 bool classHasTrivialCopyAndDestroy(QualType Type) {
23 auto *Record = Type->getAsCXXRecordDecl();
24 return Record && Record->hasDefinition() &&
25 !Record->hasNonTrivialCopyConstructor() &&
26 !Record->hasNonTrivialDestructor();
29 bool hasDeletedCopyConstructor(QualType Type) {
30 auto *Record = Type->getAsCXXRecordDecl();
31 if (!Record || !Record->hasDefinition())
33 for (
const auto *Constructor : Record->ctors()) {
34 if (Constructor->isCopyConstructor() && Constructor->isDeleted())
44 if (Type->isDependentType())
46 return !Type.isTriviallyCopyableType(Context) &&
47 !classHasTrivialCopyAndDestroy(Type) &&
48 !hasDeletedCopyConstructor(Type);
53 const auto *ClassDecl = dyn_cast<CXXRecordDecl>(&RecordDecl);
59 if (ClassDecl->hasUserProvidedDefaultConstructor())
62 if (ClassDecl->hasTrivialDefaultConstructor())
66 for (
const FieldDecl *Field : ClassDecl->fields()) {
71 for (
const CXXBaseSpecifier &Base : ClassDecl->bases()) {
85 if (Type->isArrayType())
91 if (Type->isIncompleteType())
94 if (Context.getLangOpts().ObjCAutoRefCount) {
95 switch (Type.getObjCLifetime()) {
96 case Qualifiers::OCL_ExplicitNone:
99 case Qualifiers::OCL_Strong:
100 case Qualifiers::OCL_Weak:
101 case Qualifiers::OCL_Autoreleasing:
104 case Qualifiers::OCL_None:
105 if (Type->isObjCLifetimeType())
111 QualType CanonicalType = Type.getCanonicalType();
112 if (CanonicalType->isDependentType())
116 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
119 if (
const auto *RT = CanonicalType->getAs<RecordType>()) {
128 auto *Record = Type->getAsCXXRecordDecl();
129 return Record && Record->hasDefinition() &&
130 Record->hasNonTrivialMoveConstructor();
134 auto *Record = Type->getAsCXXRecordDecl();
135 return Record && Record->hasDefinition() &&
136 Record->hasNonTrivialMoveAssignment();
bool hasNonTrivialMoveConstructor(QualType Type)
Returns true if Type has a non-trivial move constructor.
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl, const ASTContext &Context)
Returns true if RecordDecl is trivially default constructible.
llvm::Optional< bool > isExpensiveToCopy(QualType Type, const ASTContext &Context)
Returns true if Type is expensive to copy.
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
ClangTidyContext & Context
bool hasNonTrivialMoveAssignment(QualType Type)
Return true if Type has a non-trivial move assignment operator.