Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===--- UseNodiscardCheck.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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H |
| 11 | |
| 12 | #include "../ClangTidyCheck.h" |
| 13 | |
| 14 | namespace clang { |
| 15 | namespace tidy { |
| 16 | namespace modernize { |
| 17 | |
| 18 | /// Add ``[[nodiscard]]`` to non-void const-member functions with no |
| 19 | /// arguments or pass-by-value or pass by const-reference arguments. |
| 20 | /// \code |
| 21 | /// bool empty() const; |
| 22 | /// bool empty(const Bar &) const; |
| 23 | /// bool empty(int bar) const; |
| 24 | /// \endcode |
| 25 | /// Is converted to: |
| 26 | /// \code |
| 27 | /// [[nodiscard]] bool empty() const; |
| 28 | /// [[nodiscard]] bool empty(const Bar &) const; |
| 29 | /// [[nodiscard]] bool empty(int bar) const; |
| 30 | /// \endcode |
| 31 | /// |
| 32 | /// For the user-facing documentation see: |
| 33 | /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nodiscard.html |
| 34 | class UseNodiscardCheck : public ClangTidyCheck { |
| 35 | public: |
| 36 | UseNodiscardCheck(StringRef Name, ClangTidyContext *Context); |
| 37 | bool isLanguageVersionSupported(const LangOptions &LangOpts) const override; |
| 38 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 39 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 40 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 41 | |
| 42 | private: |
| 43 | const std::string NoDiscardMacro; |
| 44 | }; |
| 45 | |
| 46 | } // namespace modernize |
| 47 | } // namespace tidy |
| 48 | } // namespace clang |
| 49 | |
| 50 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H |