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
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
UseNodiscardCheck(StringRef Name, ClangTidyContext *Context)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Add [[nodiscard]] to non-void const-member functions with no arguments or pass-by-value or pass by co...
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.