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() || Type->isIncompleteType())
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->isPolymorphic())
65 if (ClassDecl->hasTrivialDefaultConstructor())
70 for (
const FieldDecl *Field : ClassDecl->fields()) {
71 if (Field->hasInClassInitializer())
77 for (
const CXXBaseSpecifier &Base : ClassDecl->bases()) {
92 if (Type->isArrayType())
98 if (Type->isIncompleteType())
101 if (Context.getLangOpts().ObjCAutoRefCount) {
102 switch (Type.getObjCLifetime()) {
103 case Qualifiers::OCL_ExplicitNone:
106 case Qualifiers::OCL_Strong:
107 case Qualifiers::OCL_Weak:
108 case Qualifiers::OCL_Autoreleasing:
111 case Qualifiers::OCL_None:
112 if (Type->isObjCLifetimeType())
118 QualType CanonicalType = Type.getCanonicalType();
119 if (CanonicalType->isDependentType())
123 if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
126 if (
const auto *RT = CanonicalType->getAs<RecordType>()) {
135 auto *Record = Type->getAsCXXRecordDecl();
136 return Record && Record->hasDefinition() &&
137 Record->hasNonTrivialMoveConstructor();
141 auto *Record = Type->getAsCXXRecordDecl();
142 return Record && Record->hasDefinition() &&
143 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.