Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:19

0001 //===--- SharedPtrArrayMismatchCheck.h - clang-tidy -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::bugprone {
0015 
0016 /// Find constructions of smart (unique or shared) pointers where the pointer
0017 /// is declared with non-array target type and an array (created with a
0018 /// new-expression) is passed to it.
0019 class SmartPtrArrayMismatchCheck : public ClangTidyCheck {
0020 public:
0021   SmartPtrArrayMismatchCheck(StringRef Name, ClangTidyContext *Context,
0022                              StringRef SmartPointerName);
0023 
0024   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0025     return LangOpts.CPlusPlus11;
0026   }
0027   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0028   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0029   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0030 
0031 protected:
0032   using SmartPtrClassMatcher = ast_matchers::internal::BindableMatcher<Decl>;
0033 
0034   /// Returns matcher that match with different smart pointer classes.
0035   ///
0036   /// Requires to bind pointer type (qualType) with PointerTypeN string declared
0037   /// in this class.
0038   virtual SmartPtrClassMatcher getSmartPointerClassMatcher() const = 0;
0039 
0040   static const char PointerTypeN[];
0041 
0042 private:
0043   StringRef const SmartPointerName;
0044 };
0045 
0046 } // namespace clang::tidy::bugprone
0047 
0048 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SMARTPTRARRAYMISMATCHCHECK_H