1ca8e20cdSJonas Toth //===--- UseNodiscardCheck.h - clang-tidy -----------------------*- C++ -*-===// 2ca8e20cdSJonas Toth // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ca8e20cdSJonas Toth // 7ca8e20cdSJonas Toth //===----------------------------------------------------------------------===// 8ca8e20cdSJonas Toth 9ca8e20cdSJonas Toth #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H 10ca8e20cdSJonas Toth #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H 11ca8e20cdSJonas Toth 12478fc5c8SAlexander Kornienko #include "../ClangTidyCheck.h" 13ca8e20cdSJonas Toth 14*4718da50SCarlos Galvez namespace clang::tidy::modernize { 15ca8e20cdSJonas Toth 16282dc72cSDmitri Gribenko /// Add ``[[nodiscard]]`` to non-void const-member functions with no 17ca8e20cdSJonas Toth /// arguments or pass-by-value or pass by const-reference arguments. 18ca8e20cdSJonas Toth /// \code 19ca8e20cdSJonas Toth /// bool empty() const; 20ca8e20cdSJonas Toth /// bool empty(const Bar &) const; 21ca8e20cdSJonas Toth /// bool empty(int bar) const; 22ca8e20cdSJonas Toth /// \endcode 23ca8e20cdSJonas Toth /// Is converted to: 24ca8e20cdSJonas Toth /// \code 25ca8e20cdSJonas Toth /// [[nodiscard]] bool empty() const; 26ca8e20cdSJonas Toth /// [[nodiscard]] bool empty(const Bar &) const; 27ca8e20cdSJonas Toth /// [[nodiscard]] bool empty(int bar) const; 28ca8e20cdSJonas Toth /// \endcode 29ca8e20cdSJonas Toth /// 30ca8e20cdSJonas Toth /// For the user-facing documentation see: 316e566bc5SRichard /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html 32ca8e20cdSJonas Toth class UseNodiscardCheck : public ClangTidyCheck { 33ca8e20cdSJonas Toth public: 34ca8e20cdSJonas Toth UseNodiscardCheck(StringRef Name, ClangTidyContext *Context); 35e40a742aSNathan James bool isLanguageVersionSupported(const LangOptions &LangOpts) const override; 36ca8e20cdSJonas Toth void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 37ca8e20cdSJonas Toth void registerMatchers(ast_matchers::MatchFinder *Finder) override; 38ca8e20cdSJonas Toth void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 39ca8e20cdSJonas Toth 40ca8e20cdSJonas Toth private: 4112cb5405SNathan James const StringRef NoDiscardMacro; 42ca8e20cdSJonas Toth }; 43ca8e20cdSJonas Toth 44*4718da50SCarlos Galvez } // namespace clang::tidy::modernize 45ca8e20cdSJonas Toth 46ca8e20cdSJonas Toth #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H 47