Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:21

0001 //===--- NoexceptFunctionCheck.h - clang-tidy -------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/ExceptionSpecAnalyzer.h"
0014 #include "clang/AST/Decl.h"
0015 #include "llvm/ADT/StringRef.h"
0016 
0017 namespace clang::tidy::performance {
0018 
0019 /// Generic check which checks if the bound function decl is
0020 /// marked with `noexcept` or `noexcept(expr)` where `expr` evaluates to
0021 /// `false`.
0022 class NoexceptFunctionBaseCheck : public ClangTidyCheck {
0023 public:
0024   NoexceptFunctionBaseCheck(StringRef Name, ClangTidyContext *Context)
0025       : ClangTidyCheck(Name, Context) {}
0026 
0027   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0028     return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
0029   }
0030   void
0031   check(const ast_matchers::MatchFinder::MatchResult &Result) final override;
0032   std::optional<TraversalKind> getCheckTraversalKind() const override {
0033     return TK_IgnoreUnlessSpelledInSource;
0034   }
0035 
0036 protected:
0037   virtual DiagnosticBuilder
0038   reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0;
0039   virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
0040                                               const Expr *NoexceptExpr) = 0;
0041 
0042   static constexpr StringRef BindFuncDeclName = "FuncDecl";
0043 
0044 private:
0045   utils::ExceptionSpecAnalyzer SpecAnalyzer;
0046 };
0047 
0048 } // namespace clang::tidy::performance
0049 
0050 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H