1 //===--- NoexceptFunctionCheck.h - clang-tidy -------------------*- C++ -*-===//
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
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
22 class NoexceptFunctionBaseCheck
: public ClangTidyCheck
{
24 NoexceptFunctionBaseCheck(StringRef Name
, ClangTidyContext
*Context
)
25 : ClangTidyCheck(Name
, Context
) {}
27 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
28 return LangOpts
.CPlusPlus11
&& LangOpts
.CXXExceptions
;
31 check(const ast_matchers::MatchFinder::MatchResult
&Result
) final override
;
32 std::optional
<TraversalKind
> getCheckTraversalKind() const override
{
33 return TK_IgnoreUnlessSpelledInSource
;
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";
45 utils::ExceptionSpecAnalyzer SpecAnalyzer
;
48 } // namespace clang::tidy::performance
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H