[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
[llvm-project.git] / clang-tools-extra / clang-tidy / readability / RedundantSmartptrGetCheck.h
blobffe8df8857dfe80f7bd9ae7288c8f6f6c459d827
1 //===--- RedundantSmartptrGetCheck.h - clang-tidy ---------------*- C++ -*-===//
2 //
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
6 //
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"
14 namespace clang::tidy::readability {
16 /// Find and remove redundant calls to smart pointer's `.get()` method.
17 ///
18 /// Examples:
19 ///
20 /// \code
21 /// ptr.get()->Foo() ==> ptr->Foo()
22 /// *ptr.get() ==> *ptr
23 /// *ptr->get() ==> **ptr
24 /// \endcode
25 class RedundantSmartptrGetCheck : public ClangTidyCheck {
26 public:
27 RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
28 : ClangTidyCheck(Name, Context),
29 IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
30 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
31 return LangOpts.CPlusPlus;
33 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
34 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
35 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
36 std::optional<TraversalKind> getCheckTraversalKind() const override {
37 return TK_IgnoreUnlessSpelledInSource;
40 private:
41 const bool IgnoreMacros;
44 } // namespace clang::tidy::readability
46 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H