[libcxx-commits] [PATCH] D120633: [libc++] Better handling for zero-sized types
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 28 10:14:51 PST 2022
Mordante added a subscriber: CaseyCarter.
Mordante added inline comments.
================
Comment at: libcxx/include/__memory/unique_ptr.h:50
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
- static_assert(sizeof(_Tp) > 0,
- "default_delete can not delete incomplete type");
- static_assert(!is_void<_Tp>::value,
- "default_delete can not delete incomplete type");
+ static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
delete __ptr;
----------------
I would like a comment explaining why `sizeof(_Tp) == 0` is possible.
Looking at the number of `sizeof(_Tp) >= 0` in the code, would it make sense to add a type trait `__is_complete` and add the explanation there?
================
Comment at: libcxx/test/std/ranges/range.access/begin.sizezero.pass.cpp:23
+};
+static_assert(sizeof(A) == 0); // an extension supported by GCC and Clang
+
----------------
I think it would be better to move this comment to line 11 to describe what the test is about.
Let's make sure the test also works on MSVC, where the size is 4. That will probably make @CaseyCarter happy.
================
Comment at: libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.sizezero.pass.cpp:11
+
+#include <memory>
+#include <cassert>
----------------
Should there be a similar test for `std::shared_ptr`?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120633/new/
https://reviews.llvm.org/D120633
More information about the libcxx-commits
mailing list