UseEmplaceCheck.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===--- UseEmplaceCheck.h - clang-tidy--------------------------*- C++ -*-===//
  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_MODERNIZE_USE_EMPLACE_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EMPLACE_H
  10. #include "../ClangTidyCheck.h"
  11. #include <string>
  12. #include <vector>
  13. namespace clang::tidy::modernize {
  14. /// This check looks for cases when inserting new element into std::vector but
  15. /// the element is constructed temporarily.
  16. /// It replaces those calls for emplace_back of arguments passed to
  17. /// constructor of temporary object.
  18. ///
  19. /// For the user-facing documentation see:
  20. /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html
  21. class UseEmplaceCheck : public ClangTidyCheck {
  22. public:
  23. UseEmplaceCheck(StringRef Name, ClangTidyContext *Context);
  24. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  25. return LangOpts.CPlusPlus11;
  26. }
  27. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  28. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  29. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  30. private:
  31. const bool IgnoreImplicitConstructors;
  32. const std::vector<StringRef> ContainersWithPushBack;
  33. const std::vector<StringRef> ContainersWithPush;
  34. const std::vector<StringRef> ContainersWithPushFront;
  35. const std::vector<StringRef> SmartPointers;
  36. const std::vector<StringRef> TupleTypes;
  37. const std::vector<StringRef> TupleMakeFunctions;
  38. const std::vector<StringRef> EmplacyFunctions;
  39. };
  40. } // namespace clang::tidy::modernize
  41. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_EMPLACE_H