clang-tools 20.0.0git
NoexceptFunctionBaseCheck.h
Go to the documentation of this file.
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
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`.
23public:
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
36protected:
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
44private:
46};
47
48} // namespace clang::tidy::performance
49
50#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Generic check which checks if the bound function decl is marked with noexcept or noexcept(expr) where...
void check(const ast_matchers::MatchFinder::MatchResult &Result) final override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
NoexceptFunctionBaseCheck(StringRef Name, ClangTidyContext *Context)
virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl, const Expr *NoexceptExpr)=0
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
std::optional< TraversalKind > getCheckTraversalKind() const override
virtual DiagnosticBuilder reportMissingNoexcept(const FunctionDecl *FuncDecl)=0
This class analysis if a FunctionDecl has been declared implicitly through defaulting or explicitly a...
static constexpr const char FuncDecl[]