blob: 4aad852c8b0de6b5e97db0ebb83d7ce6a62ce073 [file] [log] [blame]
Angel Garcia Gomez19016712015-08-25 13:03:43 +00001//===--- 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
16namespace clang {
17namespace tidy {
18namespace modernize {
19
20/// \brief Transforms the deprecated \c std::auto_ptr into the C++11 \c
21/// std::unique_ptr.
22///
23/// Note that both the \c std::auto_ptr type and the transfer of ownership are
24/// transformed. \c std::auto_ptr provides two ways to transfer the ownership,
25/// the copy-constructor and the assignment operator. Unlike most classes these
26/// operations do not 'copy' the resource but they 'steal' it.
27/// \c std::unique_ptr uses move semantics instead, which makes the intent of
28/// transferring the resource explicit. This difference between the two smart
29/// pointers requeres to wrap the copy-ctor and assign-operator with
30/// \c std::move().
31///
32/// For example, given:
33/// \code
34/// std::auto_ptr<int> i, j;
35/// i = j;
36/// \endcode
37/// This code is transformed to:
38/// \code
39/// std::unique_ptr<in> i, j;
40/// i = std::move(j);
41/// \endcode
42class ReplaceAutoPtrCheck : public ClangTidyCheck {
43public:
44 ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context);
45 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
46 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
47 void registerPPCallbacks(CompilerInstance &Compiler) override;
48 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
49
50private:
51 std::unique_ptr<IncludeInserter> Inserter;
52 const IncludeSorter::IncludeStyle IncludeStyle;
53};
54
55} // namespace modernize
56} // namespace tidy
57} // namespace clang
58
59#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H