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