10#include "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
26 unless(isImplicit()), isMoveConstructor(),
27 hasAnyConstructorInitializer(
29 withInitializer(cxxConstructExpr(hasDeclaration(
30 cxxConstructorDecl(isCopyConstructor())
32 .bind(
"move-init")))),
37 const auto *CopyCtor = Result.Nodes.getNodeAs<CXXConstructorDecl>(
"ctor");
38 const auto *Initializer =
39 Result.Nodes.getNodeAs<CXXCtorInitializer>(
"move-init");
43 QualType QT = Initializer->getInit()->getType();
44 if (QT.isTriviallyCopyableType(*Result.Context))
47 if (QT.isConstQualified())
50 const auto *RD = QT->getAsCXXRecordDecl();
51 if (RD && RD->isTriviallyCopyable())
56 const CXXConstructorDecl *
Candidate =
nullptr;
57 for (
const auto *Ctor : CopyCtor->getParent()->ctors()) {
58 if (Ctor->isMoveConstructor() && Ctor->getAccess() <= AS_protected &&
74 diag(Initializer->getSourceLocation(),
75 "move constructor initializes %select{class member|base class}0 by "
76 "calling a copy constructor")
77 << Initializer->isBaseInitializer();
78 diag(CopyCtor->getLocation(),
"copy constructor being called",
80 diag(
Candidate->getLocation(),
"candidate move constructor here",
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.