DefaultArgumentsCheck.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. //===--- DefaultArgumentsCheck.cpp - clang-tidy----------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "DefaultArgumentsCheck.h"
  9. #include "clang/AST/ASTContext.h"
  10. #include "clang/ASTMatchers/ASTMatchFinder.h"
  11. using namespace clang::ast_matchers;
  12. namespace clang::tidy::google {
  13. void DefaultArgumentsCheck::registerMatchers(MatchFinder *Finder) {
  14. Finder->addMatcher(
  15. cxxMethodDecl(anyOf(isOverride(), isVirtual()),
  16. hasAnyParameter(parmVarDecl(hasInitializer(expr()))))
  17. .bind("Decl"),
  18. this);
  19. }
  20. void DefaultArgumentsCheck::check(const MatchFinder::MatchResult &Result) {
  21. const auto *MatchedDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("Decl");
  22. diag(MatchedDecl->getLocation(),
  23. "default arguments on virtual or override methods are prohibited");
  24. }
  25. } // namespace clang::tidy::google