[libc++] Fix issues with the triviality of std::array
The Standard is currently unimplementable. We have to pick between:
1. Not implementing constexpr support properly in std::array<T, 0>
2. Making std::array<T, 0> non-trivial even when T is trivial
3. Returning nullptr from std::array<T, 0>::begin()
Libc++ initially picked (1). In 77b9abfc8e89, we started implementing constexpr properly, but lost the guarantee of triviality. Since it seems like both (1) and (2) are really important, it seems like (3) is the only viable option for libc++, after all. This is also what other implementations are doing.
This patch moves libc++ from (1) to (3).
It also:
- Improves the test coverage for the various ways of initializing std::array
- Adds tests for the triviality of std::array
- Adds tests for the aggregate-ness of std::array
Reviewed By: #libc, miscco, EricWF, zoecarver
Differential Revision: https://reviews.llvm.org/D80821
Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 7265ff928a974a844b6301c139cbb0f957532da9
diff --git a/include/array b/include/array
index 215d4e8..6874377 100644
--- a/include/array
+++ b/include/array
@@ -242,31 +242,16 @@
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-#ifndef _LIBCPP_CXX03_LANG
- union __wrapper {
- _LIBCPP_CONSTEXPR __wrapper() : __b() { }
- ~__wrapper() = default;
-
- bool __b;
- _Tp __t;
- } __w;
-
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
- value_type* data() _NOEXCEPT {return &__w.__t;}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
- const value_type* data() const _NOEXCEPT {return &__w.__t;}
-#else // C++03
typedef typename conditional<is_const<_Tp>::value, const char,
char>::type _CharType;
struct _ArrayInStructT { _Tp __data_[1]; };
_ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
- _LIBCPP_INLINE_VISIBILITY
- value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
- _LIBCPP_INLINE_VISIBILITY
- const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
-#endif
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ value_type* data() _NOEXCEPT {return nullptr;}
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ const value_type* data() const _NOEXCEPT {return nullptr;}
// No explicit construct/copy/destroy for aggregate type
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17