10 #include "clang/Lex/Lexer.h"
18 void DefaultArgumentsDeclarationsCheck::registerMatchers(MatchFinder *Finder) {
20 Finder->addMatcher(parmVarDecl(hasDefaultArgument()).bind(
"decl"),
this);
23 void DefaultArgumentsDeclarationsCheck::check(
24 const MatchFinder::MatchResult &Result) {
25 const auto *D = Result.Nodes.getNodeAs<ParmVarDecl>(
"decl");
29 SourceRange DefaultArgRange = D->getDefaultArgRange();
31 if (DefaultArgRange.getEnd() != D->getEndLoc())
34 if (DefaultArgRange.getBegin().isMacroID()) {
35 diag(D->getBeginLoc(),
36 "declaring a parameter with a default argument is disallowed");
40 SourceLocation StartLocation =
41 D->getName().empty() ? D->getBeginLoc() : D->getLocation();
43 SourceRange RemovalRange(
44 Lexer::getLocForEndOfToken(StartLocation, 0, *Result.SourceManager,
45 Result.Context->getLangOpts()),
46 DefaultArgRange.getEnd());
48 diag(D->getBeginLoc(),
49 "declaring a parameter with a default argument is disallowed")
50 << D << FixItHint::CreateRemoval(RemovalRange);