clang-tools  4.0.0
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
45 public:
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<utils::IncludeInserter> Inserter;
54  const utils::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
const std::string Name
Definition: USRFinder.cpp:164
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:262
IncludeStyle
Supported include styles.
Definition: IncludeSorter.h:27
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
std::map< std::string, std::string > OptionMap
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
ClangTidyContext & Context
Definition: ClangTidy.cpp:87
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context)
const NamedDecl * Result
Definition: USRFinder.cpp:162