1 //===--- ExceptionSpecAnalyzer.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_UTILS_EXCEPTION_SPEC_ANALYZER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H
12 #include "clang/AST/DeclCXX.h"
13 #include "llvm/ADT/DenseMap.h"
15 namespace clang::tidy::utils
{
17 /// This class analysis if a `FunctionDecl` has been declared implicitly through
18 /// defaulting or explicitly as throwing or not and evaluates noexcept
19 /// expressions if needed. Unlike the `ExceptionAnalyzer` however it can't tell
20 /// you if the function will actually throw an exception or not.
21 class ExceptionSpecAnalyzer
{
24 Throwing
, ///< This function has been declared as possibly throwing.
25 NotThrowing
, ///< This function has been declared as not throwing.
26 Unknown
, ///< We're unable to tell if this function is declared as throwing
30 ExceptionSpecAnalyzer() = default;
32 State
analyze(const FunctionDecl
*FuncDecl
);
35 enum class DefaultableMemberKind
{
51 State
analyzeImpl(const FunctionDecl
*FuncDecl
);
53 State
analyzeUnresolvedOrDefaulted(const CXXMethodDecl
*MethodDecl
,
54 const FunctionProtoType
*FuncProto
);
56 State
analyzeFieldDecl(const FieldDecl
*FDecl
, DefaultableMemberKind Kind
);
58 State
analyzeBase(const CXXBaseSpecifier
&Base
, DefaultableMemberKind Kind
);
60 enum class SkipMethods
: bool {
65 State
analyzeRecord(const CXXRecordDecl
*RecDecl
, DefaultableMemberKind Kind
,
66 SkipMethods SkipMethods
= SkipMethods::No
);
68 static State
analyzeFunctionEST(const FunctionDecl
*FuncDecl
,
69 const FunctionProtoType
*FuncProto
);
71 static bool hasTrivialMemberKind(const CXXRecordDecl
*RecDecl
,
72 DefaultableMemberKind Kind
);
74 static bool isConstructor(DefaultableMemberKind Kind
);
76 static bool isSpecialMember(DefaultableMemberKind Kind
);
78 static bool isComparison(DefaultableMemberKind Kind
);
80 static DefaultableMemberKind
81 getDefaultableMemberKind(const FunctionDecl
*FuncDecl
);
83 llvm::DenseMap
<const FunctionDecl
*, State
> FunctionCache
{32u};
86 } // namespace clang::tidy::utils
88 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_EXCEPTION_SPEC_ANALYZER_H