aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2021-03-09 15:04:51 -0800
committerRichard Smith <richard@metafoo.co.uk>2021-03-09 15:06:06 -0800
commita892b0015ed6af5945d06e87ca5da1ad8be7ad29 (patch)
tree07844cf898beacd4538e8998602d684a44494384 /clang/lib/AST/ExprConstant.cpp
parent234f3211a3dd84bb2c074402054452af24b914a6 (diff)
downloadllvm-a892b0015ed6af5945d06e87ca5da1ad8be7ad29.zip
llvm-a892b0015ed6af5945d06e87ca5da1ad8be7ad29.tar.gz
llvm-a892b0015ed6af5945d06e87ca5da1ad8be7ad29.tar.bz2
PR49465: Disallow constant evaluation of a call to operator delete(nullptr).
The only time we would consider allowing this is inside a call to std::allocator<T>::deallocate, whose contract does not permit deletion of null pointers.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ae7131e..4213beb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6712,9 +6712,12 @@ bool HandleOperatorDeleteCall(EvalInfo &Info, const CallExpr *E) {
if (Pointer.Designator.Invalid)
return false;
- // Deleting a null pointer has no effect.
- if (Pointer.isNullPointer())
+ // Deleting a null pointer would have no effect, but it's not permitted by
+ // std::allocator<T>::deallocate's contract.
+ if (Pointer.isNullPointer()) {
+ Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_deallocate_null);
return true;
+ }
if (!CheckDeleteKind(Info, E, Pointer, DynAlloc::StdAllocator))
return false;