File indexing completed on 2026-05-10 08:36:19
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
0011
0012 #include "../ClangTidyCheck.h"
0013
0014 namespace clang::tidy::cppcoreguidelines {
0015
0016
0017
0018
0019
0020
0021 class OwningMemoryCheck : public ClangTidyCheck {
0022 public:
0023 OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
0024 : ClangTidyCheck(Name, Context),
0025 LegacyResourceProducers(Options.get(
0026 "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
0027 "::calloc;::fopen;::freopen;::tmpfile")),
0028 LegacyResourceConsumers(Options.get(
0029 "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
0030 }
0031 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0032 return LangOpts.CPlusPlus11;
0033 }
0034
0035
0036 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0037
0038 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0039 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0040 std::optional<TraversalKind> getCheckTraversalKind() const override {
0041 return TK_IgnoreUnlessSpelledInSource;
0042 }
0043
0044 private:
0045 bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
0046 bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
0047 bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
0048 bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
0049 bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
0050 bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
0051 bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
0052
0053
0054
0055
0056 const StringRef LegacyResourceProducers;
0057
0058
0059 const StringRef LegacyResourceConsumers;
0060 };
0061
0062 }
0063
0064 #endif