Skip to content

Commit 2b50820

Browse files
[SYCL] Add missing sycl::span constructor (#6593)
Fixed a compilation issue with fully specialized sycl::span.
1 parent e20fefc commit 2b50820

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

sycl/include/sycl/sycl_span.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ template <typename _Tp, size_t _Extent> class _SYCL_SPAN_TEMPLATE_VIS span {
217217
constexpr span(const span &) noexcept = default;
218218
constexpr span &operator=(const span &) noexcept = default;
219219

220+
template <size_t _Sz = _Extent>
221+
_SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(
222+
element_type (&__arr)[_Sz])
223+
: __data{__arr} {
224+
(void)_Sz;
225+
_SYCL_SPAN_ASSERT(_Extent == _Sz,
226+
"size mismatch in span's constructor (&_arr)[_Sz]");
227+
}
228+
220229
_SYCL_SPAN_INLINE_VISIBILITY constexpr explicit span(pointer __ptr,
221230
size_type __count)
222231
: __data{__ptr} {
@@ -609,10 +618,9 @@ as_writable_bytes(span<_Tp, _Extent> __s) noexcept
609618

610619
// Deduction guides
611620

612-
// array arg deduction guide. dynamic_extent arg used to select
613-
// the correct template. The _Sz will be used for the __size of the span.
621+
// array arg deduction guide
614622
template <class _Tp, size_t _Sz>
615-
span(_Tp (&)[_Sz]) -> span<_Tp, dynamic_extent>;
623+
span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
616624

617625
template <class _Tp, size_t _Sz> span(std::array<_Tp, _Sz> &) -> span<_Tp, _Sz>;
618626

sycl/test/basic_tests/span.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ int main() {
2828
sycl::span<int> fromIntVec{vec};
2929

3030
// fully specialized
31-
// TODO: fix fully specialized span from array declaration support
32-
// sycl::span<int,4> fullSpecArray{arr};
33-
// sycl::span<const int,3> fullSpecConstArray{constArr};
31+
sycl::span<int,4> fullSpecArray{arr};
32+
sycl::span<const int,3> fullSpecConstArray{constArr};
3433
sycl::span<int, 4> fullSpecVecArray{vec};
3534

35+
// check that the extent is deduced correctly
36+
static_assert(decltype(fromArray)::extent == decltype(fullSpecArray)::extent,
37+
"extent doesn't match between unspecialized and fully "
38+
"specialized span from array");
39+
static_assert(decltype(fromConstArray)::extent ==
40+
decltype(fullSpecConstArray)::extent,
41+
"extent doesn't match between unspecialized and fully "
42+
"specialized span from const array");
43+
3644
return 0;
37-
}
45+
}

0 commit comments

Comments
 (0)