|
|
|||
File indexing completed on 2026-05-10 08:36:20
0001 //===--- ReplaceAutoPtrCheck.h - clang-tidy----------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H 0011 0012 #include "../ClangTidyCheck.h" 0013 #include "../utils/IncludeInserter.h" 0014 0015 namespace clang::tidy::modernize { 0016 0017 /// Transforms the deprecated `std::auto_ptr` into the C++11 `std::unique_ptr`. 0018 /// 0019 /// Note that both the `std::auto_ptr` type and the transfer of ownership are 0020 /// transformed. `std::auto_ptr` provides two ways to transfer the ownership, 0021 /// the copy-constructor and the assignment operator. Unlike most classes these 0022 /// operations do not 'copy' the resource but they 'steal' it. 0023 /// `std::unique_ptr` uses move semantics instead, which makes the intent of 0024 /// transferring the resource explicit. This difference between the two smart 0025 /// pointers requires wrapping the copy-ctor and assign-operator with 0026 /// `std::move()`. 0027 /// 0028 /// For example, given: 0029 /// 0030 /// \code 0031 /// std::auto_ptr<int> i, j; 0032 /// i = j; 0033 /// \endcode 0034 /// 0035 /// This code is transformed to: 0036 /// 0037 /// \code 0038 /// std::unique_ptr<in> i, j; 0039 /// i = std::move(j); 0040 /// \endcode 0041 class ReplaceAutoPtrCheck : public ClangTidyCheck { 0042 public: 0043 ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context); 0044 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 0045 return LangOpts.CPlusPlus; 0046 } 0047 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 0048 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0049 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, 0050 Preprocessor *ModuleExpanderPP) override; 0051 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0052 0053 private: 0054 utils::IncludeInserter Inserter; 0055 }; 0056 0057 } // namespace clang::tidy::modernize 0058 0059 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_AUTO_PTR_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|