clang-tools 24.0.0git
ExpensiveValueOrCheck.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_EXPENSIVEVALUEORCHECK_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPENSIVEVALUEORCHECK_H
11
12#include "../ClangTidyCheck.h"
13#include <vector>
14
16
17/// Warns when 'value_or' is called on an optional type whose underlying type
18/// is expensive to copy (not trivially copyable, or larger than a threshold).
19///
20/// For the user-facing documentation see:
21/// https://clang.llvm.org/extra/clang-tidy/checks/performance/expensive-value-or.html
23public:
24 ExpensiveValueOrCheck(StringRef Name, ClangTidyContext *Context);
25 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
26 return LangOpts.CPlusPlus;
27 }
28 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
31
32private:
33 const unsigned SizeThreshold;
34 /// Semicolon-separated regex patterns matching fully-qualified optional
35 /// types.
36 const std::vector<StringRef> OptionalTypes;
37 const bool WarnOnOwnershipTaking;
38};
39
40} // namespace clang::tidy::performance
41
42#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPENSIVEVALUEORCHECK_H
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
ExpensiveValueOrCheck(StringRef Name, ClangTidyContext *Context)
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
llvm::StringMap< ClangTidyValue > OptionMap