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. 27 class MoveConstArgCheck : public ClangTidyCheck { 28 public: MoveConstArgCheck(StringRef Name,ClangTidyContext * Context)29 MoveConstArgCheck(StringRef Name, ClangTidyContext *Context) 30 : ClangTidyCheck(Name, Context), CheckTriviallyCopyableMove(Options.get( 31 "CheckTriviallyCopyableMove", true)), 32 CheckMoveToConstRef(Options.get("CheckMoveToConstRef", true)) {} isLanguageVersionSupported(const LangOptions & LangOpts)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 51