clang-tools  8.0.0
OwningMemoryCheck.h
Go to the documentation of this file.
1 //===--- OwningMemoryCheck.h - clang-tidy------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace cppcoreguidelines {
18 
19 /// Checks for common use cases for gsl::owner and enforces the unique owner
20 /// nature of it whenever possible.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
25 public:
27  : ClangTidyCheck(Name, Context),
28  LegacyResourceProducers(Options.get(
29  "LegacyResourceProducers", "::malloc;::aligned_alloc;::realloc;"
30  "::calloc;::fopen;::freopen;::tmpfile")),
31  LegacyResourceConsumers(Options.get(
32  "LegacyResourceConsumers", "::free;::realloc;::freopen;::fclose")) {
33  }
34 
35  /// Make configuration of checker discoverable.
36  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
37 
38  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40 
41 private:
42  bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
43  bool handleLegacyConsumers(const ast_matchers::BoundNodes &Nodes);
44  bool handleExpectedOwner(const ast_matchers::BoundNodes &Nodes);
45  bool handleAssignmentAndInit(const ast_matchers::BoundNodes &Nodes);
46  bool handleAssignmentFromNewOwner(const ast_matchers::BoundNodes &Nodes);
47  bool handleReturnValues(const ast_matchers::BoundNodes &Nodes);
48  bool handleOwnerMembers(const ast_matchers::BoundNodes &Nodes);
49 
50  /// List of old C-style functions that create resources.
51  /// Defaults to
52  /// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
53  const std::string LegacyResourceProducers;
54  /// List of old C-style functions that consume or release resources.
55  /// Defaults to `::free;::realloc;::freopen;::fclose`.
56  const std::string LegacyResourceConsumers;
57 };
58 
59 } // namespace cppcoreguidelines
60 } // namespace tidy
61 } // namespace clang
62 
63 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Match common cases, where the owner semantic is relevant, like function calls, delete expressions and...
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
static constexpr llvm::StringLiteral Name
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.