| 1 | //===--- NoexceptFunctionCheck.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_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H |
| 11 | |
| 12 | #include "../ClangTidyCheck.h" |
| 13 | #include "../utils/ExceptionSpecAnalyzer.h" |
| 14 | #include "clang/AST/Decl.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | |
| 17 | namespace clang::tidy::performance { |
| 18 | |
| 19 | /// Generic check which checks if the bound function decl is |
| 20 | /// marked with `noexcept` or `noexcept(expr)` where `expr` evaluates to |
| 21 | /// `false`. |
| 22 | class NoexceptFunctionBaseCheck : public ClangTidyCheck { |
| 23 | public: |
| 24 | NoexceptFunctionBaseCheck(StringRef Name, ClangTidyContext *Context) |
| 25 | : ClangTidyCheck(Name, Context) {} |
| 26 | |
| 27 | bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { |
| 28 | return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions; |
| 29 | } |
| 30 | void |
| 31 | check(const ast_matchers::MatchFinder::MatchResult &Result) final override; |
| 32 | std::optional<TraversalKind> getCheckTraversalKind() const override { |
| 33 | return TK_IgnoreUnlessSpelledInSource; |
| 34 | } |
| 35 | |
| 36 | protected: |
| 37 | virtual DiagnosticBuilder |
| 38 | reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0; |
| 39 | virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl, |
| 40 | const Expr *NoexceptExpr) = 0; |
| 41 | |
| 42 | static constexpr StringRef BindFuncDeclName = "FuncDecl"; |
| 43 | |
| 44 | private: |
| 45 | utils::ExceptionSpecAnalyzer SpecAnalyzer; |
| 46 | }; |
| 47 | |
| 48 | } // namespace clang::tidy::performance |
| 49 | |
| 50 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H |
| 51 |
