10#include "clang/Lex/Lexer.h"
18 Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind(
"decl"),
this);
22 const MatchFinder::MatchResult &Result) {
23 const auto *D = Result.Nodes.getNodeAs<ParmVarDecl>(
"decl");
27 SourceRange DefaultArgRange = D->getDefaultArgRange();
29 if (DefaultArgRange.getEnd() != D->getEndLoc())
32 if (DefaultArgRange.getBegin().isMacroID()) {
33 diag(D->getBeginLoc(),
34 "declaring a parameter with a default argument is disallowed");
38 SourceLocation StartLocation =
39 D->getName().empty() ? D->getBeginLoc() : D->getLocation();
41 SourceRange RemovalRange(
42 Lexer::getLocForEndOfToken(StartLocation, 0, *Result.SourceManager,
43 Result.Context->getLangOpts()),
44 DefaultArgRange.getEnd());
46 diag(D->getBeginLoc(),
47 "declaring a parameter with a default argument is disallowed")
48 << D << FixItHint::CreateRemoval(RemovalRange);
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.