clang-tools
11.0.0
clang-tools-extra
clang-tidy
cppcoreguidelines
OwningMemoryCheck.h
Go to the documentation of this file.
1
//===--- OwningMemoryCheck.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
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang
{
15
namespace
tidy {
16
namespace
cppcoreguidelines {
17
18
/// Checks for common use cases for gsl::owner and enforces the unique owner
19
/// nature of it whenever possible.
20
///
21
/// For the user-facing documentation see:
22
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html
23
class
OwningMemoryCheck
:
public
ClangTidyCheck
{
24
public
:
25
OwningMemoryCheck
(StringRef
Name
,
ClangTidyContext
*Context)
26
:
ClangTidyCheck
(
Name
, Context),
27
LegacyResourceProducers(
Options
.get(
28
"LegacyResourceProducers"
,
"::malloc;::aligned_alloc;::realloc;"
29
"::calloc;::fopen;::freopen;::tmpfile"
)),
30
LegacyResourceConsumers(
Options
.get(
31
"LegacyResourceConsumers"
,
"::free;::realloc;::freopen;::fclose"
)) {
32
}
33
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
34
return
LangOpts.CPlusPlus11;
35
}
36
37
/// Make configuration of checker discoverable.
38
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
39
40
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
41
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
42
43
private
:
44
bool
handleDeletion(
const
ast_matchers::BoundNodes &Nodes);
45
bool
handleLegacyConsumers(
const
ast_matchers::BoundNodes &Nodes);
46
bool
handleExpectedOwner(
const
ast_matchers::BoundNodes &Nodes);
47
bool
handleAssignmentAndInit(
const
ast_matchers::BoundNodes &Nodes);
48
bool
handleAssignmentFromNewOwner(
const
ast_matchers::BoundNodes &Nodes);
49
bool
handleReturnValues(
const
ast_matchers::BoundNodes &Nodes);
50
bool
handleOwnerMembers(
const
ast_matchers::BoundNodes &Nodes);
51
52
/// List of old C-style functions that create resources.
53
/// Defaults to
54
/// `::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
55
const
std::string LegacyResourceProducers;
56
/// List of old C-style functions that consume or release resources.
57
/// Defaults to `::free;::realloc;::freopen;::fclose`.
58
const
std::string LegacyResourceConsumers;
59
};
60
61
}
// namespace cppcoreguidelines
62
}
// namespace tidy
63
}
// namespace clang
64
65
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_OWNING_MEMORY_H
clang::tidy::cppcoreguidelines::OwningMemoryCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition:
OwningMemoryCheck.h:33
clang::tidy::cppcoreguidelines::OwningMemoryCheck::OwningMemoryCheck
OwningMemoryCheck(StringRef Name, ClangTidyContext *Context)
Definition:
OwningMemoryCheck.h:25
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:114
clang::tidy::cppcoreguidelines::OwningMemoryCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition:
OwningMemoryCheck.cpp:34
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition:
ClangTidyCheck.h:471
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:76
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::cppcoreguidelines::OwningMemoryCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Match common cases, where the owner semantic is relevant, like function calls, delete expressions and...
Definition:
OwningMemoryCheck.cpp:41
clang::tidy::cppcoreguidelines::OwningMemoryCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
OwningMemoryCheck.cpp:184
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::cppcoreguidelines::OwningMemoryCheck
Checks for common use cases for gsl::owner and enforces the unique owner nature of it whenever possib...
Definition:
OwningMemoryCheck.h:23
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:111
Generated on Tue Jul 28 2020 16:14:03 for clang-tools by
1.8.16