clang-tools
17.0.0git
llvm-project
clang-tools-extra
clang-tidy
bugprone
LambdaFunctionNameCheck.h
Go to the documentation of this file.
1
//===--- LambdaFunctionNameCheck.h - clang-tidy------------------*- C++ -*-===//
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
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang::tidy::bugprone
{
15
16
/// Detect when __func__ or __FUNCTION__ is being used from within a lambda. In
17
/// that context, those expressions expand to the name of the call operator
18
/// (i.e., `operator()`).
19
///
20
/// For the user-facing documentation see:
21
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/lambda-function-name.html
22
class
LambdaFunctionNameCheck
:
public
ClangTidyCheck
{
23
public
:
24
struct
SourceRangeLessThan
{
25
bool
operator()
(
const
SourceRange &L,
const
SourceRange &R)
const
{
26
if
(L.getBegin() == R.getBegin()) {
27
return
L.getEnd() < R.getEnd();
28
}
29
return
L.getBegin() < R.getBegin();
30
}
31
};
32
using
SourceRangeSet
= std::set<SourceRange, SourceRangeLessThan>;
33
34
LambdaFunctionNameCheck
(StringRef
Name
,
ClangTidyContext
*Context)
35
:
ClangTidyCheck
(
Name
, Context) {}
36
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
37
void
registerPPCallbacks
(
const
SourceManager &SM, Preprocessor *
PP
,
38
Preprocessor *ModuleExpanderPP)
override
;
39
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
40
41
private
:
42
SourceRangeSet
SuppressMacroExpansions;
43
};
44
45
}
// namespace clang::tidy::bugprone
46
47
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H
Name
Token Name
Definition:
MacroToEnumCheck.cpp:87
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::bugprone::LambdaFunctionNameCheck
Detect when func or FUNCTION is being used from within a lambda.
Definition:
LambdaFunctionNameCheck.h:22
clang::tidy::bugprone::LambdaFunctionNameCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
LambdaFunctionNameCheck.cpp:59
clang::tidy::bugprone::LambdaFunctionNameCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
LambdaFunctionNameCheck.cpp:71
clang::tidy::bugprone::LambdaFunctionNameCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition:
LambdaFunctionNameCheck.cpp:65
clang::tidy::bugprone::LambdaFunctionNameCheck::SourceRangeSet
std::set< SourceRange, SourceRangeLessThan > SourceRangeSet
Definition:
LambdaFunctionNameCheck.h:32
clang::tidy::bugprone::LambdaFunctionNameCheck::LambdaFunctionNameCheck
LambdaFunctionNameCheck(StringRef Name, ClangTidyContext *Context)
Definition:
LambdaFunctionNameCheck.h:34
clang::tidy::bugprone
Definition:
ArgumentCommentCheck.cpp:19
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition:
BadSignalToKillThreadCheck.cpp:28
clang::tidy::bugprone::LambdaFunctionNameCheck::SourceRangeLessThan
Definition:
LambdaFunctionNameCheck.h:24
clang::tidy::bugprone::LambdaFunctionNameCheck::SourceRangeLessThan::operator()
bool operator()(const SourceRange &L, const SourceRange &R) const
Definition:
LambdaFunctionNameCheck.h:25
Generated on Mon Jun 5 2023 22:48:35 for clang-tools by
1.9.6