| 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::tidy::modernize { |
| 15 |
|
| 16 |
/// Add ``[[nodiscard]]`` to non-void const-member functions with no |
| 17 |
/// arguments or pass-by-value or pass by const-reference arguments. |
| 18 |
/// \code |
| 19 |
/// bool empty() const; |
| 20 |
/// bool empty(const Bar &) const; |
| 21 |
/// bool empty(int bar) const; |
| 22 |
/// \endcode |
| 23 |
/// Is converted to: |
| 24 |
/// \code |
| 25 |
/// [[nodiscard]] bool empty() const; |
| 26 |
/// [[nodiscard]] bool empty(const Bar &) const; |
| 27 |
/// [[nodiscard]] bool empty(int bar) const; |
| 28 |
/// \endcode |
| 29 |
/// |
| 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 { |
| 33 |
public: |
| 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; |
| 39 |
|
| 40 |
private: |
| 41 |
const StringRef NoDiscardMacro; |
| 42 |
}; |
| 43 |
|
| 44 |
} // namespace clang::tidy::modernize |
| 45 |
|
| 46 |
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H |