diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h --- a/libcxx/include/__memory/unique_ptr.h +++ b/libcxx/include/__memory/unique_ptr.h @@ -47,10 +47,6 @@ 0) _NOEXCEPT {} _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"); delete __ptr; } }; @@ -78,10 +74,6 @@ _LIBCPP_INLINE_VISIBILITY typename _EnableIfConvertible<_Up>::type operator()(_Up* __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 void type"); delete[] __ptr; } }; diff --git a/libcxx/include/__ranges/access.h b/libcxx/include/__ranges/access.h --- a/libcxx/include/__ranges/access.h +++ b/libcxx/include/__ranges/access.h @@ -59,14 +59,14 @@ struct __fn { template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[]) const noexcept - requires (sizeof(_Tp) != 0) // Disallow incomplete element types. + requires (sizeof(_Tp) >= 0) // Disallow incomplete element types. { return __t + 0; } template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept - requires (sizeof(_Tp) != 0) // Disallow incomplete element types. + requires (sizeof(_Tp) >= 0) // Disallow incomplete element types. { return __t + 0; } @@ -133,7 +133,7 @@ public: template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp (&__t)[_Np]) const noexcept - requires (sizeof(_Tp) != 0) // Disallow incomplete element types. + requires (sizeof(_Tp) >= 0) // Disallow incomplete element types. { return __t + _Np; } diff --git a/libcxx/test/std/ranges/range.access/begin.sizezero.pass.cpp b/libcxx/test/std/ranges/range.access/begin.sizezero.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/ranges/range.access/begin.sizezero.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// std::ranges::begin +// std::ranges::cbegin + +#include +#include + +#include "test_macros.h" + +struct A { + alignas(int[0]) int ptr[0]; +}; +static_assert(sizeof(A) == 0); + +int main(int, char**) +{ + A a[10]; + std::same_as auto p = std::ranges::begin(a); + assert(p == a); + std::same_as auto cp = std::ranges::cbegin(a); + assert(cp == a); + + return 0; +} diff --git a/libcxx/test/std/ranges/range.access/end.sizezero.pass.cpp b/libcxx/test/std/ranges/range.access/end.sizezero.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/ranges/range.access/end.sizezero.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: libcpp-no-concepts + +// std::ranges::end +// std::ranges::cend + +#include +#include + +#include "test_macros.h" + +struct A { + alignas(int[0]) int ptr[0]; +}; +static_assert(sizeof(A) == 0); + +int main(int, char**) +{ + A a[10]; + std::same_as auto p = std::ranges::end(a); + assert(p == a + 10); + std::same_as auto cp = std::ranges::cend(a); + assert(cp == a + 10); + + return 0; +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.sizezero.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.sizezero.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.sizezero.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11 + +// Test the fix for https://llvm.org/PR54100 + +#include +#include + +#include "test_macros.h" + +struct A { + alignas(int[0]) int ptr[0]; +}; + +int main(int, char**) +{ + { + std::unique_ptr p = std::make_unique(); + assert(p != nullptr); + } + { + std::unique_ptr p = std::make_unique(1); + assert(p != nullptr); + } + return 0; +}