From 04eccade1981142db238eebe0f865d480aec8221 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 29 Nov 2024 18:43:39 +0800 Subject: [PATCH 1/2] Make `valarray` ADL-proof as required --- stl/inc/valarray | 12 +++++------ .../test.compile.pass.cpp | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/stl/inc/valarray b/stl/inc/valarray index 38303a6419a..3b370470e1d 100644 --- a/stl/inc/valarray +++ b/stl/inc/valarray @@ -80,7 +80,7 @@ public: } valarray(const _Ty& _Val, size_t _Count) { // construct with _Count * _Val - _Grow(_Count, &_Val); + _Grow(_Count, _STD addressof(_Val)); } valarray(const _Ty* _Ptr, size_t _Count) { // construct with [_Ptr, _Ptr + _Count) @@ -162,7 +162,7 @@ public: void resize(size_t _Newsize, _Ty _Val) { // determine new length, filling with _Val elements _Tidy_deallocate(); - _Grow(_Newsize, &_Val, 0); + _Grow(_Newsize, _STD addressof(_Val), 0); } valarray& operator=(const slice_array<_Ty>& _Slicearr); // defined below @@ -538,7 +538,7 @@ private: _Myptr = _Allocate_for_op_delete<_Ty>(_Newsize); _Tidy_deallocate_guard _Guard{this}; for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx) { - _Construct_in_place(_Myptr[_Idx]); + _STD _Construct_in_place(_Myptr[_Idx]); } _Guard._Target = nullptr; @@ -552,7 +552,7 @@ private: _Myptr = _Allocate_for_op_delete<_Ty>(_Newsize); _Tidy_deallocate_guard _Guard{this}; for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx, _Ptr += _Inc) { - _Construct_in_place(_Myptr[_Idx], *_Ptr); + _STD _Construct_in_place(_Myptr[_Idx], *_Ptr); } _Guard._Target = nullptr; @@ -562,7 +562,7 @@ private: void _Tidy_deallocate() noexcept { if (_Myptr) { // destroy elements - _Destroy_range(_Myptr, _Myptr + _Mysize); + _STD _Destroy_range(_Myptr, _Myptr + _Mysize); #ifdef __cpp_aligned_new constexpr bool _Extended_alignment = alignof(_Ty) > __STDCPP_DEFAULT_NEW_ALIGNMENT__; if constexpr (_Extended_alignment) { @@ -2028,7 +2028,7 @@ private: template valarray<_Ty>& valarray<_Ty>::operator=(const slice_array<_Ty>& _Slicearr) { _Tidy_deallocate(); - _Grow(_Slicearr.size(), &_Slicearr._Data(_Slicearr.start()), _Slicearr.stride()); + _Grow(_Slicearr.size(), _STD addressof(_Slicearr._Data(_Slicearr.start())), _Slicearr.stride()); return *this; } diff --git a/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp b/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp index 0bc1d7ba294..8ad1e3d80c6 100644 --- a/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp +++ b/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #if _HAS_CXX17 #include #endif // _HAS_CXX17 @@ -145,6 +146,25 @@ void test_promise() { promise{allocator_arg, adl_proof_allocator{}}; } +void test_valarray() { + using validator_class = holder; + + valarray valarr1(42); + + validator_class a[1]{}; + valarray valarr2(a, 1); + valarr2.resize(172, a[0]); + + valarray valarr3(a[0], 1); + valarr3 = valarr2[slice{0, 1, 1}]; + + auto valarr4 = valarr1; + valarr4 = valarr1; + + auto valarr5 = static_cast&&>(valarr2); + valarr5 = static_cast&&>(valarr3); +} + #if _HAS_CXX17 void test_optional() { optional o{}; From 0ad1042e0a058dc028efd6b157fbefe12b377d14 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 29 Nov 2024 16:51:08 -0800 Subject: [PATCH 2/2] Casey's review comment --- .../test.compile.pass.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp b/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp index 8ad1e3d80c6..57e78b559cc 100644 --- a/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp +++ b/tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #if _HAS_CXX17 #include @@ -80,7 +81,7 @@ template struct tagged_identity { template constexpr U&& operator()(U&& u) const noexcept { - return static_cast(u); + return std::forward(u); } }; @@ -88,7 +89,7 @@ template struct tagged_large_identity { template constexpr U&& operator()(U&& u) const noexcept { - return static_cast(u); + return std::forward(u); } alignas(64) unsigned char unused[64]{}; @@ -161,8 +162,8 @@ void test_valarray() { auto valarr4 = valarr1; valarr4 = valarr1; - auto valarr5 = static_cast&&>(valarr2); - valarr5 = static_cast&&>(valarr3); + auto valarr5 = std::move(valarr2); + valarr5 = std::move(valarr3); } #if _HAS_CXX17