From d50e1c05080553c74f44080886ba6a3cbea7dd18 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 22 Oct 2021 12:15:12 -0700 Subject: [PATCH 1/3] Specially handle `array` for non-default-constructible `T` Previously, these types were non-instantiable; we can't break ABI for something that doesn't compile. Fixes #942 --- stl/inc/array | 14 +++++++------- tests/libcxx/expected_results.txt | 10 +++------- tests/libcxx/skipped_tests.txt | 10 +++------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/stl/inc/array b/stl/inc/array index c417a1826b4..2e3140a99ea 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -728,7 +728,7 @@ public: _STL_REPORT_ERROR("array subscript out of range"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD const_reference operator[](size_type) const noexcept /* strengthened */ { @@ -736,7 +736,7 @@ public: _STL_REPORT_ERROR("array subscript out of range"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD reference front() noexcept /* strengthened */ { @@ -744,7 +744,7 @@ public: _STL_REPORT_ERROR("array::front() invalid"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD const_reference front() const noexcept /* strengthened */ { @@ -752,7 +752,7 @@ public: _STL_REPORT_ERROR("array::front() invalid"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD reference back() noexcept /* strengthened */ { @@ -760,7 +760,7 @@ public: _STL_REPORT_ERROR("array::back() invalid"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD const_reference back() const noexcept /* strengthened */ { @@ -768,7 +768,7 @@ public: _STL_REPORT_ERROR("array::back() invalid"); #endif // _CONTAINER_DEBUG_LEVEL > 0 - return _Elems[0]; + return *data(); } _NODISCARD _CONSTEXPR17 _Ty* data() noexcept { @@ -783,7 +783,7 @@ public: _Xout_of_range("invalid array subscript"); } - _Ty _Elems[1]; + conditional_t, _Ty, char> _Elems[1]; }; template ::value, int> = 0> diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 2ea46e7fd6b..ea2271fa916 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -69,6 +69,9 @@ std/language.support/support.limits/support.limits.general/concepts.version.pass # Bogus test believes that optional cannot be a literal type std/utilities/optional/optional.object/optional.object.dtor/dtor.pass.cpp:0 FAIL +# Bogus test believes that copyability of array must be the same as array +std/containers/sequences/array/array.cons/implicit_copy.pass.cpp FAIL + # *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX *** # Tracked by VSO-593630 " Enable libcxx filesystem tests" @@ -348,13 +351,6 @@ std/input.output/file.streams/fstreams/filebuf.virtuals/underflow.pass.cpp FAIL std/containers/sequences/array/array.fill/fill.fail.cpp FAIL std/containers/sequences/array/array.swap/swap.fail.cpp FAIL -# GH-942 : std::array doesn't compile - when type is not default constructible -std/containers/sequences/array/array.cons/implicit_copy.pass.cpp FAIL -std/containers/sequences/array/array.cons/initialization.pass.cpp FAIL -std/containers/sequences/array/array.data/data_const.pass.cpp FAIL -std/containers/sequences/array/array.data/data.pass.cpp FAIL -std/containers/sequences/array/iterators.pass.cpp FAIL - # GH-1006 : debug checks for predicates are observable std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp FAIL std/algorithms/alg.sorting/alg.min.max/minmax_init_list_comp.pass.cpp FAIL diff --git a/tests/libcxx/skipped_tests.txt b/tests/libcxx/skipped_tests.txt index 9f247e32f38..401947ec26a 100644 --- a/tests/libcxx/skipped_tests.txt +++ b/tests/libcxx/skipped_tests.txt @@ -69,6 +69,9 @@ language.support\support.limits\support.limits.general\concepts.version.pass.cpp # Bogus test believes that optional cannot be a literal type utilities\optional\optional.object\optional.object.dtor\dtor.pass.cpp +# Bogus test believes that copyability of array must be the same as array +containers\sequences\array\array.cons\implicit_copy.pass.cpp + # *** INTERACTIONS WITH CONTEST / C1XX THAT UPSTREAM LIKELY WON'T FIX *** # Tracked by VSO-593630 " Enable libcxx filesystem tests" @@ -348,13 +351,6 @@ input.output\file.streams\fstreams\filebuf.virtuals\underflow.pass.cpp containers\sequences\array\array.fill\fill.fail.cpp containers\sequences\array\array.swap\swap.fail.cpp -# GH-942 : std::array doesn't compile - when type is not default constructible -containers\sequences\array\array.cons\implicit_copy.pass.cpp -containers\sequences\array\array.cons\initialization.pass.cpp -containers\sequences\array\array.data\data_const.pass.cpp -containers\sequences\array\array.data\data.pass.cpp -containers\sequences\array\iterators.pass.cpp - # GH-1006 : debug checks for predicates are observable algorithms\alg.sorting\alg.merge\inplace_merge_comp.pass.cpp algorithms\alg.sorting\alg.min.max\minmax_init_list_comp.pass.cpp From a2607b2b0a9ab430651daf1f1999f6df853cb926 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Sun, 24 Oct 2021 19:41:07 -0700 Subject: [PATCH 2/3] Tim's review comments --- stl/inc/array | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stl/inc/array b/stl/inc/array index 2e3140a99ea..331a5b31f84 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -615,6 +615,8 @@ template array(_First, _Rest...) -> array::type, 1 + sizeof...(_Rest)>; #endif // _HAS_CXX17 +struct _Empty_array_element {}; + template class array<_Ty, 0> { public: @@ -783,7 +785,7 @@ public: _Xout_of_range("invalid array subscript"); } - conditional_t, _Ty, char> _Elems[1]; + conditional_t<_Is_implicitly_default_constructible<_Ty>::value, _Ty, _Empty_array_element> _Elems[1]; }; template ::value, int> = 0> From 69b708eba090c2656c2c4f2e96a9a34525b7ad8d Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Mon, 25 Oct 2021 14:03:38 -0700 Subject: [PATCH 3/3] Tim's repeated review comment =) --- stl/inc/array | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stl/inc/array b/stl/inc/array index 331a5b31f84..9c8b39023ed 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -785,7 +785,9 @@ public: _Xout_of_range("invalid array subscript"); } - conditional_t<_Is_implicitly_default_constructible<_Ty>::value, _Ty, _Empty_array_element> _Elems[1]; + conditional_t, _Is_implicitly_default_constructible<_Ty>>, _Ty, + _Empty_array_element> + _Elems[1]; }; template ::value, int> = 0>