clang-tools
11.0.0
clang-tools-extra
clang-tidy
cppcoreguidelines
NoMallocCheck.h
Go to the documentation of this file.
1
//===--- NoMallocCheck.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_NO_MALLOC_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang
{
15
namespace
tidy {
16
namespace
cppcoreguidelines {
17
18
/// This checker is concerned with C-style memory management and suggest modern
19
/// alternatives to it.
20
/// The check is only enabled in C++. For analyzing malloc calls see Clang
21
/// Static Analyzer - unix.Malloc.
22
///
23
/// For the user-facing documentation see:
24
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-no-malloc.html
25
class
NoMallocCheck
:
public
ClangTidyCheck
{
26
public
:
27
/// Construct Checker and read in configuration for function names.
28
NoMallocCheck
(StringRef
Name
,
ClangTidyContext
*Context)
29
:
ClangTidyCheck
(
Name
, Context),
30
AllocList(
Options
.get(
"Allocations"
,
"::malloc;::calloc"
)),
31
ReallocList(
Options
.get(
"Reallocations"
,
"::realloc"
)),
32
DeallocList(
Options
.get(
"Deallocations"
,
"::free"
)) {}
33
34
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
35
return
LangOpts.CPlusPlus;
36
}
37
38
/// Make configuration of checker discoverable.
39
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
40
41
/// Registering for malloc, calloc, realloc and free calls.
42
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
43
44
/// Checks matched function calls and gives suggestion to modernize the code.
45
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
46
47
private
:
48
/// Semicolon-separated list of fully qualified names of memory allocation
49
/// functions the check warns about. Defaults to `::malloc;::calloc`.
50
const
std::string AllocList;
51
/// Semicolon-separated list of fully qualified names of memory reallocation
52
/// functions the check warns about. Defaults to `::realloc`.
53
const
std::string ReallocList;
54
/// Semicolon-separated list of fully qualified names of memory deallocation
55
/// functions the check warns about. Defaults to `::free`.
56
const
std::string DeallocList;
57
};
58
59
}
// namespace cppcoreguidelines
60
}
// namespace tidy
61
}
// namespace clang
62
63
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
clang::tidy::cppcoreguidelines::NoMallocCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Checks matched function calls and gives suggestion to modernize the code.
Definition:
NoMallocCheck.cpp:58
clang::tidy::cppcoreguidelines::NoMallocCheck
This checker is concerned with C-style memory management and suggest modern alternatives to it.
Definition:
NoMallocCheck.h:25
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:114
clang::tidy::cppcoreguidelines::NoMallocCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Registering for malloc, calloc, realloc and free calls.
Definition:
NoMallocCheck.cpp:39
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
clang::tidy::cppcoreguidelines::NoMallocCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition:
NoMallocCheck.cpp:33
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::cppcoreguidelines::NoMallocCheck::NoMallocCheck
NoMallocCheck(StringRef Name, ClangTidyContext *Context)
Construct Checker and read in configuration for function names.
Definition:
NoMallocCheck.h:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::cppcoreguidelines::NoMallocCheck::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:
NoMallocCheck.h:34
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:111
Generated on Tue Jul 28 2020 16:14:02 for clang-tools by
1.8.16