aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaExceptionSpec.cpp
diff options
context:
space:
mode:
authorMital Ashok <mital@mitalashok.co.uk>2024-06-20 14:43:14 +0100
committerGitHub <noreply@github.com>2024-06-20 15:43:14 +0200
commitb608b223ab152bb84c8f28a4a1184f9033c99560 (patch)
treea8d614367998c1f0684d2424c90c253e3a8541eb /clang/lib/Sema/SemaExceptionSpec.cpp
parent33c9331a9279d5d7f72afbac43de7f7da2ab63ed (diff)
downloadllvm-b608b223ab152bb84c8f28a4a1184f9033c99560.zip
llvm-b608b223ab152bb84c8f28a4a1184f9033c99560.tar.gz
llvm-b608b223ab152bb84c8f28a4a1184f9033c99560.tar.bz2
[Clang] [Sema] Ensure noexcept(typeid(E)) checks if E throws when needed (#95846)
3ad31e12ccfc7db25f3cbedc4ee966e7099ac78f changed it so that not all potentially-evaluated `typeid`s were marked as potentially-throwing, but I forgot to check the subexpression if the null check of the `typeid` didn't potentially-throw. This adds that check.
Diffstat (limited to 'clang/lib/Sema/SemaExceptionSpec.cpp')
-rw-r--r--clang/lib/Sema/SemaExceptionSpec.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp b/clang/lib/Sema/SemaExceptionSpec.cpp
index c914448..d226e3b 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1111,13 +1111,22 @@ static CanThrowResult canDynamicCastThrow(const CXXDynamicCastExpr *DC) {
}
static CanThrowResult canTypeidThrow(Sema &S, const CXXTypeidExpr *DC) {
+ // A typeid of a type is a constant and does not throw.
if (DC->isTypeOperand())
return CT_Cannot;
if (DC->isValueDependent())
return CT_Dependent;
- return DC->hasNullCheck() ? CT_Can : CT_Cannot;
+ // If this operand is not evaluated it cannot possibly throw.
+ if (!DC->isPotentiallyEvaluated())
+ return CT_Cannot;
+
+ // Can throw std::bad_typeid if a nullptr is dereferenced.
+ if (DC->hasNullCheck())
+ return CT_Can;
+
+ return S.canThrow(DC->getExprOperand());
}
CanThrowResult Sema::canThrow(const Stmt *S) {