clang-tools  6.0.0
LambdaFunctionNameCheck.h
Go to the documentation of this file.
1 //===--- LambdaFunctionNameCheck.h - clang-tidy------------------*- C++ -*-===//
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 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace misc {
18 
19 /// Detect when __func__ or __FUNCTION__ is being used from within a lambda. In
20 /// that context, those expressions expand to the name of the call operator
21 /// (i.e., `operator()`).
22 ///
23 /// For the user-facing documentation see:
24 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-lambda-function-name.html
26 public:
28  bool operator()(const SourceRange &L, const SourceRange &R) const {
29  if (L.getBegin() == R.getBegin()) {
30  return L.getEnd() < R.getEnd();
31  }
32  return L.getBegin() < R.getBegin();
33  }
34  };
35  using SourceRangeSet = std::set<SourceRange, SourceRangeLessThan>;
36 
38  : ClangTidyCheck(Name, Context) {}
39  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
40  void registerPPCallbacks(CompilerInstance &Compiler) override;
41  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
42 
43 private:
44  SourceRangeSet SuppressMacroExpansions;
45 };
46 
47 } // namespace misc
48 } // namespace tidy
49 } // namespace clang
50 
51 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_LAMBDA_FUNCTION_NAME_H
bool operator()(const SourceRange &L, const SourceRange &R) const
LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context)
StringHandle Name
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
std::set< SourceRange, SourceRangeLessThan > SourceRangeSet
Detect when func or FUNCTION is being used from within a lambda.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.