1 //===--- DefaultArgumentsCheck.cpp - clang-tidy----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "DefaultArgumentsCheck.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 
14 using namespace clang::ast_matchers;
15 
16 namespace clang {
17 namespace tidy {
18 namespace google {
19 
20 void DefaultArgumentsCheck::registerMatchers(MatchFinder *Finder) {
21   Finder->addMatcher(
22       cxxMethodDecl(anyOf(isOverride(), isVirtual()),
23                     hasAnyParameter(parmVarDecl(hasInitializer(expr()))))
24           .bind("Decl"),
25       this);
26 }
27 
28 void DefaultArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
29   const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("Decl");
30   diag(MatchedDecl->getLocation(),
31        "default arguments on virtual or override methods are prohibited");
32 }
33 
34 } // namespace google
35 } // namespace tidy
36 } // namespace clang
37