From d782e777e9cfa586554af39d926815418ddaa309 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 22 Sep 2023 01:33:29 +0800 Subject: [PATCH 1/3] Make `to_array` ADL-proof --- stl/inc/array | 4 ++-- tests/std/tests/P0325R4_to_array/test.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stl/inc/array b/stl/inc/array index 7cd41156dbe..6cabe84844f 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -834,7 +834,7 @@ _NODISCARD constexpr array, _Size> to_array(_Ty (&_Array)[_Size "to_array does not accept multidimensional arrays."); static_assert(is_constructible_v<_Ty, _Ty&>, "N4950 [array.creation]/1: " "to_array requires copy constructible elements."); - return _To_array_lvalue_impl(_Array, make_index_sequence<_Size>{}); + return _STD _To_array_lvalue_impl(_Array, make_index_sequence<_Size>{}); } _EXPORT_STD template @@ -843,7 +843,7 @@ _NODISCARD constexpr array, _Size> to_array(_Ty (&&_Array)[_Siz "to_array does not accept multidimensional arrays."); static_assert(is_move_constructible_v<_Ty>, "N4950 [array.creation]/4: " "to_array requires move constructible elements."); - return _To_array_rvalue_impl(_STD move(_Array), make_index_sequence<_Size>{}); + return _STD _To_array_rvalue_impl(_STD move(_Array), make_index_sequence<_Size>{}); } #endif // _HAS_CXX20 diff --git a/tests/std/tests/P0325R4_to_array/test.cpp b/tests/std/tests/P0325R4_to_array/test.cpp index ccdbbdcecb1..bac6b7b9d2c 100644 --- a/tests/std/tests/P0325R4_to_array/test.cpp +++ b/tests/std/tests/P0325R4_to_array/test.cpp @@ -53,6 +53,19 @@ void assert_not_constexpr() { assert_equal(to_array({"cats"s, "go"s, "meow"s}), array{"cats", "go", "meow"}); } +struct incomplete; + +template +struct holder { + T t; +}; + +void test_adl_proof() { // COMPILE-ONLY + holder* a[1]{}; + (void) std::to_array(a); // intentionally qualified to avoid ADL + (void) std::to_array(std::move(a)); // intentionally qualified to avoid ADL +} + int main() { assert(assert_constexpr()); static_assert(assert_constexpr()); From e5c04fe7deb166865c4fb4b3b4d45ea1d519c4f4 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 22 Sep 2023 02:03:35 +0800 Subject: [PATCH 2/3] Qualify `_Swap_ranges_unchecked` But I don't think this can make any program additionally accepted. --- stl/inc/array | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/array b/stl/inc/array index 6cabe84844f..34c6d9382f0 100644 --- a/stl/inc/array +++ b/stl/inc/array @@ -433,7 +433,7 @@ public: } _CONSTEXPR20 void swap(array& _Other) noexcept(_Is_nothrow_swappable<_Ty>::value) { - _Swap_ranges_unchecked(_Elems, _Elems + _Size, _Other._Elems); + _STD _Swap_ranges_unchecked(_Elems, _Elems + _Size, _Other._Elems); } _NODISCARD _CONSTEXPR17 iterator begin() noexcept { From 80ddd84e4c3275fad4bd8bfcd77b0baf358f6248 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 21 Sep 2023 19:06:11 -0700 Subject: [PATCH 3/3] Work around the `/clr` bug with incomplete types. --- tests/std/tests/P0325R4_to_array/test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P0325R4_to_array/test.cpp b/tests/std/tests/P0325R4_to_array/test.cpp index bac6b7b9d2c..adf4c3ae531 100644 --- a/tests/std/tests/P0325R4_to_array/test.cpp +++ b/tests/std/tests/P0325R4_to_array/test.cpp @@ -53,6 +53,7 @@ void assert_not_constexpr() { assert_equal(to_array({"cats"s, "go"s, "meow"s}), array{"cats", "go", "meow"}); } +#ifndef _M_CEE // TRANSITION, VSO-1659496 struct incomplete; template @@ -65,6 +66,7 @@ void test_adl_proof() { // COMPILE-ONLY (void) std::to_array(a); // intentionally qualified to avoid ADL (void) std::to_array(std::move(a)); // intentionally qualified to avoid ADL } +#endif // _M_CEE int main() { assert(assert_constexpr());