clang-tools  16.0.0git
MoveConstArgCheck.h
Go to the documentation of this file.
1 //===--- MoveConstArgCheck.h - clang-tidy -------------------------===//
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_MISC_MOVECONSTANTARGUMENTCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 #include "llvm/ADT/DenseSet.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace performance {
18 
19 /// Find casts of calculation results to bigger type. Typically from int to
20 ///
21 /// The options are
22 ///
23 /// - `CheckTriviallyCopyableMove`: Whether to check for trivially-copyable
24 // types as their objects are not moved but copied. Enabled by default.
25 // - `CheckMoveToConstRef`: Whether to check if a `std::move()` is passed
26 // as a const reference argument.
28 public:
30  : ClangTidyCheck(Name, Context), CheckTriviallyCopyableMove(Options.get(
31  "CheckTriviallyCopyableMove", true)),
32  CheckMoveToConstRef(Options.get("CheckMoveToConstRef", true)) {}
33  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
34  return LangOpts.CPlusPlus;
35  }
36  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
38  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
39 
40 private:
41  const bool CheckTriviallyCopyableMove;
42  const bool CheckMoveToConstRef;
43  llvm::DenseSet<const CallExpr *> AlreadyCheckedMoves;
44 };
45 
46 } // namespace performance
47 } // namespace tidy
48 } // namespace clang
49 
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::performance::MoveConstArgCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: MoveConstArgCheck.cpp:43
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:53
clang::tidy::performance::MoveConstArgCheck
Find casts of calculation results to bigger type.
Definition: MoveConstArgCheck.h:27
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:415
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:67
Name
Token Name
Definition: MacroToEnumCheck.cpp:89
clang::tidy::performance::MoveConstArgCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: MoveConstArgCheck.cpp:92
clang::tidy::performance::MoveConstArgCheck::MoveConstArgCheck
MoveConstArgCheck(StringRef Name, ClangTidyContext *Context)
Definition: MoveConstArgCheck.h:29
clang::tidy::performance::MoveConstArgCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: MoveConstArgCheck.cpp:38
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
LangOpts
const LangOptions * LangOpts
Definition: ExtractFunction.cpp:375
clang::tidy::performance::MoveConstArgCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition: MoveConstArgCheck.h:33