diff options
author | Richard Smith <richard@metafoo.co.uk> | 2021-03-09 15:04:51 -0800 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2021-03-09 15:06:06 -0800 |
commit | a892b0015ed6af5945d06e87ca5da1ad8be7ad29 (patch) | |
tree | 07844cf898beacd4538e8998602d684a44494384 /clang/lib/AST/ExprConstant.cpp | |
parent | 234f3211a3dd84bb2c074402054452af24b914a6 (diff) | |
download | llvm-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.cpp | 7 |
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; |