Skip to content

Commit 79137b6

Browse files
<valarray>: Make valarray ADL-proof as required (#5157)
Co-authored-by: Casey Carter <[email protected]>
1 parent 83be0b7 commit 79137b6

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

stl/inc/valarray

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public:
8080
}
8181

8282
valarray(const _Ty& _Val, size_t _Count) { // construct with _Count * _Val
83-
_Grow(_Count, &_Val);
83+
_Grow(_Count, _STD addressof(_Val));
8484
}
8585

8686
valarray(const _Ty* _Ptr, size_t _Count) { // construct with [_Ptr, _Ptr + _Count)
@@ -162,7 +162,7 @@ public:
162162

163163
void resize(size_t _Newsize, _Ty _Val) { // determine new length, filling with _Val elements
164164
_Tidy_deallocate();
165-
_Grow(_Newsize, &_Val, 0);
165+
_Grow(_Newsize, _STD addressof(_Val), 0);
166166
}
167167

168168
valarray& operator=(const slice_array<_Ty>& _Slicearr); // defined below
@@ -538,7 +538,7 @@ private:
538538
_Myptr = _Allocate_for_op_delete<_Ty>(_Newsize);
539539
_Tidy_deallocate_guard<valarray> _Guard{this};
540540
for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx) {
541-
_Construct_in_place(_Myptr[_Idx]);
541+
_STD _Construct_in_place(_Myptr[_Idx]);
542542
}
543543

544544
_Guard._Target = nullptr;
@@ -552,7 +552,7 @@ private:
552552
_Myptr = _Allocate_for_op_delete<_Ty>(_Newsize);
553553
_Tidy_deallocate_guard<valarray> _Guard{this};
554554
for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx, _Ptr += _Inc) {
555-
_Construct_in_place(_Myptr[_Idx], *_Ptr);
555+
_STD _Construct_in_place(_Myptr[_Idx], *_Ptr);
556556
}
557557

558558
_Guard._Target = nullptr;
@@ -562,7 +562,7 @@ private:
562562

563563
void _Tidy_deallocate() noexcept {
564564
if (_Myptr) { // destroy elements
565-
_Destroy_range(_Myptr, _Myptr + _Mysize);
565+
_STD _Destroy_range(_Myptr, _Myptr + _Mysize);
566566
#ifdef __cpp_aligned_new
567567
constexpr bool _Extended_alignment = alignof(_Ty) > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
568568
if constexpr (_Extended_alignment) {
@@ -2028,7 +2028,7 @@ private:
20282028
template <class _Ty>
20292029
valarray<_Ty>& valarray<_Ty>::operator=(const slice_array<_Ty>& _Slicearr) {
20302030
_Tidy_deallocate();
2031-
_Grow(_Slicearr.size(), &_Slicearr._Data(_Slicearr.start()), _Slicearr.stride());
2031+
_Grow(_Slicearr.size(), _STD addressof(_Slicearr._Data(_Slicearr.start())), _Slicearr.stride());
20322032
return *this;
20332033
}
20342034

tests/std/tests/GH_000140_adl_proof_construction/test.compile.pass.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <future>
77
#include <memory>
88
#include <type_traits>
9+
#include <utility>
10+
#include <valarray>
911
#if _HAS_CXX17
1012
#include <optional>
1113
#endif // _HAS_CXX17
@@ -79,15 +81,15 @@ template <class Tag>
7981
struct tagged_identity {
8082
template <class U>
8183
constexpr U&& operator()(U&& u) const noexcept {
82-
return static_cast<U&&>(u);
84+
return std::forward<U>(u);
8385
}
8486
};
8587

8688
template <class Tag>
8789
struct tagged_large_identity {
8890
template <class U>
8991
constexpr U&& operator()(U&& u) const noexcept {
90-
return static_cast<U&&>(u);
92+
return std::forward<U>(u);
9193
}
9294

9395
alignas(64) unsigned char unused[64]{};
@@ -145,6 +147,25 @@ void test_promise() {
145147
promise<validator&>{allocator_arg, adl_proof_allocator<unsigned char>{}};
146148
}
147149

150+
void test_valarray() {
151+
using validator_class = holder<validator>;
152+
153+
valarray<validator_class> valarr1(42);
154+
155+
validator_class a[1]{};
156+
valarray<validator_class> valarr2(a, 1);
157+
valarr2.resize(172, a[0]);
158+
159+
valarray<validator_class> valarr3(a[0], 1);
160+
valarr3 = valarr2[slice{0, 1, 1}];
161+
162+
auto valarr4 = valarr1;
163+
valarr4 = valarr1;
164+
165+
auto valarr5 = std::move(valarr2);
166+
valarr5 = std::move(valarr3);
167+
}
168+
148169
#if _HAS_CXX17
149170
void test_optional() {
150171
optional<validator> o{};

0 commit comments

Comments
 (0)