clang-tools 8.0.0

UseNodiscardCheck.h
Go to the documentation of this file.
1 //===--- UseNodiscardCheck.h - clang-tidy -----------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
12
13 #include "../ClangTidy.h"
14
15 namespace clang {
16 namespace tidy {
17 namespace modernize {
18
19 /// \brief Add ``[[nodiscard]]`` to non-void const-member functions with no
20 /// arguments or pass-by-value or pass by const-reference arguments.
21 /// \code
22 /// bool empty() const;
23 /// bool empty(const Bar &) const;
24 /// bool empty(int bar) const;
25 /// \endcode
26 /// Is converted to:
27 /// \code
28 /// [[nodiscard]] bool empty() const;
29 /// [[nodiscard]] bool empty(const Bar &) const;
30 /// [[nodiscard]] bool empty(int bar) const;
31 /// \endcode
32 ///
33 /// For the user-facing documentation see:
34 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nodiscard.html
35 class UseNodiscardCheck : public ClangTidyCheck {
36 public:
37 UseNodiscardCheck(StringRef Name, ClangTidyContext *Context);
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::UseNodiscardCheck
UseNodiscardCheck(StringRef Name, ClangTidyContext *Context)
Definition: UseNodiscardCheck.cpp:79
clang::tidy::modernize::UseNodiscardCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: UseNodiscardCheck.cpp:87
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:35
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:98
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition: ClangdServer.cpp:60
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:83
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:100
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:118