summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-05-09 13:43:58 +0000
committerHaojian Wu <hokein@google.com>2016-05-09 13:43:58 +0000
commit11726686820358e49dba86b0ee07002bd54965b6 (patch)
tree636353529305d03d0b492e080e3204d207883282 /clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp
parente473dc937f59a9fefe450725ca4774a5245826a2 (diff)
downloadbcm5719-llvm-11726686820358e49dba86b0ee07002bd54965b6.tar.gz
bcm5719-llvm-11726686820358e49dba86b0ee07002bd54965b6.zip
[clang-tidy] new google-default-arguments check
Summary: To check the google style guide rule here: https://google.github.io/styleguide/cppguide.html#Default_Arguments Patch by Clement Courbet! Reviewers: hokein Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19534 llvm-svn: 268919
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp b/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp
new file mode 100644
index 00000000000..ccbd870a6ec
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/google/DefaultArgumentsCheck.cpp
@@ -0,0 +1,36 @@
+//===--- DefaultArgumentsCheck.cpp - clang-tidy----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "DefaultArgumentsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace google {
+
+void DefaultArgumentsCheck::registerMatchers(MatchFinder *Finder) {
+ Finder->addMatcher(
+ cxxMethodDecl(anyOf(isOverride(), isVirtual()),
+ hasAnyParameter(parmVarDecl(hasInitializer(expr()))))
+ .bind("Decl"),
+ this);
+}
+
+void DefaultArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("Decl");
+ diag(MatchedDecl->getLocation(),
+ "default arguments on virtual or override methods are prohibited");
+}
+
+} // namespace google
+} // namespace tidy
+} // namespace clang
OpenPOWER on IntegriCloud