10 #include "clang/AST/ASTContext.h" 11 #include "clang/ASTMatchers/ASTMatchFinder.h" 17 namespace readability {
19 void DeletedDefaultCheck::registerMatchers(MatchFinder *Finder) {
28 cxxMethodDecl(anyOf(cxxConstructorDecl().bind(
"constructor"),
29 isCopyAssignmentOperator(),
30 isMoveAssignmentOperator()),
31 isDefaulted(), unless(isImplicit()), isDeleted(),
32 unless(isInstantiated()))
37 void DeletedDefaultCheck::check(
const MatchFinder::MatchResult &
Result) {
38 const StringRef
Message =
"%0 is explicitly defaulted but implicitly " 39 "deleted, probably because %1; definition can " 40 "either be removed or explicitly deleted";
41 if (
const auto *Constructor =
42 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"constructor")) {
43 auto Diag = diag(Constructor->getBeginLoc(),
Message);
44 if (Constructor->isDefaultConstructor()) {
45 Diag <<
"default constructor" 46 <<
"a non-static data member or a base class is lacking a default " 48 }
else if (Constructor->isCopyConstructor()) {
49 Diag <<
"copy constructor" 50 <<
"a non-static data member or a base class is not copyable";
51 }
else if (Constructor->isMoveConstructor()) {
52 Diag <<
"move constructor" 53 <<
"a non-static data member or a base class is neither copyable " 56 }
else if (
const auto *Assignment =
57 Result.Nodes.getNodeAs<CXXMethodDecl>(
"method-decl")) {
58 diag(Assignment->getBeginLoc(),
Message)
59 << (Assignment->isCopyAssignmentOperator() ?
"copy assignment operator" 60 :
"move assignment operator")
61 <<
"a base class or a non-static data member is not assignable, e.g. " 62 "because the latter is marked 'const'";
constexpr llvm::StringLiteral Message
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result