aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-03-28 02:00:02 -0400
committerDavid Tolnay <dtolnay@gmail.com>2021-03-28 02:03:21 -0400
commitbb98d9eb09962903f3c23343d991aae8b373e1fd (patch)
tree0afcf8bec038386a1896b064e520e6c3752112b7
parent96ee470356e322a3d3967dd28738a95c4ad2acdd (diff)
downloadcxx-bb98d9eb09962903f3c23343d991aae8b373e1fd.tar.gz
Allow slice null ptr safely if slice is empty
-rw-r--r--include/cxx.h8
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>