clang-tools  3.9.0
VariadicFunctionDefCheck.cpp
Go to the documentation of this file.
1 //===--- VariadicfunctiondefCheck.cpp - clang-tidy-------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 
14 using namespace clang::ast_matchers;
15 
16 namespace clang {
17 namespace tidy {
18 namespace cert {
19 
20 void VariadicFunctionDefCheck::registerMatchers(MatchFinder *Finder) {
21  if (!getLangOpts().CPlusPlus)
22  return;
23 
24  // We only care about function *definitions* that are variadic, and do not
25  // have extern "C" language linkage.
26  Finder->addMatcher(
27  functionDecl(isDefinition(), isVariadic(), unless(isExternC()))
28  .bind("func"),
29  this);
30 }
31 
32 void VariadicFunctionDefCheck::check(const MatchFinder::MatchResult &Result) {
33  const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("func");
34 
35  diag(FD->getLocation(),
36  "do not define a C-style variadic function; consider using a function "
37  "parameter pack or currying instead");
38 }
39 
40 } // namespace cert
41 } // namespace tidy
42 } // namespace clang
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:210
const NamedDecl * Result
Definition: USRFinder.cpp:137