clang-tools 20.0.0git
UseNodiscardCheck.h
Go to the documentation of this file.
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
14namespace 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
33public:
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
40private:
41 const StringRef NoDiscardMacro;
42};
43
44} // namespace clang::tidy::modernize
45
46#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by co...
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
llvm::StringMap< ClangTidyValue > OptionMap