MoveConstArgCheck.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. #include "llvm/ADT/DenseSet.h"
  12. namespace clang::tidy::performance {
  13. /// Find casts of calculation results to bigger type. Typically from int to
  14. ///
  15. /// The options are
  16. ///
  17. /// - `CheckTriviallyCopyableMove`: Whether to check for trivially-copyable
  18. // types as their objects are not moved but copied. Enabled by default.
  19. // - `CheckMoveToConstRef`: Whether to check if a `std::move()` is passed
  20. // as a const reference argument.
  21. class MoveConstArgCheck : public ClangTidyCheck {
  22. public:
  23. MoveConstArgCheck(StringRef Name, ClangTidyContext *Context)
  24. : ClangTidyCheck(Name, Context), CheckTriviallyCopyableMove(Options.get(
  25. "CheckTriviallyCopyableMove", true)),
  26. CheckMoveToConstRef(Options.get("CheckMoveToConstRef", true)) {}
  27. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  28. return LangOpts.CPlusPlus;
  29. }
  30. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  31. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  32. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  33. private:
  34. const bool CheckTriviallyCopyableMove;
  35. const bool CheckMoveToConstRef;
  36. llvm::DenseSet<const CallExpr *> AlreadyCheckedMoves;
  37. };
  38. } // namespace clang::tidy::performance
  39. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MOVECONSTANTARGUMENTCHECK_H