DefaultArgumentsCallsCheck.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. //===--- DefaultArgumentsCallsCheck.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 "DefaultArgumentsCallsCheck.h"
  9. using namespace clang::ast_matchers;
  10. namespace clang::tidy::fuchsia {
  11. void DefaultArgumentsCallsCheck::registerMatchers(MatchFinder *Finder) {
  12. // Calling a function which uses default arguments is disallowed.
  13. Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this);
  14. }
  15. void DefaultArgumentsCallsCheck::check(const MatchFinder::MatchResult &Result) {
  16. const auto *S = Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt");
  17. if (!S)
  18. return;
  19. diag(S->getUsedLocation(),
  20. "calling a function that uses a default argument is disallowed");
  21. diag(S->getParam()->getBeginLoc(), "default parameter was declared here",
  22. DiagnosticIDs::Note);
  23. }
  24. } // namespace clang::tidy::fuchsia