1 //===--- UseNodiscardCheck.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_MODERNIZE_USENODISCARDCHECK_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H 12 13 #include "../ClangTidy.h" 14 15 namespace clang { 16 namespace tidy { 17 namespace modernize { 18 19 /// \brief Add ``[[nodiscard]]`` to non-void const-member functions with no 20 /// arguments or pass-by-value or pass by const-reference arguments. 21 /// \code 22 /// bool empty() const; 23 /// bool empty(const Bar &) const; 24 /// bool empty(int bar) const; 25 /// \endcode 26 /// Is converted to: 27 /// \code 28 /// [[nodiscard]] bool empty() const; 29 /// [[nodiscard]] bool empty(const Bar &) const; 30 /// [[nodiscard]] bool empty(int bar) const; 31 /// \endcode 32 /// 33 /// For the user-facing documentation see: 34 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nodiscard.html 35 class UseNodiscardCheck : public ClangTidyCheck { 36 public: 37 UseNodiscardCheck(StringRef Name, ClangTidyContext *Context); 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 51