clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ReplaceAutoPtrCheck.h
Go to the documentation of this file.
1 //===--- ReplaceAutoPtrCheck.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_MODERNIZE_REPLACE_AUTO_PTR_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
12
13 #include "../ClangTidy.h"
14 #include "../utils/IncludeInserter.h"
15
16 namespace clang {
17 namespace tidy {
18 namespace modernize {
19
20 /// Transforms the deprecated `std::auto_ptr` into the C++11 `std::unique_ptr`.
21 ///
22 /// Note that both the `std::auto_ptr` type and the transfer of ownership are
23 /// transformed. `std::auto_ptr` provides two ways to transfer the ownership,
24 /// the copy-constructor and the assignment operator. Unlike most classes these
25 /// operations do not 'copy' the resource but they 'steal' it.
26 /// `std::unique_ptr` uses move semantics instead, which makes the intent of
27 /// transferring the resource explicit. This difference between the two smart
28 /// pointers requeres to wrap the copy-ctor and assign-operator with
29 /// `std::move()`.
30 ///
31 /// For example, given:
32 ///
33 /// \code
34 /// std::auto_ptr<int> i, j;
35 /// i = j;
36 /// \endcode
37 ///
38 /// This code is transformed to:
39 ///
40 /// \code
41 /// std::unique_ptr<in> i, j;
42 /// i = std::move(j);
43 /// \endcode
44 class ReplaceAutoPtrCheck : public ClangTidyCheck {
45 public:
46 ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context);
47 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
48 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
49 void registerPPCallbacks(CompilerInstance &Compiler) override;
50 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
51
52 private:
53 std::unique_ptr<IncludeInserter> Inserter;
54 const IncludeSorter::IncludeStyle IncludeStyle;
55 };
56
57 } // namespace modernize
58 } // namespace tidy
59 } // namespace clang
60
61 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
clang::tidy::modernize::ReplaceAutoPtrCheck
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
Definition: ReplaceAutoPtrCheck.h:44
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::IncludeSorter::IncludeStyle
IncludeStyle
Definition: IncludeSorter.h:26
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::modernize::ReplaceAutoPtrCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: ReplaceAutoPtrCheck.cpp:199
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:82
clang::tidy::modernize::ReplaceAutoPtrCheck::registerPPCallbacks
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Definition: ReplaceAutoPtrCheck.cpp:209
clang::tidy::modernize::ReplaceAutoPtrCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: ReplaceAutoPtrCheck.cpp:220
clang::tidy::modernize::ReplaceAutoPtrCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: ReplaceAutoPtrCheck.cpp:195
Context
ClangTidyContext & Context
Definition: ClangTidy.cpp:93
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
clang::tidy::modernize::ReplaceAutoPtrCheck::ReplaceAutoPtrCheck
ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context)
Definition: ReplaceAutoPtrCheck.cpp:189
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121