SmartPtrArrayMismatchCheck.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===--- SharedPtrArrayMismatchCheck.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_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::bugprone {
  12. /// Find constructions of smart (unique or shared) pointers where the pointer
  13. /// is declared with non-array target type and an array (created with a
  14. /// new-expression) is passed to it.
  15. class SmartPtrArrayMismatchCheck : public ClangTidyCheck {
  16. public:
  17. SmartPtrArrayMismatchCheck(StringRef Name, ClangTidyContext *Context,
  18. StringRef SmartPointerName);
  19. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  20. return LangOpts.CPlusPlus11;
  21. }
  22. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  23. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  24. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  25. protected:
  26. using SmartPtrClassMatcher = ast_matchers::internal::BindableMatcher<Decl>;
  27. /// Returns matcher that match with different smart pointer classes.
  28. ///
  29. /// Requires to bind pointer type (qualType) with PointerTypeN string declared
  30. /// in this class.
  31. virtual SmartPtrClassMatcher getSmartPointerClassMatcher() const = 0;
  32. static const char PointerTypeN[];
  33. private:
  34. StringRef const SmartPointerName;
  35. };
  36. } // namespace clang::tidy::bugprone
  37. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H