1 //===--- UseNodiscardCheck.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_MODERNIZE_USENODISCARDCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
12 #include "../ClangTidyCheck.h"
14 namespace clang::tidy::modernize
{
16 /// Add ``[[nodiscard]]`` to non-void const-member functions with no
17 /// arguments or pass-by-value or pass by const-reference arguments.
19 /// bool empty() const;
20 /// bool empty(const Bar &) const;
21 /// bool empty(int bar) const;
25 /// [[nodiscard]] bool empty() const;
26 /// [[nodiscard]] bool empty(const Bar &) const;
27 /// [[nodiscard]] bool empty(int bar) const;
30 /// For the user-facing documentation see:
31 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html
32 class UseNodiscardCheck
: public ClangTidyCheck
{
34 UseNodiscardCheck(StringRef Name
, ClangTidyContext
*Context
);
35 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
;
36 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
37 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
38 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
41 const StringRef NoDiscardMacro
;
44 } // namespace clang::tidy::modernize
46 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H