Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ExceptionSpecAnalyzer.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_UTILS_EXCEPTION_SPEC_ANALYZER_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H
0011 
0012 #include "clang/AST/DeclCXX.h"
0013 #include "llvm/ADT/DenseMap.h"
0014 
0015 namespace clang::tidy::utils {
0016 
0017 /// This class analysis if a `FunctionDecl` has been declared implicitly through
0018 /// defaulting or explicitly as throwing or not and evaluates noexcept
0019 /// expressions if needed. Unlike the `ExceptionAnalyzer` however it can't tell
0020 /// you if the function will actually throw an exception or not.
0021 class ExceptionSpecAnalyzer {
0022 public:
0023   enum class State {
0024     Throwing,    ///< This function has been declared as possibly throwing.
0025     NotThrowing, ///< This function has been declared as not throwing.
0026     Unknown, ///< We're unable to tell if this function is declared as throwing
0027              ///< or not.
0028   };
0029 
0030   ExceptionSpecAnalyzer() = default;
0031 
0032   State analyze(const FunctionDecl *FuncDecl);
0033 
0034 private:
0035   enum class DefaultableMemberKind {
0036     DefaultConstructor,
0037     CopyConstructor,
0038     MoveConstructor,
0039     CopyAssignment,
0040     MoveAssignment,
0041     Destructor,
0042 
0043     CompareEqual,
0044     CompareNotEqual,
0045     CompareThreeWay,
0046     CompareRelational,
0047 
0048     None,
0049   };
0050 
0051   State analyzeImpl(const FunctionDecl *FuncDecl);
0052 
0053   State analyzeUnresolvedOrDefaulted(const CXXMethodDecl *MethodDecl,
0054                                      const FunctionProtoType *FuncProto);
0055 
0056   State analyzeFieldDecl(const FieldDecl *FDecl, DefaultableMemberKind Kind);
0057 
0058   State analyzeBase(const CXXBaseSpecifier &Base, DefaultableMemberKind Kind);
0059 
0060   enum class SkipMethods : bool {
0061     Yes = true,
0062     No = false,
0063   };
0064 
0065   State analyzeRecord(const CXXRecordDecl *RecordDecl,
0066                       DefaultableMemberKind Kind,
0067                       SkipMethods SkipMethods = SkipMethods::No);
0068 
0069   static State analyzeFunctionEST(const FunctionDecl *FuncDecl,
0070                                   const FunctionProtoType *FuncProto);
0071 
0072   static bool hasTrivialMemberKind(const CXXRecordDecl *RecDecl,
0073                                    DefaultableMemberKind Kind);
0074 
0075   static bool isConstructor(DefaultableMemberKind Kind);
0076 
0077   static bool isSpecialMember(DefaultableMemberKind Kind);
0078 
0079   static bool isComparison(DefaultableMemberKind Kind);
0080 
0081   static DefaultableMemberKind
0082   getDefaultableMemberKind(const FunctionDecl *FuncDecl);
0083 
0084   llvm::DenseMap<const FunctionDecl *, State> FunctionCache{32U};
0085 };
0086 
0087 } // namespace clang::tidy::utils
0088 
0089 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H