Skip to content

Commit 52e02bd

Browse files
[SYCL] Fix narrowing type conversion in marray (#7372)
On Windows with -Wc++-narrowing (enabled by default) known-identity test fails because initializer list has limitations and doesn't allow narrowing conversions. It may occur when e.g. we use operator~ which upgrades type. In this case check EnableIfSuitableTypes succeeds but initializer list limitations may cause compilation errors. Inserting static_cast is valid since we already have a check for allowed types. Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 33db95c commit 52e02bd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

sycl/include/sycl/marray.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ template <typename Type, std::size_t NumElements> class marray {
6464
template <
6565
typename... ArgTN, typename = EnableIfSuitableTypes<ArgTN...>,
6666
typename = typename std::enable_if<sizeof...(ArgTN) == NumElements>::type>
67-
constexpr marray(const ArgTN &...Args) : MData{Args...} {}
67+
constexpr marray(const ArgTN &...Args) : MData{static_cast<Type>(Args)...} {}
6868

6969
constexpr marray(const marray<Type, NumElements> &Rhs) = default;
7070

sycl/test/basic_tests/known_identity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ typename std::enable_if<!std::is_same_v<T, half> && !std::is_same_v<T, float> &&
246246
checkMarrayKnownIdentity() {
247247
constexpr marray<T, Num> zeros(T(0));
248248
constexpr marray<T, Num> ones(T(1));
249-
constexpr marray<T, Num> bit_ones(T(~0));
249+
constexpr marray<T, Num> bit_ones(~T(0));
250250

251251
static_assert(has_known_identity<plus<>, marray<T, Num>>::value);
252252
static_assert(

0 commit comments

Comments
 (0)