53 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H11 12#include "../ClangTidyCheck.h"13 14namespace clang::tidy::bugprone {15 16/// Detect when __func__ or __FUNCTION__ is being used from within a lambda. In17/// that context, those expressions expand to the name of the call operator18/// (i.e., `operator()`).19///20/// For the user-facing documentation see:21/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/lambda-function-name.html22class LambdaFunctionNameCheck : public ClangTidyCheck {23public: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 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {36 return LangOpts.CPlusPlus11;37 }38 39 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;40 void registerMatchers(ast_matchers::MatchFinder *Finder) override;41 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,42 Preprocessor *ModuleExpanderPP) override;43 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;44 45private:46 SourceRangeSet SuppressMacroExpansions;47 bool IgnoreMacros;48};49 50} // namespace clang::tidy::bugprone51 52#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LAMBDAFUNCTIONNAMECHECK_H53