[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
[llvm-project.git] / clang-tools-extra / clang-tidy / performance / NoexceptFunctionBaseCheck.h
blob4775219d7e439cea7ed30b0ce4c69aae6a12c73f
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "../utils/ExceptionSpecAnalyzer.h"
14 #include "clang/AST/Decl.h"
15 #include "llvm/ADT/StringRef.h"
17 namespace clang::tidy::performance {
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) {}
27 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28 return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
30 void
31 check(const ast_matchers::MatchFinder::MatchResult &Result) final override;
32 std::optional<TraversalKind> getCheckTraversalKind() const override {
33 return TK_IgnoreUnlessSpelledInSource;
36 protected:
37 virtual DiagnosticBuilder
38 reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0;
39 virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
40 const Expr *NoexceptExpr) = 0;
42 static constexpr StringRef BindFuncDeclName = "FuncDecl";
44 private:
45 utils::ExceptionSpecAnalyzer SpecAnalyzer;
48 } // namespace clang::tidy::performance
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H