10 #include "../utils/Matchers.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 21 namespace readability {
23 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
24 if (!getLangOpts().CPlusPlus)
29 hasDeclaration(cxxConstructorDecl(hasParent(
35 unless(isDelegatingConstructor()),
37 anyOf(isUnion(), ast_matchers::isTemplateInstantiation()))),
38 forEachConstructorInitializer(
39 cxxCtorInitializer(isWritten(),
40 withInitializer(ignoringImplicit(Construct)),
41 unless(forField(hasType(isConstQualified()))),
42 unless(forField(hasParent(recordDecl(isUnion())))))
47 void RedundantMemberInitCheck::check(
const MatchFinder::MatchResult &
Result) {
48 const auto *Init = Result.Nodes.getNodeAs<CXXCtorInitializer>(
"init");
49 const auto *Construct = Result.Nodes.getNodeAs<CXXConstructExpr>(
"construct");
51 if (Construct->getNumArgs() == 0 ||
52 Construct->getArg(0)->isDefaultArgument()) {
53 if (Init->isAnyMemberInitializer()) {
54 diag(Init->getSourceLocation(),
"initializer for member %0 is redundant")
55 << Init->getAnyMember()
56 << FixItHint::CreateRemoval(Init->getSourceRange());
58 diag(Init->getSourceLocation(),
59 "initializer for base class %0 is redundant")
60 << Construct->getType()
61 << FixItHint::CreateRemoval(Init->getSourceRange());
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result