10 #include "../utils/Matchers.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Frontend/CompilerInstance.h" 14 #include "clang/Lex/Lexer.h" 15 #include "clang/Lex/Preprocessor.h" 21 namespace performance {
23 MoveConstructorInitCheck::MoveConstructorInitCheck(StringRef
Name,
26 IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
27 Options.getLocalOrGlobal(
"IncludeStyle",
"llvm"))) {}
37 unless(isImplicit()), isMoveConstructor(),
38 hasAnyConstructorInitializer(
40 withInitializer(cxxConstructExpr(hasDeclaration(
41 cxxConstructorDecl(isCopyConstructor()).bind(
"ctor")))))
47 const auto *CopyCtor = Result.Nodes.getNodeAs<CXXConstructorDecl>(
"ctor");
48 const auto *Initializer =
49 Result.Nodes.getNodeAs<CXXCtorInitializer>(
"move-init");
53 QualType QT = Initializer->getInit()->getType();
54 if (QT.isTriviallyCopyableType(*Result.Context))
57 if (QT.isConstQualified())
60 const auto *RD = QT->getAsCXXRecordDecl();
61 if (RD && RD->isTriviallyCopyable())
66 const CXXConstructorDecl *
Candidate =
nullptr;
67 for (
const auto *Ctor : CopyCtor->getParent()->ctors()) {
68 if (Ctor->isMoveConstructor() && Ctor->getAccess() <= AS_protected &&
84 diag(Initializer->getSourceLocation(),
85 "move constructor initializes %0 by calling a copy constructor")
86 << (Initializer->isBaseInitializer() ?
"base class" :
"class member");
87 diag(CopyCtor->getLocation(),
"copy constructor being called",
89 diag(Candidate->getLocation(),
"candidate move constructor here",
95 const SourceManager &SM, Preprocessor *
PP, Preprocessor *ModuleExpanderPP) {
96 Inserter = std::make_unique<utils::IncludeInserter>(SM,
getLangOpts(),
98 PP->addPPCallbacks(Inserter->CreatePPCallbacks());
static StringRef toString(IncludeStyle Style)
Converts IncludeStyle to string representation.
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.