Skip to content

Commit 7f16aa3

Browse files
alexeyvoronov-intelbader
authored andcommitted
[SYCL] Add a requirement for "as" method return type of vec class (#686)
Signed-off-by: Alexey Voronov <alexey.voronov@intel.com>
1 parent 5be0314 commit 7f16aa3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sycl/include/CL/sycl/types.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#include <array>
5454
#include <cmath>
55+
#include <cstring>
5556
#ifndef __SYCL_DEVICE_ONLY__
5657
#include <cfenv>
5758
#endif
@@ -579,11 +580,16 @@ template <typename Type, int NumElements> class vec {
579580
return Result;
580581
}
581582

582-
template <typename asT>
583-
typename std::enable_if<sizeof(asT) == sizeof(DataType), asT>::type
584-
as() const {
583+
template <typename asT> asT as() const {
584+
static_assert((sizeof(*this) == sizeof(asT)),
585+
"The new SYCL vec type must have the same storage size in "
586+
"bytes as this SYCL vec");
587+
static_assert(
588+
detail::is_contained<asT, detail::gtl::vector_basic_list>::value,
589+
"asT must be SYCL vec of a different element type and "
590+
"number of elements specified by asT");
585591
asT Result;
586-
*static_cast<DataType *>(static_cast<void *>(&Result.m_Data)) = m_Data;
592+
std::memcpy(&Result.m_Data, &m_Data, sizeof(decltype(Result.m_Data)));
587593
return Result;
588594
}
589595

0 commit comments

Comments
 (0)