ExceptionEscapeCheck.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===--- ExceptionEscapeCheck.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_BUGPRONE_EXCEPTION_ESCAPE_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
  10. #include "../ClangTidyCheck.h"
  11. #include "../utils/ExceptionAnalyzer.h"
  12. #include "llvm/ADT/StringSet.h"
  13. namespace clang::tidy::bugprone {
  14. /// Finds functions which should not throw exceptions: Destructors, move
  15. /// constructors, move assignment operators, the main() function,
  16. /// swap() functions, functions marked with throw() or noexcept and functions
  17. /// given as option to the checker.
  18. ///
  19. /// For the user-facing documentation see:
  20. /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-escape.html
  21. class ExceptionEscapeCheck : public ClangTidyCheck {
  22. public:
  23. ExceptionEscapeCheck(StringRef Name, ClangTidyContext *Context);
  24. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  25. return LangOpts.CPlusPlus && LangOpts.CXXExceptions;
  26. }
  27. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  28. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  29. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  30. private:
  31. std::string RawFunctionsThatShouldNotThrow;
  32. std::string RawIgnoredExceptions;
  33. llvm::StringSet<> FunctionsThatShouldNotThrow;
  34. utils::ExceptionAnalyzer Tracer;
  35. };
  36. } // namespace clang::tidy::bugprone
  37. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H