10#include "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/Lex/Lexer.h"
23 IgnoreBaseInCopyConstructors);
29 unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
30 forEachConstructorInitializer(
35 cxxConstructorDecl(ofClass(cxxRecordDecl(
36 unless(isTriviallyDefaultConstructible()))))))
38 unless(forField(hasType(isConstQualified()))),
39 unless(forField(hasParent(recordDecl(isUnion())))))
46 const auto *Init = Result.Nodes.getNodeAs<CXXCtorInitializer>(
"init");
47 const auto *Construct = Result.Nodes.getNodeAs<CXXConstructExpr>(
"construct");
48 const auto *ConstructorDecl =
49 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"constructor");
51 if (IgnoreBaseInCopyConstructors && ConstructorDecl->isCopyConstructor() &&
52 Init->isBaseInitializer())
55 if (Construct->getNumArgs() == 0 ||
56 Construct->getArg(0)->isDefaultArgument()) {
57 if (Init->isAnyMemberInitializer()) {
58 diag(Init->getSourceLocation(),
"initializer for member %0 is redundant")
59 << Init->getAnyMember()
60 << FixItHint::CreateRemoval(Init->getSourceRange());
62 diag(Init->getSourceLocation(),
63 "initializer for base class %0 is redundant")
64 << Construct->getType()
65 << FixItHint::CreateRemoval(Init->getSourceRange());
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.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
llvm::StringMap< ClangTidyValue > OptionMap