UseNodiscardCheck.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::modernize {
  12. /// Add ``[[nodiscard]]`` to non-void const-member functions with no
  13. /// arguments or pass-by-value or pass by const-reference arguments.
  14. /// \code
  15. /// bool empty() const;
  16. /// bool empty(const Bar &) const;
  17. /// bool empty(int bar) const;
  18. /// \endcode
  19. /// Is converted to:
  20. /// \code
  21. /// [[nodiscard]] bool empty() const;
  22. /// [[nodiscard]] bool empty(const Bar &) const;
  23. /// [[nodiscard]] bool empty(int bar) const;
  24. /// \endcode
  25. ///
  26. /// For the user-facing documentation see:
  27. /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-nodiscard.html
  28. class UseNodiscardCheck : public ClangTidyCheck {
  29. public:
  30. UseNodiscardCheck(StringRef Name, ClangTidyContext *Context);
  31. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
  32. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  33. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  34. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  35. private:
  36. const StringRef NoDiscardMacro;
  37. };
  38. } // namespace clang::tidy::modernize
  39. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USENODISCARDCHECK_H