diff options
author | David Tolnay <dtolnay@gmail.com> | 2021-03-28 02:00:02 -0400 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2021-03-28 02:03:21 -0400 |
commit | bb98d9eb09962903f3c23343d991aae8b373e1fd (patch) | |
tree | 0afcf8bec038386a1896b064e520e6c3752112b7 | |
parent | 96ee470356e322a3d3967dd28738a95c4ad2acdd (diff) | |
download | cxx-bb98d9eb09962903f3c23343d991aae8b373e1fd.tar.gz |
Allow slice null ptr safely if slice is empty
-rw-r--r-- | include/cxx.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/include/cxx.h b/include/cxx.h index c2b345d2..cdc63fbf 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -505,8 +505,12 @@ Slice<T>::Slice() noexcept { template <typename T> Slice<T>::Slice(T *s, std::size_t count) noexcept { - assert(s != nullptr); - sliceInit(this, const_cast<typename std::remove_const<T>::type *>(s), count); + assert(s != nullptr || count == 0); + sliceInit(this, + s == nullptr && count == 0 + ? reinterpret_cast<void *>(align_of<T>()) + : const_cast<typename std::remove_const<T>::type *>(s), + count); } template <typename T> |