clang-tools  14.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 
14 namespace clang {
15 namespace tidy {
16 namespace modernize {
17 
18 /// Add ``[[nodiscard]]`` to non-void const-member functions with no
19 /// arguments or pass-by-value or pass by const-reference arguments.
20 /// \code
21 /// bool empty() const;
22 /// bool empty(const Bar &) const;
23 /// bool empty(int bar) const;
24 /// \endcode
25 /// Is converted to:
26 /// \code
27 /// [[nodiscard]] bool empty() const;
28 /// [[nodiscard]] bool empty(const Bar &) const;
29 /// [[nodiscard]] bool empty(int bar) const;
30 /// \endcode
31 ///
32 /// For the user-facing documentation see:
33 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nodiscard.html
35 public:
36  UseNodiscardCheck(StringRef Name, ClangTidyContext *Context);
37  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
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
clang::tidy::modernize::UseNodiscardCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::modernize::UseNodiscardCheck::UseNodiscardCheck
UseNodiscardCheck(StringRef Name, ClangTidyContext *Context)
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::modernize::UseNodiscardCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
clang::tidy::modernize::UseNodiscardCheck
Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by co...
Definition: UseNodiscardCheck.h:34
clang::tidy::modernize::UseNodiscardCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::modernize::UseNodiscardCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.