summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtr.h
blob: ced67706932217a3a68a4dfdc45be797b24a8684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//===-- ReplaceAutoPtr.h ------------ std::auto_ptr replacement -*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the declaration of the ReplaceAutoPtrTransform
/// class.
///
//===----------------------------------------------------------------------===//

#ifndef CLANG_MODERNIZE_REPLACE_AUTO_PTR_H
#define CLANG_MODERNIZE_REPLACE_AUTO_PTR_H

#include "Core/Transform.h"
#include "llvm/Support/Compiler.h"

/// \brief Subclass of Transform that transforms the deprecated \c std::auto_ptr
/// into the C++11 \c std::unique_ptr.
///
/// Note that both the \c std::auto_ptr type and the transfer of ownership are
/// transformed. \c std::auto_ptr provides two ways to transfer the ownership,
/// the copy-constructor and the assignment operator. Unlike most classes theses
/// operations do not 'copy' the resource but they 'steal' it.
/// \c std::unique_ptr uses move semantics instead, which makes the intent of
/// transferring the resource explicit. This difference between the two smart
/// pointers requires to wrap the copy-ctor and assign-operator with
/// \c std::move().
///
/// For example, given:
/// \code
///   std::auto_ptr<int> i, j;
///   i = j;
/// \endcode
/// the code is transformed to:
/// \code
///   std::unique_ptr<int> i, j;
///   i = std::move(j);
/// \endcode
class ReplaceAutoPtrTransform : public Transform {
public:
  ReplaceAutoPtrTransform(const TransformOptions &Options)
      : Transform("ReplaceAutoPtr", Options) {}

  /// \see Transform::run().
  virtual int apply(const FileOverrides &InputStates,
                    const clang::tooling::CompilationDatabase &Database,
                    const std::vector<std::string> &SourcePaths) LLVM_OVERRIDE;
};

#endif // CLANG_MODERNIZE_REPLACE_AUTO_PTR_H
OpenPOWER on IntegriCloud