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
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
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.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
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.