Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make to_array ADL-proof #4042

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -834,7 +834,7 @@ _NODISCARD constexpr array<remove_cv_t<_Ty>, _Size> to_array(_Ty (&_Array)[_Size
"to_array does not accept multidimensional arrays.");
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
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 <class _Ty, size_t _Size>
Expand All @@ -843,7 +843,7 @@ _NODISCARD constexpr array<remove_cv_t<_Ty>, _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

Expand Down
13 changes: 13 additions & 0 deletions tests/std/tests/P0325R4_to_array/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void assert_not_constexpr() {
assert_equal(to_array({"cats"s, "go"s, "meow"s}), array<string, 3>{"cats", "go", "meow"});
}

struct incomplete;

template <class T>
struct holder {
T t;
};

void test_adl_proof() { // COMPILE-ONLY
holder<incomplete>* 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());
Expand Down