1 //===--- RedundantSmartptrGetCheck.h - clang-tidy ---------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
12 #include "../ClangTidyCheck.h"
16 namespace readability
{
18 /// Find and remove redundant calls to smart pointer's `.get()` method.
23 /// ptr.get()->Foo() ==> ptr->Foo()
24 /// *ptr.get() ==> *ptr
25 /// *ptr->get() ==> **ptr
27 class RedundantSmartptrGetCheck
: public ClangTidyCheck
{
29 RedundantSmartptrGetCheck(StringRef Name
, ClangTidyContext
*Context
)
30 : ClangTidyCheck(Name
, Context
),
31 IgnoreMacros(Options
.getLocalOrGlobal("IgnoreMacros", true)) {}
32 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
33 return LangOpts
.CPlusPlus
;
35 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
36 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
37 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
38 llvm::Optional
<TraversalKind
> getCheckTraversalKind() const override
{
39 return TK_IgnoreUnlessSpelledInSource
;
43 const bool IgnoreMacros
;
46 } // namespace readability
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H