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