clang-tools  5.0.0
UniqueptrResetReleaseCheck.h
Go to the documentation of this file.
1 //===--- UniqueptrResetReleaseCheck.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_MISC_UNIQUEPTRRESETRELEASECHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNIQUEPTRRESETRELEASECHECK_H
12 
13 #include "../ClangTidy.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace misc {
18 
19 /// Find and replace `unique_ptr::reset(release())` with `std::move()`.
20 ///
21 /// Example:
22 ///
23 /// \code
24 /// std::unique_ptr<Foo> x, y;
25 /// x.reset(y.release()); -> x = std::move(y);
26 /// \endcode
27 ///
28 /// If `y` is already rvalue, `std::move()` is not added. `x` and `y` can also
29 /// be `std::unique_ptr<Foo>*`.
31 public:
33  : ClangTidyCheck(Name, Context) {}
34 
35  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37 };
38 
39 } // namespace misc
40 } // namespace tidy
41 } // namespace clang
42 
43 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNIQUEPTRRESETRELEASECHECK_H
Find and replace unique_ptr::reset(release()) with std::move().
StringHandle Name
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:275
UniqueptrResetReleaseCheck(StringRef Name, ClangTidyContext *Context)
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.