clang-tools 20.0.0git
DefaultArgumentsCallsCheck.cpp
Go to the documentation of this file.
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
10
11using namespace clang::ast_matchers;
12
14
16 // Calling a function which uses default arguments is disallowed.
17 Finder->addMatcher(cxxDefaultArgExpr().bind("stmt"), this);
18}
19
20void DefaultArgumentsCallsCheck::check(const MatchFinder::MatchResult &Result) {
21 const auto *S = Result.Nodes.getNodeAs<CXXDefaultArgExpr>("stmt");
22 if (!S)
23 return;
24
25 diag(S->getUsedLocation(),
26 "calling a function that uses a default argument is disallowed");
27 diag(S->getParam()->getBeginLoc(), "default parameter was declared here",
28 DiagnosticIDs::Note);
29}
30
31} // namespace clang::tidy::fuchsia
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.