clang-tools 23.0.0git
PreferSingleCharOverloadsCheck.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_PREFERSINGLECHAROVERLOADSCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_PREFERSINGLECHAROVERLOADSCHECK_H
11
12#include "../ClangTidyCheck.h"
13
14#include <vector>
15
17
18/// Optimize calls to std::string::find() and friends when the needle passed is
19/// a single character string literal.
20/// The character literal overload is more efficient.
21///
22/// For the user-facing documentation see:
23/// https://clang.llvm.org/extra/clang-tidy/checks/performance/prefer-single-char-overloads.html
25public:
26 PreferSingleCharOverloadsCheck(StringRef Name, ClangTidyContext *Context);
27 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28 return LangOpts.CPlusPlus;
29 }
30 std::optional<TraversalKind> getCheckTraversalKind() const override {
31 return TK_IgnoreUnlessSpelledInSource;
32 }
33 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36
37private:
38 const std::vector<StringRef> StringLikeClasses;
39};
40
41} // namespace clang::tidy::performance
42
43#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_PREFERSINGLECHAROVERLOADSCHECK_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
PreferSingleCharOverloadsCheck(StringRef Name, ClangTidyContext *Context)
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
std::optional< TraversalKind > getCheckTraversalKind() const override
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
llvm::StringMap< ClangTidyValue > OptionMap