clang-tools 10.0.0

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
34 class UseNodiscardCheck : public ClangTidyCheck {
35 public:
36 UseNodiscardCheck(StringRef Name, ClangTidyContext *Context);
37 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
38 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
40
41 private:
42 const std::string NoDiscardMacro;
43 };
44
45 } // namespace modernize
46 } // namespace tidy
47 } // namespace clang
48
49 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
clang::tidy::modernize::UseNodiscardCheck::UseNodiscardCheck
UseNodiscardCheck(StringRef Name, ClangTidyContext *Context)
Definition: UseNodiscardCheck.cpp:78
clang::tidy::modernize::UseNodiscardCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: UseNodiscardCheck.cpp:86
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::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
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...
Definition: UseNodiscardCheck.cpp:82
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
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.
Definition: UseNodiscardCheck.cpp:119