Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- UniqueptrResetReleaseCheck.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_MISC_UNIQUEPTRRESETRELEASECHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNIQUEPTRRESETRELEASECHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 
0015 namespace clang::tidy::misc {
0016 
0017 /// Find and replace `unique_ptr::reset(release())` with `std::move()`.
0018 ///
0019 /// Example:
0020 ///
0021 /// \code
0022 ///   std::unique_ptr<Foo> x, y;
0023 ///   x.reset(y.release()); -> x = std::move(y);
0024 /// \endcode
0025 ///
0026 /// If `y` is already rvalue, `std::move()` is not added.  `x` and `y` can also
0027 /// be `std::unique_ptr<Foo>*`.
0028 class UniqueptrResetReleaseCheck : public ClangTidyCheck {
0029 public:
0030   UniqueptrResetReleaseCheck(StringRef Name, ClangTidyContext *Context);
0031 
0032   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0033     // Only register the matchers for C++11; the functionality currently does
0034     // not
0035     // provide any benefit to other languages, despite being benign.
0036     return LangOpts.CPlusPlus11;
0037   }
0038   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0039                            Preprocessor *ModuleExpanderPP) override;
0040   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0041   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0042   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0043 
0044 private:
0045   utils::IncludeInserter Inserter;
0046 };
0047 
0048 } // namespace clang::tidy::misc
0049 
0050 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNIQUEPTRRESETRELEASECHECK_H