brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 6ed3025 Raw
50 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H11 12#include "../ClangTidyCheck.h"13#include "../utils/ExceptionSpecAnalyzer.h"14#include "clang/AST/Decl.h"15#include "llvm/ADT/StringRef.h"16 17namespace clang::tidy::performance {18 19/// Generic check which checks if the bound function decl is20/// marked with `noexcept` or `noexcept(expr)` where `expr` evaluates to21/// `false`.22class NoexceptFunctionBaseCheck : public ClangTidyCheck {23public: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 check(const ast_matchers::MatchFinder::MatchResult &Result) final;31  std::optional<TraversalKind> getCheckTraversalKind() const override {32    return TK_IgnoreUnlessSpelledInSource;33  }34 35protected:36  virtual DiagnosticBuilder37  reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0;38  virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,39                                              const Expr *NoexceptExpr) = 0;40 41  static constexpr StringRef BindFuncDeclName = "FuncDecl";42 43private:44  utils::ExceptionSpecAnalyzer SpecAnalyzer;45};46 47} // namespace clang::tidy::performance48 49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONBASECHECK_H50