clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
modernize
ReplaceAutoPtrCheck.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
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_MODERNIZE_REPLACE_AUTO_PTR_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
11
12
#include "
../ClangTidyCheck.h
"
13
#include "
../utils/IncludeInserter.h
"
14
15
namespace
clang::tidy::modernize
{
16
17
/// Transforms the deprecated `std::auto_ptr` into the C++11 `std::unique_ptr`.
18
///
19
/// Note that both the `std::auto_ptr` type and the transfer of ownership are
20
/// transformed. `std::auto_ptr` provides two ways to transfer the ownership,
21
/// the copy-constructor and the assignment operator. Unlike most classes these
22
/// operations do not 'copy' the resource but they 'steal' it.
23
/// `std::unique_ptr` uses move semantics instead, which makes the intent of
24
/// transferring the resource explicit. This difference between the two smart
25
/// pointers requires wrapping the copy-ctor and assign-operator with
26
/// `std::move()`.
27
///
28
/// For example, given:
29
///
30
/// \code
31
/// std::auto_ptr<int> i, j;
32
/// i = j;
33
/// \endcode
34
///
35
/// This code is transformed to:
36
///
37
/// \code
38
/// std::unique_ptr<in> i, j;
39
/// i = std::move(j);
40
/// \endcode
41
class
ReplaceAutoPtrCheck
:
public
ClangTidyCheck
{
42
public
:
43
ReplaceAutoPtrCheck
(StringRef Name,
ClangTidyContext
*Context);
44
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
45
return
LangOpts.CPlusPlus11;
46
}
47
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
48
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
49
void
registerPPCallbacks
(
const
SourceManager &SM, Preprocessor *PP,
50
Preprocessor *ModuleExpanderPP)
override
;
51
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
52
53
private
:
54
utils::IncludeInserter Inserter;
55
};
56
57
}
// namespace clang::tidy::modernize
58
59
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
ClangTidyCheck.h
IncludeInserter.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::modernize::ReplaceAutoPtrCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Definition
ReplaceAutoPtrCheck.cpp:45
clang::tidy::modernize::ReplaceAutoPtrCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
ReplaceAutoPtrCheck.cpp:49
clang::tidy::modernize::ReplaceAutoPtrCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Definition
ReplaceAutoPtrCheck.h:44
clang::tidy::modernize::ReplaceAutoPtrCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Definition
ReplaceAutoPtrCheck.cpp:92
clang::tidy::modernize::ReplaceAutoPtrCheck::ReplaceAutoPtrCheck
ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context)
Definition
ReplaceAutoPtrCheck.cpp:38
clang::tidy::modernize::ReplaceAutoPtrCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
ReplaceAutoPtrCheck.cpp:98
clang::tidy::modernize
Definition
AvoidBindCheck.cpp:29
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition
ClangTidyOptions.h:128
Generated on
for clang-tools by
1.14.0