[libc++] Complete overhaul of constexpr support in std::array
This commit adds missing support for constexpr in std::array under all
standard modes up to and including C++20. It also transforms the <array>
tests to check for constexpr-friendliness under the right standard modes.
Fixes https://llvm.org/PR40124
Fixes rdar://57522096
Supersedes https://reviews.llvm.org/D60666
Differential Revision: https://reviews.llvm.org/D80452
diff --git a/libcxx/test/std/containers/sequences/array/empty.pass.cpp b/libcxx/test/std/containers/sequences/array/empty.pass.cpp
index a17aa50..8b61575 100644
--- a/libcxx/test/std/containers/sequences/array/empty.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/empty.pass.cpp
@@ -10,28 +10,45 @@
// class array
-// bool empty() const noexcept;
+// constexpr bool empty() const noexcept;
#include <array>
#include <cassert>
#include "test_macros.h"
-#include "min_allocator.h"
+
+TEST_CONSTEXPR_CXX14 bool tests()
+{
+ {
+ typedef std::array<int, 2> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.empty());
+ assert(!c.empty());
+ }
+ {
+ typedef std::array<int, 0> C;
+ C c = {};
+ ASSERT_NOEXCEPT(c.empty());
+ assert(c.empty());
+ }
+
+ return true;
+}
int main(int, char**)
{
- {
- typedef std::array<int, 2> C;
- C c;
- ASSERT_NOEXCEPT(c.empty());
- assert(!c.empty());
- }
- {
- typedef std::array<int, 0> C;
- C c;
- ASSERT_NOEXCEPT(c.empty());
- assert( c.empty());
- }
+ tests();
+#if TEST_STD_VER >= 14
+ static_assert(tests(), "");
+#endif
- return 0;
+#if TEST_STD_VER >= 11
+ // Sanity check for constexpr in C++11
+ {
+ constexpr std::array<int, 3> array = {};
+ static_assert(!array.empty(), "");
+ }
+#endif
+
+ return 0;
}